package model import ( "git.getensh.com/common/gopkgsv2/database" "gorm.io/gorm" ) type DataListModel interface { List(db *gorm.DB, pagination *Pagination) ([]AdmDataList, error) Count(db *gorm.DB) (int64, error) Update(db *gorm.DB, values interface{}) error Get(db *gorm.DB) (*AdmDataList, error) } type AdmDataList struct { Id int64 `gorm:"column:id" json:"id" form:"id"` TableName string `gorm:"column:table_name" json:"table_name" form:"table_name"` Desc string `gorm:"column:desc" json:"desc" form:"desc"` Level string `gorm:"column:level" json:"level" form:"level"` SourceCode string `gorm:"column:source_code" json:"source_code" form:"source_code"` Db string `gorm:"column:db" json:"db" form:"db"` CreatedAt int64 `gorm:"column:created_at" json:"created_at" form:"created_at"` UpdatedAt int64 `gorm:"column:updated_at" json:"updated_at" form:"updated_at"` } type defaultDataList struct { tableName string fields string } func NewDataList() DataListModel { return &defaultDataList{ tableName: "t_adm_data_management", fields: "`id`, `table_name`, `desc`, `level`, `source_code`, `db`, `created_at`, `updated_at`", } } func (d *defaultDataList) List(db *gorm.DB, pagination *Pagination) ([]AdmDataList, error) { var res []AdmDataList err := database.List(db, &res, database.Option{ TableName: d.tableName, Fields: d.fields, Limit: pagination.Limit, OffSet: pagination.Offset, }) return res, err } func (d *defaultDataList) Count(db *gorm.DB) (int64, error) { return database.Count(db, database.Option{ TableName: d.tableName, }) } func (d *defaultDataList) Update(db *gorm.DB, values interface{}) error { return database.Update(db, values, database.Option{ TableName: d.tableName, }) } func (d *defaultDataList) Get(db *gorm.DB) (*AdmDataList, error) { var res AdmDataList err := database.Get(db, &res, database.Option{ TableName: d.tableName, Fields: d.fields, }) return &res, err }