model.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package yb_my_chart
  2. import "hongze/hongze_yb/global"
  3. func (m *YbMyChart) Count(condition string, pars []interface{}) (num int64, err error) {
  4. err = global.DEFAULT_MYSQL.Model(m).
  5. Where(condition, pars...).
  6. Count(&num).Error
  7. return
  8. }
  9. func (m *YbMyChart) Create() (err error) {
  10. err = global.DEFAULT_MYSQL.Create(m).Error
  11. return
  12. }
  13. func (m *YbMyChart) Update(updateCols []string) (err error) {
  14. err = global.DEFAULT_MYSQL.Model(m).Select(updateCols).Updates(m).Error
  15. return
  16. }
  17. func (m *YbMyChart) List(condition string, pars []interface{}) (list []*YbMyChart, err error) {
  18. list = make([]*YbMyChart, 0)
  19. err = global.DEFAULT_MYSQL.Model(m).
  20. Where(condition, pars...).
  21. Order("create_time DESC").
  22. Find(&list).Error
  23. return
  24. }
  25. func (m *YbMyChart) PageList(condition string, pars []interface{}, pageIndex, pageSize int) (list []*YbMyChart, err error) {
  26. offset := (pageIndex - 1) * pageSize
  27. err = global.DEFAULT_MYSQL.Model(m).
  28. Where(condition, pars...).
  29. Offset(offset).Limit(pageSize).
  30. Order("create_time DESC").
  31. Scan(&list).Error
  32. return
  33. }
  34. func (m *YbMyChart) Fetch(id int) (item *YbMyChart, err error) {
  35. err = global.DEFAULT_MYSQL.Model(m).Where("my_chart_id = ?", id).First(&item).Error
  36. return
  37. }
  38. func (m *YbMyChart) FetchByCondition(condition string, pars []interface{}) (item *YbMyChart, err error) {
  39. err = global.DEFAULT_MYSQL.Model(m).
  40. Where(condition, pars...).
  41. First(&item).Error
  42. return
  43. }
  44. func (m *YbMyChart) Delete() (err error) {
  45. err = global.DEFAULT_MYSQL.Delete(m).Error
  46. return
  47. }