Documentation
¶
Index ¶
- Variables
- func GetExpireTime(expireTime time.Duration) *time.Duration
- func GetTX(ctx context.Context) *gorm.DB
- func NewRepository[T any](dbProvider DBProviderInterface) *repository[T]
- type ApiStorer
- type CacheStore
- func (c *CacheStore) DelKey(ctx context.Context, cacheType CacheType, cacheKey any) error
- func (c *CacheStore) GetSet(ctx context.Context, cacheType CacheType, cacheKey any) ([]string, error)
- func (c *CacheStore) NormalizeCacheKey(cacheKey any) (string, error)
- func (c *CacheStore) SetSet(ctx context.Context, cacheType CacheType, cacheKey any, cacheValue []any, ...) error
- type CacheStorer
- type CacheType
- type CasbinStorer
- type DBProvider
- type DBProviderInterface
- type FeiShuUserStorer
- type Option
- func In(colum string, values any) Option
- func Like(colum string, value any) Option
- func Limit(limit int) Option
- func Offset(offset int) Option
- func Order(value string) Option
- func Preload(modelName string, args ...any) Option
- func Scopes(funcs ...func(*gorm.DB) *gorm.DB) Option
- func Select(columns ...string) Option
- func Where(colum string, value any) Option
- type RoleStorer
- type TxManager
- type TxManagerInterface
- type UserStorer
Constants ¶
This section is empty.
Variables ¶
View Source
var (
NeverExpires time.Duration = 0
)
View Source
var StoreProviderSet = wire.NewSet( wire.Bind(new(DBProviderInterface), new(*DBProvider)), NewDBProvider, wire.Bind(new(TxManagerInterface), new(*TxManager)), NewTxManager, NewUserStore, NewRoleStore, NewApiStore, NewCasbinStore, NewFeiShuUserStore, wire.Bind(new(CacheStorer), new(*CacheStore)), NewCacheStore, )
Functions ¶
func NewRepository ¶
func NewRepository[T any](dbProvider DBProviderInterface) *repository[T]
NewRepository 创建一个新的通用 Repository 实例。 它接收一个 DBProviderInterface,使得 Repository 能够获取到正确的 GORM DB 实例(可能是主 DB 或事务 DB)。
Types ¶
type ApiStorer ¶
type ApiStorer interface {
Create(ctx context.Context, obj *model.Api) error
CreateBatch(ctx context.Context, objs []*model.Api) error // 批量创建
Update(ctx context.Context, obj *model.Api, opts ...Option) error
Delete(ctx context.Context, obj *model.Api, opts ...Option) error // 增加选项,支持where条件删除
Query(ctx context.Context, opts ...Option) (*model.Api, error)
List(ctx context.Context, page, pageSize int, colum, oder string, opts ...Option) (total int64, objs []*model.Api, err error)
}
func NewApiStore ¶
func NewApiStore(dbProvider DBProviderInterface) ApiStorer
type CacheStore ¶
type CacheStore struct {
// contains filtered or unexported fields
}
func NewCacheStore ¶
func NewCacheStore(redisClient *redis.Client) (*CacheStore, func(), error)
func (*CacheStore) NormalizeCacheKey ¶
func (c *CacheStore) NormalizeCacheKey(cacheKey any) (string, error)
NormalizeCacheKey 将常用类型的 cacheKey 转换为 string
type CacheStorer ¶
type CasbinStorer ¶
type CasbinStorer interface {
Create(ctx context.Context, obj *model.CasbinRule) error
CreateBatch(ctx context.Context, objs []*model.CasbinRule) error // 批量创建
Update(ctx context.Context, obj *model.CasbinRule, opts ...Option) error
Delete(ctx context.Context, obj *model.CasbinRule, opts ...Option) error // 增加选项,支持where条件删除
DeleteBatch(ctx context.Context, objs []*model.CasbinRule, opts ...Option) error // 批量删除
Query(ctx context.Context, opts ...Option) (*model.CasbinRule, error)
List(ctx context.Context, page, pageSize int, colum, oder string, opts ...Option) (total int64, objs []*model.CasbinRule, err error)
}
func NewCasbinStore ¶
func NewCasbinStore(dbProvider DBProviderInterface) CasbinStorer
type DBProvider ¶
type DBProvider struct {
// contains filtered or unexported fields
}
DBProvider 是 DBProviderInterface 的实现。
func NewDBProvider ¶
func NewDBProvider(db *gorm.DB) *DBProvider
NewDBProvider 创建一个新的 DBProvider 实例。
type DBProviderInterface ¶
type DBProviderInterface interface {
// contains filtered or unexported methods
}
DBProviderInterface 数据库连接提供接口。
type FeiShuUserStorer ¶
type FeiShuUserStorer interface {
Create(ctx context.Context, obj *model.FeiShuUser) error
CreateBatch(ctx context.Context, objs []*model.FeiShuUser) error
Update(ctx context.Context, obj *model.FeiShuUser, opts ...Option) error
Delete(ctx context.Context, obj *model.FeiShuUser, opts ...Option) error
Query(ctx context.Context, opts ...Option) (*model.FeiShuUser, error)
List(ctx context.Context, page, pageSize int, colum, oder string, opts ...Option) (total int64, objs []*model.FeiShuUser, err error)
AppendAssociation(ctx context.Context, model *model.FeiShuUser, objName string, obj any) error
ReplaceAssociation(ctx context.Context, model *model.FeiShuUser, objName string, obj any) error
ClearAssociation(ctx context.Context, model *model.FeiShuUser, objName string) error
}
func NewFeiShuUserStore ¶
func NewFeiShuUserStore(dbProvider DBProviderInterface) FeiShuUserStorer
type Option ¶
Option 函数用于配置 GORM 查询。 它接收一个 *gorm.DB 实例并返回修改后的 *gorm.DB 实例, 从而允许链式调用 GORM 方法。
@example:
options := []store.Option{
store.Where("id", req.ID),
store.Where("status", model.UserStatusEnable),
store.Preload("Profile"),
store.Order("created_at desc"),
}
type RoleStorer ¶
type RoleStorer interface {
Create(ctx context.Context, obj *model.Role) error
CreateBatch(ctx context.Context, objs []*model.Role) error // 批量创建
Update(ctx context.Context, obj *model.Role, opts ...Option) error
Delete(ctx context.Context, obj *model.Role, opts ...Option) error // 增加选项,支持where条件删除
Query(ctx context.Context, opts ...Option) (*model.Role, error)
List(ctx context.Context, page, pageSize int, colum, oder string, opts ...Option) (total int64, objs []*model.Role, err error)
AppendAssociation(ctx context.Context, model *model.Role, objName string, obj any) error
ReplaceAssociation(ctx context.Context, model *model.Role, objName string, obj any) error
ClearAssociation(ctx context.Context, model *model.Role, objName string) error
}
func NewRoleStore ¶
func NewRoleStore(dbProvider DBProviderInterface) RoleStorer
type TxManager ¶
type TxManager struct {
// contains filtered or unexported fields
}
TxManager 是 TxManagerInterface 的实现。
type TxManagerInterface ¶
type TxManagerInterface interface {
// Transaction 在一个事务中执行给定的函数。
// 函数内部可以通过 GetTX(ctx) 获取事务 DB 实例,从而确保所有操作都在同一事务内。
Transaction(ctx context.Context, fn func(ctx context.Context) error) error
}
TxManagerInterface 事务管理器接口。
type UserStorer ¶
type UserStorer interface {
Create(ctx context.Context, obj *model.User) error
CreateBatch(ctx context.Context, objs []*model.User) error // 批量创建
Update(ctx context.Context, obj *model.User, opts ...Option) error
Delete(ctx context.Context, obj *model.User, opts ...Option) error // 增加选项,支持where条件删除
Query(ctx context.Context, opts ...Option) (*model.User, error)
List(ctx context.Context, page, pageSize int, colum, oder string, opts ...Option) (total int64, objs []*model.User, err error)
AppendAssociation(ctx context.Context, model *model.User, objName string, obj any) error
ReplaceAssociation(ctx context.Context, model *model.User, objName string, obj any) error
ClearAssociation(ctx context.Context, model *model.User, objName string) error
}
func NewUserStore ¶
func NewUserStore(dbProvider DBProviderInterface) UserStorer
Click to show internal directories.
Click to hide internal directories.