部分提交

This commit is contained in:
des
2026-01-11 10:11:09 +08:00
parent b56da6575e
commit becb6a512b
9 changed files with 88 additions and 90 deletions

43
srv/main.go Normal file
View File

@@ -0,0 +1,43 @@
package main
import (
"context"
"fmt"
"time"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
type User struct {
id int8
createTime time.Time
lastUpdateTime time.Time
name string
account string
passwd string
}
func (User) TableName() string {
return "user"
}
func main() {
dsn := "host=localhost " +
"user=gatekeeper " +
"dbname=crimson " +
"sslmode=disable " +
"port=5432 " +
"password=crimson "
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
panic("无法连接数据库")
}
ctx := context.Background()
user, err := gorm.G[User](db).First(ctx)
fmt.Println(user)
fmt.Println("程序结束")
return
}