feat: and 查询
This commit is contained in:
@@ -1,5 +1,14 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"bgm/consts"
|
||||
bgm "bgm/helper"
|
||||
"fmt"
|
||||
ctxLogger "github.com/luizsuper/ctxLoggers"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Category struct {
|
||||
//ID int `json:"id" gorm:"column:id"`
|
||||
Key int `json:"key" gorm:"column:key"`
|
||||
@@ -10,3 +19,16 @@ type Category struct {
|
||||
func (m *Category) TableName() string {
|
||||
return "category"
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package model
|
||||
|
||||
type Response struct {
|
||||
Message string `json:"message"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user