keyList.go 1.7 KB

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