package models import ( "time" "xorm.io/xorm" ) type CommonFields struct { Creator string `xorm:"creator"` CreateTime time.Time `xorm:"CreateTime created"` UpdateTime time.Time `xorm:"UpdateTime updated"` Deleted time.Time `xorm:"'deleted'"` } func GetListByPage(page int, pageSize int, where []map[string]interface{}, db xorm.EngineGroup) (count int64, data []interface{}, err error) { db.ShowSQL(true) var rs []interface{} var session = db.Where("1 = 1") for k, v := range where { session = session.Where(k, v) } count, err = session.Limit(pageSize, (page-1)*page).FindAndCount(&rs) return } func GetOne(where []map[string]interface{}, db xorm.EngineGroup) (rs interface{}, err error) { var session = db.Where("1 = 1") for k, v := range where { session = session.Where(k, v) } err = session.Find(&rs) return } func Insert(pb interface{}, db xorm.EngineGroup) (int64, error) { return db.Insert(pb) } func UpdateById(id int64, pb interface{}, db xorm.EngineGroup) error { _, err := db.Where("id = ?", id).Update(pb) return err } func DetleById(id int64, db xorm.EngineGroup) (err error) { _, err = db.Where("id = ?", id).Delete() return }