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

4 years ago
  1. package main
  2. func (myTestr *MyTestr) Save(isAllCols ...bool) (err error) {
  3. tmp := MyTestr{}
  4. whereQuery, whereArgs := myTestr.wherePrimaryKey()
  5. myTestr.getXorm().Where(whereQuery, whereArgs...).Get(&tmp)
  6. if tmp.Id == 0 {
  7. _, err = myTestr.getXorm().Insert(myTestr)
  8. } else {
  9. if len(isAllCols) > 0 && isAllCols[0] {
  10. _, err = myTestr.getXorm().AllCols().Where(whereQuery, whereArgs...).Update(myTestr)
  11. } else {
  12. _, err = myTestr.getXorm().Where(whereQuery, whereArgs...).Update(myTestr)
  13. }
  14. }
  15. return err
  16. }
  17. func (myTestr *MyTestr) Load() (err error) {
  18. whereQuery, whereArgs := myTestr.wherePrimaryKey()
  19. _, err = myTestr.getXorm().Where(whereQuery, whereArgs...).Get(myTestr)
  20. return
  21. }
  22. func (myTestr *MyTestr) Data() (data []MyTestr) {
  23. myTestr.getXorm().OrderBy("id desc").Find(&data)
  24. return
  25. }
  26. func (myTestr *MyTestr) PageData(page, pageSize int) (data []MyTestr, count int64) {
  27. count, _ = myTestr.getXorm().OrderBy("id desc").Limit(pageSize, page*pageSize).FindAndCount(&data)
  28. return
  29. }
  30. func (myTestr *MyTestr) Delete() (err error) {
  31. whereQuery, whereArgs := myTestr.wherePrimaryKey()
  32. _, err = myTestr.getXorm().Where(whereQuery, whereArgs...).Delete(myTestr)
  33. return
  34. }