ads3.go 1.8 KB

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