package implement import ( "applet/app/db/dao" "applet/app/db/model" "applet/app/utils/logx" "reflect" "xorm.io/xorm" ) func NewMediumDb(engine *xorm.Engine) dao.MediumDao { return &MediumDb{Db: engine} } type MediumDb struct { Db *xorm.Engine } func (m MediumDb) UpdateMedium(medium *model.Medium, columns ...string) (int64, error) { affected, err := m.Db.Where("id =?", medium.Id).Cols(columns...).Update(m) if err != nil { return 0, err } return affected, nil } func (m MediumDb) GetMediumByUsername(username string) (medium *model.Medium, err error) { medium = new(model.Medium) has, err := m.Db.Where("username =?", username).Get(medium) if err != nil { return nil, logx.Error(err) } if has == false { return nil, nil } return medium, nil } func (m MediumDb) MediumInsert(medium *model.Medium) (int64, error) { insertAffected, err := m.Db.InsertOne(medium) if err != nil { return 0, err } return insertAffected, nil } func (m MediumDb) MediumDeleteBySession(session *xorm.Session, id interface{}) (int64, error) { if reflect.TypeOf(id).Kind() == reflect.Slice { return session.In("id", id).Delete(model.Admin{}) } else { return session.Where("id = ?", id).Delete(model.Admin{}) } }