我正在尝试使用 Postgres 与 golang 中的 gorm 连接来查询和获取所有数据。
我的戈姆模型
type WebsiteSlots struct {
Id uint `gorm:"primary_key"`
Settings string `gorm:"json"`
AdsizeId int `gorm:"type:int"`
WebsiteId int `gorm:"type:int"`
AdSize Adsizes `gorm:"foreignkey:AdSizesId"`
Website Websites `gorm:"foreignkey:WebsiteId"`
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
}
func (WebsiteSlots) TableName() string {
return "website_ads"
}
我的查询存储库 GetSlots() 正在生成
"SELECT * FROM "website_ads" WHERE "website_ads"."id" = 2 LIMIT 50 OFFSET 0"
这个查询。不知道这个 ""website_ads"."id" = 2" 是怎么来的?
type Slots struct {
Container *container.Container
}
func (w *Slots) GetSlots(skip int , limit int) []models.WebsiteSlots {
var results []models.WebsiteSlots
sites := w.Container.Get("dbprovider").(*services.Database)
postgresConnection := sites.PostgresConnection()
postgresConnection.LogMode(true)
var websiteslots models.WebsiteSlots
resp, _ := postgresConnection.Debug().Find(&websiteslots).Limit(limit).Offset(skip).Rows()
//i := 0
for resp.Next() {
results = append(results,websiteslots)
}
return results
}
有人可以帮忙吗?
慕容708150
ITMISS
相关分类