You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

42 lines
1.2 KiB

package main
func (myTestr *MyTestr) Save(isAllCols ...bool) (err error) {
tmp := MyTestr{}
whereQuery, whereArgs := myTestr.wherePrimaryKey()
myTestr.getXorm().Where(whereQuery, whereArgs...).Get(&tmp)
if tmp.Id == 0 {
_, err = myTestr.getXorm().Insert(myTestr)
} else {
if len(isAllCols) > 0 && isAllCols[0] {
_, err = myTestr.getXorm().AllCols().Where(whereQuery, whereArgs...).Update(myTestr)
} else {
_, err = myTestr.getXorm().Where(whereQuery, whereArgs...).Update(myTestr)
}
}
return err
}
func (myTestr *MyTestr) Load() (err error) {
whereQuery, whereArgs := myTestr.wherePrimaryKey()
_, err = myTestr.getXorm().Where(whereQuery, whereArgs...).Get(myTestr)
return
}
func (myTestr *MyTestr) Data() (data []MyTestr) {
myTestr.getXorm().OrderBy("id desc").Find(&data)
return
}
func (myTestr *MyTestr) PageData(page, pageSize int) (data []MyTestr, count int64) {
count, _ = myTestr.getXorm().OrderBy("id desc").Limit(pageSize, page*pageSize).FindAndCount(&data)
return
}
func (myTestr *MyTestr) Delete() (err error) {
whereQuery, whereArgs := myTestr.wherePrimaryKey()
_, err = myTestr.getXorm().Where(whereQuery, whereArgs...).Delete(myTestr)
return
}