4 Star 6 Fork 3

王军 / golib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
dbutils.go 487 Bytes
一键复制 编辑 原始数据 按行查看 历史
/*
* @Author: Wangjun
* @Date: 2021-05-15 22:43:19
* @LastEditTime: 2022-04-11 09:22:49
* @LastEditors: Wangjun
* @Description:
* @FilePath: \golib\dbutils\dbutils.go
* hnxr
*/
package dbutils
import "gorm.io/gorm"
// Save 保存数据, 有则更新,无则插入
func Save(db *gorm.DB, record interface{}) (err error) {
newdb := db.Model(record).Updates(record)
if newdb.Error == nil && newdb.RowsAffected == 0 {
return db.Create(record).Error
}
return newdb.Error
}
Go
1
https://gitee.com/haodreams/golib.git
git@gitee.com:haodreams/golib.git
haodreams
golib
golib
956c397b13ee

搜索帮助