go jinzhu/gorm. 到 gorm.io。 go-gorm

go-gorm  是 jinzhu的grom 第二版本
之前沒注意第一版本只更新到1.9。 現在的第二版 已經到1.21了


文檔

https://gorm.io/zh_CN/docs/create.html

升級遇到問題
問題: cannot use &count (type *int) as type *int64 in argument to db.Count

解決:int 改爲int64
問題: not enough arguments in call to helpers.MysqlClient.Model(&DeliveryRules{}).Where("rule_id = ?", d.RuleID).Update
        have (map[string]interface {})
        want (string, interface {})

解決:Update.   改爲 Updates

 

.Limit(limit).Offset(offset)
limit 和 offset 都是int類型

問題:需求錄入查詢不到數據
解決:單條查詢要用First。判斷用 err != 'record not found'   多條查詢用Find。 判斷用len()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章