maintain_template.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package model
  2. import (
  3. "git.getensh.com/common/gopkgsv2/database"
  4. "gorm.io/gorm"
  5. )
  6. type MaintenanceTemplateModel interface {
  7. Insert(db *gorm.DB, data interface{}) error
  8. List(db *gorm.DB) ([]MaintenanceTemplate, error)
  9. Get(db *gorm.DB) (*MaintenanceTemplate, error)
  10. Update(db *gorm.DB, values interface{}) error
  11. }
  12. type MaintenanceTemplate struct {
  13. ID int64 `gorm:"column:id" json:"id"`
  14. Name string `gorm:"column:name" json:"name"`
  15. }
  16. type defaultMaintenanceTemplateModel struct {
  17. tableName string
  18. fields string
  19. }
  20. func NewMaintenanceTemplateModel() MaintenanceTemplateModel {
  21. return &defaultMaintenanceTemplateModel{
  22. "db_adm_management.t_adm_maintenance_template",
  23. "id, name",
  24. }
  25. }
  26. func (d *defaultMaintenanceTemplateModel) Insert(db *gorm.DB, data interface{}) error {
  27. return database.Create(db, data, database.Option{
  28. TableName: d.tableName,
  29. })
  30. }
  31. func (d *defaultMaintenanceTemplateModel) List(db *gorm.DB) ([]MaintenanceTemplate, error) {
  32. var res []MaintenanceTemplate
  33. err := database.List(db, &res, database.Option{
  34. TableName: d.tableName,
  35. Fields: d.fields,
  36. })
  37. return res, err
  38. }
  39. func (d *defaultMaintenanceTemplateModel) Get(db *gorm.DB) (*MaintenanceTemplate, error) {
  40. var res MaintenanceTemplate
  41. err := database.Get(db, &res, database.Option{
  42. TableName: d.tableName,
  43. Fields: d.fields,
  44. })
  45. return &res, err
  46. }
  47. func (d *defaultMaintenanceTemplateModel) Update(db *gorm.DB, values interface{}) error {
  48. return database.Update(db, values, database.Option{
  49. TableName: d.tableName,
  50. })
  51. }