1Panel/core/app/repo/common.go
2024-07-25 14:43:41 +08:00

30 lines
518 B
Go

package repo
import (
"gorm.io/gorm"
)
type DBOption func(*gorm.DB) *gorm.DB
type ICommonRepo interface {
WithByID(id uint) DBOption
WithOrderBy(orderStr string) DBOption
}
type CommonRepo struct{}
func NewICommonRepo() ICommonRepo {
return &CommonRepo{}
}
func (c *CommonRepo) WithByID(id uint) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("id = ?", id)
}
}
func (c *CommonRepo) WithOrderBy(orderStr string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Order(orderStr)
}
}