package model import ( "git.getensh.com/common/gopkgsv2/database" "gorm.io/gorm" ) type SyBrandModel interface { Get(db *gorm.DB) (*DipSyBrand, error) List(db *gorm.DB, pagination *Pagination) ([]DipSyBrand, error) Count(db *gorm.DB) (int64, error) Update(db *gorm.DB, values interface{}) error } type DipSyBrand struct { ID int64 `gorm:"column:id" json:"id" form:"id"` Initial string `gorm:"column:initial" json:"initial" form:"initial"` BrandName string `gorm:"column:brand_name" json:"brand_name" form:"brand_name"` BrandId string `gorm:"column:brand_id" json:"brand_id" form:"brand_id"` Weight int64 `gorm:"column:weight" json:"weight" form:"weight"` HasImg int64 `gorm:"column:has_img" json:"has_img" form:"has_img"` Status int64 `gorm:"column:status" json:"status" form:"status"` UpdateTime string `gorm:"column:update_time" json:"update_time" form:"update_time"` } type defaultSyBrand struct { tableName string fields string } func NewSyBrand() SyBrandModel { return &defaultSyBrand{ tableName: "db_adm_ads.t_adm_ads2", fields: "id, initial, brand_name, brand_id, weight, has_img, status, update_time", } } func (d *defaultSyBrand) Get(db *gorm.DB) (*DipSyBrand, error) { var res DipSyBrand err := database.Get(db, &res, database.Option{ TableName: d.tableName, Fields: d.fields, }) return &res, err } func (d *defaultSyBrand) List(db *gorm.DB, pagination *Pagination) ([]DipSyBrand, error) { var res []DipSyBrand err := database.List(db, &res, database.Option{ TableName: d.tableName, Fields: d.fields, Limit: pagination.Limit, OffSet: pagination.Offset, OrderBy: "initial ASC, weight DESC", }) return res, err } func (d *defaultSyBrand) Count(db *gorm.DB) (int64, error) { return database.Count(db, database.Option{ TableName: d.tableName, }) } func (d *defaultSyBrand) Update(db *gorm.DB, values interface{}) error { return database.Update(db, values, database.Option{ TableName: d.tableName, }) }