第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

全選在 golaong gorm 中不起作用

全選在 golaong gorm 中不起作用

Go
侃侃爾雅 2021-12-27 15:41:22
我正在使用 gin 框架并嘗試使用 grom 進行 crud 操作。我正在嘗試從 MYSQL 數(shù)據(jù)庫中獲取數(shù)據(jù)。我有 db.go 來獲取數(shù)據(jù)庫實例,每個表和模型的一些控制器我有一個這樣的模型    type Campaigns struct {        ID                     int       `json:"id" form:"id" gorm:"column:CampaignID"`        UserID                 int       `json:"userId" form:"userId" gorm:"column:UserID"`        Name                   string    `json:"name" form:"name" gorm:"column:Name"`        StartDate              time.Time `json:"start" form:"start" gorm:"column:StartDate"`        EndDate                time.Time `json:"end" form:"end" gorm:"column:EndDate"`        Customer               string    `json:"customer" form:"customer" gorm:"column:Customer"`        CustomerID             int       `json:"customerId" form:"customerId" gorm:"column:CustomerID"`        ImpressionsCounter     int       `json:"ImpressionsCounter" form:"ImpressionsCounter" gorm:"column:ImpressionsCounter"`        MaxImpressions         int       `json:"maxImpressions" form:"maxImpressions" gorm:"column:MaxImpressions"`        CurrentSpend           float64   `json:"currentSpend" gorm:"column:CurrentSpend"`        MaxSpend               float64   `json:"maxSpend" form:"maxSpend" gorm:"column:MaxSpend"`        Active                 bool      `json:"active" form:"active" gorm:"column:Active"`        Created                time.Time `json:"created" gorm:"column:DateCreated"`        Updated                time.Time `json:"updated" gorm:"column:DateCreated"`}這是我正在使用的一個控制器    package controllersimport (    "time"  "github.com/op/go-logging"    "github.com/gin-gonic/gin"    "github.com/jinzhu/gorm"  _ "github.com/go-sql-driver/mysql"    "../models")var log = logging.MustGetLogger("AsAPI")type AsController struct {    DB gorm.DB}func (ac *AsController) SetDB(d gorm.DB) {    ac.DB = d    ac.DB.LogMode(true)}
查看完整描述

2 回答

?
瀟湘沐

TA貢獻1816條經(jīng)驗 獲得超6個贊

您可以在驅(qū)動程序文檔https://github.com/go-sql-driver/mysql#timetime-support 中找到答案 :

MySQL DATE 和 DATETIME 值的默認內(nèi)部輸出類型是 []byte,它允許您將值掃描到程序中的 []byte、string 或 sql.RawBytes 變量中。

然而,許多人希望將 MySQL 的 DATE 和 DATETIME 值掃描到 time.Time 變量中,這與 MySQL 中的 Go to DATE 和 DATETIME 中的邏輯相反。您可以通過使用 DSN 參數(shù) parseTime=true 將內(nèi)部輸出類型從 []byte 更改為 time.Time 來實現(xiàn)。您可以使用 loc DSN 參數(shù)設(shè)置默認 time.Time 位置。

或者,您可以使用 NullTime 類型作為掃描目標,它適用于 time.Time 和 string / []byte。


查看完整回答
反對 回復 2021-12-27
?
翻過高山走不出你

TA貢獻1875條經(jīng)驗 獲得超3個贊

你真的在這里打開過數(shù)據(jù)庫嗎?我根本沒有看到實際的 Open() 調(diào)用......


查看完整回答
反對 回復 2021-12-27
  • 2 回答
  • 0 關(guān)注
  • 194 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號