Golang sqlx 使用 Where in 解決辦法

     最近工作中遇到了需要使用where in (?)的情況,一直嘗試了幾個都不行,最近在官方找到了一個解決辦法,話不多說Talk is cheap,Show me the code。

 

...

IdInt64List = []int64{ 1, 2, 3, 5} // 需要放在where in裏面更新的IdList 

db := config.DB // 數據庫連接
query, args, err := sqlx.In("UPDATE TestTable set model = ? , `status` = 1 WHERE id in (?)", Model, IdInt64List)
if err != nil {
	return err
}

query = db.Rebind(query)  // Rebind query
res, err := db.Exec(query, args ...)
if err != nil {
	return err
}

...

 

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