package model import ( "git.getensh.com/common/gopkgsv2/database" "gorm.io/gorm" ) type MaintenanceTemplateModel interface { Insert(db *gorm.DB, data interface{}) error List(db *gorm.DB) ([]MaintenanceTemplate, error) Get(db *gorm.DB) (*MaintenanceTemplate, error) Update(db *gorm.DB, values interface{}) error } type MaintenanceTemplate struct { ID int64 `gorm:"column:id" json:"id"` Name string `gorm:"column:name" json:"name"` } type defaultMaintenanceTemplateModel struct { tableName string fields string } func NewMaintenanceTemplateModel() MaintenanceTemplateModel { return &defaultMaintenanceTemplateModel{ "db_adm_management.t_adm_maintenance_template", "id, name", } } func (d *defaultMaintenanceTemplateModel) Insert(db *gorm.DB, data interface{}) error { return database.Create(db, data, database.Option{ TableName: d.tableName, }) } func (d *defaultMaintenanceTemplateModel) List(db *gorm.DB) ([]MaintenanceTemplate, error) { var res []MaintenanceTemplate err := database.List(db, &res, database.Option{ TableName: d.tableName, Fields: d.fields, }) return res, err } func (d *defaultMaintenanceTemplateModel) Get(db *gorm.DB) (*MaintenanceTemplate, error) { var res MaintenanceTemplate err := database.Get(db, &res, database.Option{ TableName: d.tableName, Fields: d.fields, }) return &res, err } func (d *defaultMaintenanceTemplateModel) Update(db *gorm.DB, values interface{}) error { return database.Update(db, values, database.Option{ TableName: d.tableName, }) }