部分提交
This commit is contained in:
43
srv/main.go
Normal file
43
srv/main.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user