Documentation
¶
Overview ¶
* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 21:13:15 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-13 11:07:41 * @FilePath: \go-sqlbuilder\persist\query_param.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-10 01:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-13 07:45:23 * @FilePath: \go-sqlbuilder\repository\cache_manager.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-10 01:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-11 09:20:54 * @FilePath: \go-sqlbuilder\repository\interfaces.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
Index ¶
- type BaseRepository
- func (r *BaseRepository[T]) Count(ctx context.Context, filters ...*Filter) (int64, error)
- func (r *BaseRepository[T]) Create(ctx context.Context, entity *T) (*T, error)
- func (r *BaseRepository[T]) CreateBatch(ctx context.Context, entities ...*T) error
- func (r *BaseRepository[T]) Delete(ctx context.Context, id interface{}) error
- func (r *BaseRepository[T]) DeleteBatch(ctx context.Context, ids ...interface{}) error
- func (r *BaseRepository[T]) DeleteByFilters(ctx context.Context, filters ...*Filter) error
- func (r *BaseRepository[T]) Exists(ctx context.Context, filters ...*Filter) (bool, error)
- func (r *BaseRepository[T]) Get(ctx context.Context, id interface{}) (*T, error)
- func (r *BaseRepository[T]) GetByFilter(ctx context.Context, filter *Filter) (*T, error)
- func (r *BaseRepository[T]) GetByFilters(ctx context.Context, filters ...*Filter) (*T, error)
- func (r *BaseRepository[T]) List(ctx context.Context, query *Query) ([]*T, error)
- func (r *BaseRepository[T]) ListWithPagination(ctx context.Context, query *Query, page *meta.Paging) ([]*T, *meta.Paging, error)
- func (r *BaseRepository[T]) Transaction(ctx context.Context, fn func(tx Transaction) error) error
- func (r *BaseRepository[T]) Update(ctx context.Context, entity *T) (*T, error)
- func (r *BaseRepository[T]) UpdateBatch(ctx context.Context, entities ...*T) error
- func (r *BaseRepository[T]) UpdateByFilters(ctx context.Context, entity *T, filters ...*Filter) error
- type CacheConfig
- type CacheManager
- type CacheManagerImpl
- func (m *CacheManagerImpl) BatchDelete(ctx context.Context, keys ...string) error
- func (m *CacheManagerImpl) BatchGet(ctx context.Context, keys ...string) (map[string]interface{}, error)
- func (m *CacheManagerImpl) BatchSet(ctx context.Context, items map[string]interface{}, ttl time.Duration) error
- func (m *CacheManagerImpl) Delete(ctx context.Context, keys ...string) error
- func (m *CacheManagerImpl) DeletePattern(ctx context.Context, pattern string) error
- func (m *CacheManagerImpl) Exists(ctx context.Context, key string) (bool, error)
- func (m *CacheManagerImpl) Get(ctx context.Context, key string) (interface{}, error)
- func (m *CacheManagerImpl) Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error
- func (m *CacheManagerImpl) TTL(ctx context.Context, key string) (time.Duration, error)
- type Filter
- func NewBetweenFilter(field string, min, max interface{}) *Filter
- func NewEqFilter(field string, value interface{}) *Filter
- func NewGtFilter(field string, value interface{}) *Filter
- func NewGteFilter(field string, value interface{}) *Filter
- func NewInFilter(field string, values ...interface{}) *Filter
- func NewLikeFilter(field string, value string) *Filter
- func NewLtFilter(field string, value interface{}) *Filter
- func NewLteFilter(field string, value interface{}) *Filter
- func NewNeqFilter(field string, value interface{}) *Filter
- type Order
- type Query
- type Repository
- type RepositoryFactory
- type Transaction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseRepository ¶
type BaseRepository[T any] struct { // contains filtered or unexported fields }
BaseRepository 基础仓储实现,包含通用的 CRUD 操作
func NewBaseRepository ¶
func NewBaseRepository[T any](dbHandler db.Handler, table string) *BaseRepository[T]
NewBaseRepository 创建基础仓储
func (*BaseRepository[T]) Create ¶
func (r *BaseRepository[T]) Create(ctx context.Context, entity *T) (*T, error)
Create 创建单个记录
func (*BaseRepository[T]) CreateBatch ¶
func (r *BaseRepository[T]) CreateBatch(ctx context.Context, entities ...*T) error
CreateBatch 批量创建记录
func (*BaseRepository[T]) Delete ¶
func (r *BaseRepository[T]) Delete(ctx context.Context, id interface{}) error
Delete 删除单个记录
func (*BaseRepository[T]) DeleteBatch ¶
func (r *BaseRepository[T]) DeleteBatch(ctx context.Context, ids ...interface{}) error
DeleteBatch 批量删除记录
func (*BaseRepository[T]) DeleteByFilters ¶
func (r *BaseRepository[T]) DeleteByFilters(ctx context.Context, filters ...*Filter) error
DeleteByFilters 按过滤条件删除记录
func (*BaseRepository[T]) Get ¶
func (r *BaseRepository[T]) Get(ctx context.Context, id interface{}) (*T, error)
Get 获取单个记录
func (*BaseRepository[T]) GetByFilter ¶
func (r *BaseRepository[T]) GetByFilter(ctx context.Context, filter *Filter) (*T, error)
GetByFilter 按单个过滤条件获取记录
func (*BaseRepository[T]) GetByFilters ¶
func (r *BaseRepository[T]) GetByFilters(ctx context.Context, filters ...*Filter) (*T, error)
GetByFilters 按多个过滤条件获取记录
func (*BaseRepository[T]) List ¶
func (r *BaseRepository[T]) List(ctx context.Context, query *Query) ([]*T, error)
List 列表查询
func (*BaseRepository[T]) ListWithPagination ¶
func (r *BaseRepository[T]) ListWithPagination(ctx context.Context, query *Query, page *meta.Paging) ([]*T, *meta.Paging, error)
ListWithPagination 分页列表查询
func (*BaseRepository[T]) Transaction ¶
func (r *BaseRepository[T]) Transaction(ctx context.Context, fn func(tx Transaction) error) error
Transaction 事务支持
func (*BaseRepository[T]) Update ¶
func (r *BaseRepository[T]) Update(ctx context.Context, entity *T) (*T, error)
Update 更新单个记录
func (*BaseRepository[T]) UpdateBatch ¶
func (r *BaseRepository[T]) UpdateBatch(ctx context.Context, entities ...*T) error
UpdateBatch 批量更新记录
func (*BaseRepository[T]) UpdateByFilters ¶
func (r *BaseRepository[T]) UpdateByFilters(ctx context.Context, entity *T, filters ...*Filter) error
UpdateByFilters 按过滤条件更新记录
type CacheManager ¶
type CacheManager interface {
// 获取
Get(ctx context.Context, key string) (interface{}, error)
// 设置
Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error
// 删除
Delete(ctx context.Context, keys ...string) error
// 删除匹配的键
DeletePattern(ctx context.Context, pattern string) error
// 检查存在
Exists(ctx context.Context, key string) (bool, error)
// 获取 TTL
TTL(ctx context.Context, key string) (time.Duration, error)
// 批量操作
BatchGet(ctx context.Context, keys ...string) (map[string]interface{}, error)
BatchSet(ctx context.Context, items map[string]interface{}, ttl time.Duration) error
BatchDelete(ctx context.Context, keys ...string) error
}
CacheManager 缓存管理接口
func NewCacheManager ¶
func NewCacheManager(handler cache.Handler) CacheManager
NewCacheManager 创建缓存管理器
type CacheManagerImpl ¶
type CacheManagerImpl struct {
// contains filtered or unexported fields
}
CacheManagerImpl 缓存管理器实现
func (*CacheManagerImpl) BatchDelete ¶
func (m *CacheManagerImpl) BatchDelete(ctx context.Context, keys ...string) error
BatchDelete 批量删除缓存键
func (*CacheManagerImpl) BatchGet ¶
func (m *CacheManagerImpl) BatchGet(ctx context.Context, keys ...string) (map[string]interface{}, error)
BatchGet 批量获取缓存值
func (*CacheManagerImpl) BatchSet ¶
func (m *CacheManagerImpl) BatchSet(ctx context.Context, items map[string]interface{}, ttl time.Duration) error
BatchSet 批量设置缓存值
func (*CacheManagerImpl) Delete ¶
func (m *CacheManagerImpl) Delete(ctx context.Context, keys ...string) error
Delete 删除单个或多个缓存键
func (*CacheManagerImpl) DeletePattern ¶
func (m *CacheManagerImpl) DeletePattern(ctx context.Context, pattern string) error
DeletePattern 删除匹配模式的所有键(仅适用于支持的后端)
func (*CacheManagerImpl) Get ¶
func (m *CacheManagerImpl) Get(ctx context.Context, key string) (interface{}, error)
Get 获取缓存值
type Filter ¶
type Filter struct {
Field string
Operator string // "=", ">", "<", ">=", "<=", "!=", "in", "like", "between"
Value interface{}
}
Filter 数据库查询过滤条件
func NewBetweenFilter ¶
NewBetweenFilter 创建 BETWEEN 过滤条件
func NewGteFilter ¶
NewGteFilter 创建大于等于过滤条件
func NewInFilter ¶
NewInFilter 创建 IN 过滤条件
func NewLikeFilter ¶
NewLikeFilter 创建 LIKE 过滤条件
func NewLteFilter ¶
NewLteFilter 创建小于等于过滤条件
func NewNeqFilter ¶
NewNeqFilter 创建不等于过滤条件
type Repository ¶
type Repository[T any] interface { // 创建 Create(ctx context.Context, entity *T) (*T, error) CreateBatch(ctx context.Context, entities ...*T) error // 读取 Get(ctx context.Context, id interface{}) (*T, error) GetByFilter(ctx context.Context, filter *Filter) (*T, error) GetByFilters(ctx context.Context, filters ...*Filter) (*T, error) List(ctx context.Context, query *Query) ([]*T, error) ListWithPagination(ctx context.Context, query *Query, page *meta.Paging) ([]*T, *meta.Paging, error) // 更新 Update(ctx context.Context, entity *T) (*T, error) UpdateBatch(ctx context.Context, entities ...*T) error UpdateByFilters(ctx context.Context, entity *T, filters ...*Filter) error // 删除 Delete(ctx context.Context, id interface{}) error DeleteBatch(ctx context.Context, ids ...interface{}) error DeleteByFilters(ctx context.Context, filters ...*Filter) error // 事务 Transaction(ctx context.Context, fn func(tx Transaction) error) error // 工具方法 Count(ctx context.Context, filters ...*Filter) (int64, error) Exists(ctx context.Context, filters ...*Filter) (bool, error) }
Repository 通用仓储接口
type RepositoryFactory ¶
type RepositoryFactory interface {
// 缓存管理
CacheManager() CacheManager
// 关闭工厂
Close() error
}
RepositoryFactory 仓储工厂接口
type Transaction ¶
type Transaction interface {
// 执行事务内的操作
Create(ctx context.Context, entity interface{}) error
CreateBatch(ctx context.Context, entities ...interface{}) error
Update(ctx context.Context, entity interface{}) error
UpdateBatch(ctx context.Context, entities ...interface{}) error
Delete(ctx context.Context, entity interface{}) error
DeleteBatch(ctx context.Context, entities ...interface{}) error
}
Transaction 事务接口