網(wǎng)站首頁 編程語言 正文
1. 更新日志
1.1. v1.0
1.1.1. 破壞性變更
- gorm.Open返回類型為
*gorm.DB
而不是gorm.DB
- 更新只會(huì)更新更改的字段
大多數(shù)應(yīng)用程序不會(huì)受到影響,只有當(dāng)您更改回調(diào)中的更新值(如BeforeSave
,BeforeUpdate
)時(shí),應(yīng)該使用scope.SetColumn
,例如:
func (user *User) BeforeUpdate(scope *gorm.Scope) { if pw, err := bcrypt.GenerateFromPassword(user.Password, 0); err == nil { scope.SetColumn("EncryptedPassword", pw) // user.EncryptedPassword = pw // 不工作,更新時(shí)不會(huì)包括EncryptedPassword字段 } }
軟刪除的默認(rèn)查詢作用域只會(huì)檢查deleted_at IS NULL
之前它會(huì)檢查deleted_at小于0001-01-02也排除空白時(shí)間,如:
SELECT * FROM users WHERE deleted_at IS NULL OR deleted_at <= '0001-01-02'
但是沒有必要,如果你使用*time.Time
作為模型的DeletedAt
,它已經(jīng)被gorm.Model
使用了,所以SQL就足夠了
SELECT * FROM users WHERE deleted_at IS NULL
所以如果你使用gorm.Model
,那么你是好的,沒有什么需要改變,只要確保所有記錄的空白時(shí)間為deleted_at
設(shè)置為NULL
,示例遷移腳本:
import ( "github.com/jinzhu/now" ) func main() { var models = []interface{}{&User{}, &Image{}} for _, model := range models { db.Unscoped().Model(model).Where("deleted_at < ?", now.MustParse("0001-01-02")).Update("deleted_at", gorm.Expr("NULL")) } }
- 新的ToDBName邏輯
在GORM將struct,F(xiàn)ield的名稱轉(zhuǎn)換為db名稱之前,只有那些來自golint的常見初始化(如HTTP
,URI
)是特殊處理的。
所以字段HTTP
的數(shù)據(jù)庫名稱將是http
而不是h_t_t_p
,但是一些其他的初始化,如SKU
不在golint,它的數(shù)據(jù)庫名稱將是s_k_u
,這看起來很丑陋,這個(gè)版本固定這個(gè),任何大寫的初始化應(yīng)該正確轉(zhuǎn)換。
錯(cuò)誤RecordNotFound
已重命名為ErrRecordNotFound
mssql
驅(qū)動(dòng)程序已從默認(rèn)驅(qū)動(dòng)程序中刪除,
導(dǎo)入它用import _ "github.com/jinzhu/gorm/dialects/mssql"
Hstore已移至github.com/jinzhu/gorm/dialects/postgres
gorm執(zhí)行sql
type Object interface { GroupOrderOpenlog() (uidList []int) } func (o *object) GroupOrderOpenlog() { type res struct { Uid int `json:"uid"` } var re []res sql:= "SELECT uid FROM order_openlog GROUP BY uid" o.Db.Raw(sql).Scan(&re) fmt.Println(re) for _,k :=range re{ fmt.Println(k.Uid) } }
原文鏈接:https://www.cnblogs.com/guyouyin123/p/15770452.html
相關(guān)推薦
- 2022-12-04 python亂序字符串排序的實(shí)現(xiàn)方式_python
- 2022-02-15 使用數(shù)組的sort方法完成項(xiàng)目中的排序功能(數(shù)組sort方法與chart圖表展示結(jié)合)
- 2022-07-14 詳解HBase表的數(shù)據(jù)模型_其它綜合
- 2022-06-13 ASP.NET?Core使用自定義日志中間件_實(shí)用技巧
- 2022-09-19 Tomcat配置HTTPS訪問的實(shí)現(xiàn)步驟_Tomcat
- 2023-03-22 nginx搭建高可用集群的實(shí)現(xiàn)方法_nginx
- 2022-04-06 詳解pandas中缺失數(shù)據(jù)處理的函數(shù)_python
- 2022-08-20 Python數(shù)據(jù)讀寫之Python讀寫CSV文件_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支