package model import ( "git.getensh.com/common/gopkgsv2/database" "gorm.io/gorm" ) type MaintainItemModel interface { Get(db *gorm.DB) (*GdMaintainItem, error) List(db *gorm.DB, fields string) ([]GdMaintainItem, error) } type GdMaintainItem struct { ID int64 `gorm:"column:id" json:"id"` ItemId int64 `gorm:"column:item_id" json:"item_id"` ItemName string `gorm:"column:item_name" json:"item_name"` ItemType int64 `gorm:"column:item_type" json:"item_type"` } type defaultMaintainItem struct { tableName string fields string } func NewMaintainItemModel() MaintainItemModel { return &defaultMaintainItem{ tableName: "db_adm_dws.t_adm_ads12", fields: "id, item_id, item_name, item_type", } } func (d *defaultMaintainItem) Get (db *gorm.DB) (*GdMaintainItem, error) { var res GdMaintainItem err := database.Get(db, &res, database.Option{ TableName: d.tableName, Fields: d.fields, }) return &res, err } func (d *defaultMaintainItem) List (db *gorm.DB, fields string) ([]GdMaintainItem, error) { if fields == "" { fields = d.fields } var res []GdMaintainItem err := database.List(db, &res, database.Option{ TableName: d.tableName, Fields: fields, }) return res, err }