亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Gorm 添加了我不需要的不需要的 where 子句

Gorm 添加了我不需要的不需要的 where 子句

Go
米琪卡哇伊 2023-08-21 14:39:22
我正在嘗試使用 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() 正在生成“從“website_ads”中選擇*,其中“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}有人可以幫忙嗎?
查看完整描述

2 回答

?
墨色風雨

TA貢獻1853條經驗 獲得超6個贊

var websiteslots models.WebsiteSlots
    resp, _ := postgresConnection.Debug().Find(&websiteslots).Limit(limit).Offset(skip).Rows()

Find() 需要一個結構體切片。但您提供的是單個結構。我不知道這是否是額外 WHERE 子句的原因。


查看完整回答
反對 回復 2023-08-21
?
慕俠2389804

TA貢獻1719條經驗 獲得超6個贊

websiteslots := []models.WebsiteSlots{}

postgresConnection.Debug().Limit(limit).Offset(skip).Find(&websiteslots)

return websiteslots 

在這里你使用Find()&Row()這兩者都可能會出現問題。你得到結果websiteslots然后為什么要使用resp準備結果。


查看完整回答
反對 回復 2023-08-21
  • 2 回答
  • 0 關注
  • 230 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號