1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package model
- import (
- "git.getensh.com/common/gopkgsv2/database"
- "gorm.io/gorm"
- )
- type FieldListModel interface {
- List(db *gorm.DB, pagination *Pagination) ([]AdmFieldList, error)
- Count(db *gorm.DB) (int64, error)
- Update(db *gorm.DB, values interface{}) error
- Get(db *gorm.DB) (*AdmFieldList, error)
- }
- type AdmFieldList struct {
- Id int64 `gorm:"column:id" json:"id" form:"id"`
- Field string `gorm:"column:field" json:"field" form:"field"`
- Desc string `gorm:"column:desc" json:"desc" form:"desc"`
- }
- type defaultFieldList struct {
- tableName string
- fields string
- }
- func NewFieldList() FieldListModel {
- return &defaultFieldList{
- tableName: "t_adm_field_management",
- fields: "`id`, `field`, `desc`",
- }
- }
- func (d *defaultFieldList) List(db *gorm.DB, pagination *Pagination) ([]AdmFieldList, error) {
- var res []AdmFieldList
- err := database.List(db, &res, database.Option{
- TableName: d.tableName,
- Fields: d.fields,
- Limit: pagination.Limit,
- OffSet: pagination.Offset,
- })
- return res, err
- }
- func (d *defaultFieldList) Count(db *gorm.DB) (int64, error) {
- return database.Count(db, database.Option{
- TableName: d.tableName,
- })
- }
- func (d *defaultFieldList) Update(db *gorm.DB, values interface{}) error {
- return database.Update(db, values, database.Option{
- TableName: d.tableName,
- })
- }
- func (d *defaultFieldList) Get(db *gorm.DB) (*AdmFieldList, error) {
- var res AdmFieldList
- err := database.Get(db, &res, database.Option{
- TableName: d.tableName,
- Fields: d.fields,
- })
- return &res, err
- }
|