Zeus/model/category.go

35 lines
831 B
Go
Raw Normal View History

2021-12-13 21:39:15 +08:00
package model
2021-12-14 19:45:25 +08:00
import (
"bgm/consts"
bgm "bgm/helper"
"fmt"
ctxLogger "github.com/luizsuper/ctxLoggers"
"go.uber.org/zap"
"gorm.io/gorm"
)
2021-12-13 21:39:15 +08:00
type Category struct {
//ID int `json:"id" gorm:"column:id"`
Key int `json:"key" gorm:"column:key"`
Value string `json:"value" gorm:"column:value"`
Gid string `json:"gid" gorm:"column:gid"`
}
func (m *Category) TableName() string {
return "category"
}
2021-12-14 19:45:25 +08:00
func GetCategoryM(page, size int, query bgm.QueryMap, db *gorm.DB) (*[]Category, error) {
i := new([]Category)
db = db.Limit(size).Offset((page - 1) * size)
for k, v := range query {
db = db.Where(fmt.Sprintf("%v = ?", k), v)
}
if err := db.Debug().Find(i).Error; err != nil {
ctxLogger.Info(nil, consts.GetServiceModelErr, zap.String(consts.ErrorReason, err.Error()))
return nil, err
}
return i, nil
}