3 Star 17 Fork 4

eyebluecn/tank

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
preference_dao.go 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
zicla 提交于 2018-01-01 15:57 +08:00 . Add a new field version into preference.
package rest
import (
_ "github.com/jinzhu/gorm/dialects/mysql"
"github.com/nu7hatch/gouuid"
"time"
)
type PreferenceDao struct {
BaseDao
}
//按照Id查询偏好设置
func (this *PreferenceDao) Fetch() *Preference {
// Read
var preference = &Preference{}
db := this.context.DB.First(preference)
if db.Error != nil {
if db.Error.Error() == "record not found" {
preference.Name = "蓝眼云盘"
preference.Version = VERSION
this.Create(preference)
return preference
} else {
return nil
}
}
return preference
}
//创建
func (this *PreferenceDao) Create(preference *Preference) *Preference {
timeUUID, _ := uuid.NewV4()
preference.Uuid = string(timeUUID.String())
preference.CreateTime = time.Now()
preference.ModifyTime = time.Now()
db := this.context.DB.Create(preference)
this.PanicError(db.Error)
return preference
}
//修改一个偏好设置
func (this *PreferenceDao) Save(preference *Preference) *Preference {
preference.ModifyTime = time.Now()
db := this.context.DB.Save(preference)
this.PanicError(db.Error)
return preference
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/eyebluecn/tank.git
git@gitee.com:eyebluecn/tank.git
eyebluecn
tank
tank
v1.0.5

搜索帮助