dataList.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package model
  2. import (
  3. "git.getensh.com/common/gopkgsv2/database"
  4. "gorm.io/gorm"
  5. )
  6. type DataListModel interface {
  7. List(db *gorm.DB, pagination *Pagination) ([]AdmDataList, error)
  8. Count(db *gorm.DB) (int64, error)
  9. Update(db *gorm.DB, values interface{}) error
  10. Get(db *gorm.DB) (*AdmDataList, error)
  11. }
  12. type AdmDataList struct {
  13. Id int64 `gorm:"column:id" json:"id" form:"id"`
  14. TableName string `gorm:"column:table_name" json:"table_name" form:"table_name"`
  15. Desc string `gorm:"column:desc" json:"desc" form:"desc"`
  16. Level string `gorm:"column:level" json:"level" form:"level"`
  17. SourceCode string `gorm:"column:source_code" json:"source_code" form:"source_code"`
  18. Db string `gorm:"column:db" json:"db" form:"db"`
  19. CreatedAt int64 `gorm:"column:created_at" json:"created_at" form:"created_at"`
  20. UpdatedAt int64 `gorm:"column:updated_at" json:"updated_at" form:"updated_at"`
  21. }
  22. type defaultDataList struct {
  23. tableName string
  24. fields string
  25. }
  26. func NewDataList() DataListModel {
  27. return &defaultDataList{
  28. tableName: "t_adm_data_management",
  29. fields: "`id`, `table_name`, `desc`, `level`, `source_code`, `db`, `created_at`, `updated_at`",
  30. }
  31. }
  32. func (d *defaultDataList) List(db *gorm.DB, pagination *Pagination) ([]AdmDataList, error) {
  33. var res []AdmDataList
  34. err := database.List(db, &res, database.Option{
  35. TableName: d.tableName,
  36. Fields: d.fields,
  37. Limit: pagination.Limit,
  38. OffSet: pagination.Offset,
  39. })
  40. return res, err
  41. }
  42. func (d *defaultDataList) Count(db *gorm.DB) (int64, error) {
  43. return database.Count(db, database.Option{
  44. TableName: d.tableName,
  45. })
  46. }
  47. func (d *defaultDataList) Update(db *gorm.DB, values interface{}) error {
  48. return database.Update(db, values, database.Option{
  49. TableName: d.tableName,
  50. })
  51. }
  52. func (d *defaultDataList) Get(db *gorm.DB) (*AdmDataList, error) {
  53. var res AdmDataList
  54. err := database.Get(db, &res, database.Option{
  55. TableName: d.tableName,
  56. Fields: d.fields,
  57. })
  58. return &res, err
  59. }