package db import ( "applet/app/db/model" "time" "xorm.io/xorm" ) type MasterDb struct { Db *xorm.Engine `json:"db"` } func (masterDb *MasterDb) Set() { // set方法 masterDb.Db = ZhimengDb } func (masterDb *MasterDb) GetMaster(mid string) *model.Master { var data model.Master get, err := masterDb.Db.Where("master_id=?", mid).Get(&data) if get == false || err != nil { data = model.Master{MasterId: mid, CreateTime: time.Now(), UpdateTime: time.Now(), FormWay: "api"} masterDb.Db.InsertOne(&data) } return &data } func (masterDb *MasterDb) GetMasterId(id int) *model.Master { var data model.Master get, err := masterDb.Db.Where("id=?", id).Get(&data) if get == false || err != nil { return nil } return &data } func (masterDb *MasterDb) MasterUpdate(data *model.Master) bool { get, err := masterDb.Db.Where("id=?", data.Id).Update(data) if get == 0 || err != nil { return false } return true }