Documentation ¶
Index ¶
- Constants
- func WithDefaultCurr(curr int32)
- func WithDefaultSize(size int32)
- func WithTrashed(db *gorm.DB) *gorm.DB
- type ActionOption
- func WithContext[T any](ctx context.Context) ActionOption[T]
- func WithDB[T any](db *gorm.DB) ActionOption[T]
- func WithIAssociation[T any](o IAssociation) ActionOption[T]
- func WithICtx[T any](ctx ICtx) ActionOption[T]
- func WithIOperation[T any](o IOperation[T]) ActionOption[T]
- func WithIOperationX[T any](o IOperationX[T]) ActionOption[T]
- func WithTable[T any](table schema.Tabler) ActionOption[T]
- func WithTracer[T any](t Tracer) ActionOption[T]
- type AssociationKey
- type BaseModel
- type Ctx
- type IAction
- type IAssociation
- type IBind
- type ICtx
- type IOperation
- type IOperationMutation
- type IOperationMutationX
- type IOperationQuery
- type IOperationQueryX
- type IOperationX
- type IOrder
- type OpentracingPlugin
- type OperationImpl
- type OperationImplOption
- type OperationMutationOption
- type OperationMutationXOption
- type OperationQueryOption
- type OperationQueryXOption
- type OperationXImplOption
- type Order
- type Page
- type Pagination
- type ScopeMethod
- func BetweenColumn[T any](column string, min, max T) ScopeMethod
- func Paginate(pgInfo Pagination) ScopeMethod
- func WhereColumn[T any](column string, val ...T) ScopeMethod
- func WhereID(ids ...uint32) ScopeMethod
- func WhereInColumn[T any](column string, values ...T) ScopeMethod
- func WhereLikeKeyword(keyword string, columns ...string) ScopeMethod
- type Tracer
Constants ¶
const ( ASC orderType = true DESC orderType = false )
Variables ¶
This section is empty.
Functions ¶
func WithDefaultCurr ¶ added in v0.4.2
func WithDefaultCurr(curr int32)
WithDefaultCurr is used to set default curr
func WithDefaultSize ¶ added in v0.4.2
func WithDefaultSize(size int32)
WithDefaultSize is used to set default size
Types ¶
type ActionOption ¶
type ActionOption[T any] func(a *action[T])
func WithIAssociation ¶ added in v0.4.0
func WithIAssociation[T any](o IAssociation) ActionOption[T]
WithIAssociation 设置IAssociation
func WithIOperation ¶ added in v0.4.0
func WithIOperation[T any](o IOperation[T]) ActionOption[T]
WithIOperation 设置IOperation
func WithIOperationX ¶ added in v0.4.0
func WithIOperationX[T any](o IOperationX[T]) ActionOption[T]
WithIOperationX 设置IOperationX
func WithTracer ¶ added in v0.4.0
WithTracer 设置Tracer
type AssociationKey ¶ added in v0.3.1
type AssociationKey string
type BaseModel ¶
type BaseModel struct { ID uint32 `gorm:"primary_key" json:"id"` CreatedAt time.Time `gorm:"column:created_at;type:timestamp;not null;default:CURRENT_TIMESTAMP;comment:创建时间" json:"createdAt"` UpdatedAt time.Time `` /* 140-byte string literal not displayed */ DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at;type:bigint;not null;default:0;" json:"deletedAt"` }
type IAction ¶
type IAction[T any] interface { IOperation[T] IOperationX[T] IBind[T] IAssociation }
IAction 操作接口
type IAssociation ¶ added in v0.3.1
type IAssociation interface { // AssociationAppend 添加关联 AssociationAppend(associationKey AssociationKey, list ...schema.Tabler) error // AssociationReplace 替换关联 AssociationReplace(associationKey AssociationKey, list ...schema.Tabler) error // AssociationDelete 删除关联 AssociationDelete(associationKey AssociationKey, list ...schema.Tabler) error // AssociationClear 清除关联 AssociationClear(associationKey AssociationKey) error // AssociationCount 关联数量 AssociationCount(associationKey AssociationKey) int64 }
IAssociation 关联操作
func NewDefaultAssociation ¶ added in v0.3.1
func NewDefaultAssociation(db *gorm.DB) IAssociation
NewDefaultAssociation 创建默认关联
type IBind ¶ added in v0.1.0
type IBind[T any] interface { // WithDB 设置DB WithDB(db *gorm.DB) IAction[T] // WithContext 设置Ctx WithContext(ctx context.Context) IAction[T] // WithTable 设置Table WithTable(table schema.Tabler) IAction[T] // WithModel 设置Model WithModel(model any) IAction[T] // Preload 预加载 Preload(preloadKey string, wheres ...ScopeMethod) IAction[T] // Joins 设置关联 Joins(joinsKey string, wheres ...ScopeMethod) IAction[T] // Scopes 设置作用域 Scopes(wheres ...ScopeMethod) IAction[T] // Order 排序 Order(column string) IOrder[T] // Clauses 设置Clauses Clauses(condList ...clause.Expression) IAction[T] DB() *gorm.DB }
IBind 绑定操作, 用于链式操作
type IOperation ¶ added in v0.4.0
type IOperation[T any] interface { IOperationQuery[T] IOperationMutation[T] }
func NewOperationImpl ¶ added in v0.4.0
func NewOperationImpl[T any](opts ...OperationImplOption[T]) IOperation[T]
NewOperationImpl 实例化操作
type IOperationMutation ¶ added in v0.4.0
type IOperationMutation[T any] interface { // Create 创建数据 Create(m *T) error // BatchCreate 批量创建数据 BatchCreate(m []*T, max int) error // Update 更新数据 Update(m *T, wheres ...ScopeMethod) error // UpdateMap 通过map更新数据 UpdateMap(m map[string]any, wheres ...ScopeMethod) error // UpdateByID 根据ID更新数据 UpdateByID(id uint32, m *T, wheres ...ScopeMethod) error // UpdateMapByID 根据ID更新数据 UpdateMapByID(id uint32, m map[string]any, wheres ...ScopeMethod) error // Delete 删除数据 Delete(wheres ...ScopeMethod) error // DeleteByID 根据ID删除数据 DeleteByID(id uint32, wheres ...ScopeMethod) error // ForcedDelete 强制删除数据 ForcedDelete(wheres ...ScopeMethod) error // ForcedDeleteByID 根据ID强制删除数据 ForcedDeleteByID(id uint32, wheres ...ScopeMethod) error }
IOperationMutation 变更操作, 返回error
func NewOperationMutation ¶ added in v0.4.0
func NewOperationMutation[T any](opts ...OperationMutationOption[T]) IOperationMutation[T]
NewOperationMutation 实例化操作
type IOperationMutationX ¶ added in v0.4.0
type IOperationMutationX[T any] interface { // CreateX 创建数据 CreateX(m *T) // BatchCreateX 批量创建数据 BatchCreateX(m []*T, batchSize int) // UpdateX 更新数据 UpdateX(m *T, wheres ...ScopeMethod) // UpdateMapX 通过map更新数据 UpdateMapX(m map[string]any, wheres ...ScopeMethod) // UpdateByIDX 根据ID更新数据 UpdateByIDX(id uint32, m *T, wheres ...ScopeMethod) // UpdateMapByIDX 根据ID更新数据 UpdateMapByIDX(id uint32, m map[string]any, wheres ...ScopeMethod) // DeleteX 删除数据 DeleteX(wheres ...ScopeMethod) // DeleteByIDX 根据ID删除数据 DeleteByIDX(id uint32, wheres ...ScopeMethod) // ForcedDeleteX 强制删除数据 ForcedDeleteX(wheres ...ScopeMethod) // ForcedDeleteByIDX 根据ID强制删除数据 ForcedDeleteByIDX(id uint32, wheres ...ScopeMethod) GetMutationErr() error }
IOperationMutationX 变更操作, 不返回error
func NewOperationMutationX ¶ added in v0.4.0
func NewOperationMutationX[T any](opts ...OperationMutationXOption[T]) IOperationMutationX[T]
NewOperationMutationX 实例化操作
type IOperationQuery ¶ added in v0.4.0
type IOperationQuery[T any] interface { // First 查询单条数据 First(wheres ...ScopeMethod) (*T, error) // FirstWithTrashed 查询单条数据(包含软删除数据) FirstWithTrashed(wheres ...ScopeMethod) (*T, error) // FirstByID 根据ID查询单条数据 FirstByID(id uint32, wheres ...ScopeMethod) (*T, error) // FirstByIDWithTrashed 根据ID查询单条数据(包含软删除数据) FirstByIDWithTrashed(id uint32, wheres ...ScopeMethod) (*T, error) // Last 查询单条数据 Last(wheres ...ScopeMethod) (*T, error) // LastWithTrashed 查询单条数据(包含软删除数据) LastWithTrashed(wheres ...ScopeMethod) (*T, error) // LastByID 根据ID查询单条数据 LastByID(id uint32, wheres ...ScopeMethod) (*T, error) // LastByIDWithTrashed 根据ID查询单条数据(包含软删除数据) LastByIDWithTrashed(id uint32, wheres ...ScopeMethod) (*T, error) // List 查询多条数据 List(pgInfo Pagination, wheres ...ScopeMethod) ([]*T, error) // ListWithTrashed 查询多条数据(包含软删除数据) ListWithTrashed(pgInfo Pagination, wheres ...ScopeMethod) ([]*T, error) // Count 查询数量 Count(wheres ...ScopeMethod) (int64, error) // CountWithTrashed 查询数量(包含软删除数据) CountWithTrashed(wheres ...ScopeMethod) (int64, error) }
IOperationQuery 扩展查询操作, 返回error
func NewOperationQuery ¶ added in v0.4.0
func NewOperationQuery[T any](opts ...OperationQueryOption[T]) IOperationQuery[T]
NewOperationQuery 实例化查询操作
type IOperationQueryX ¶ added in v0.4.0
type IOperationQueryX[T any] interface { // FirstX 查询单条数据 FirstX(wheres ...ScopeMethod) *T // FirstWithTrashedX 查询单条数据(包含软删除数据) FirstWithTrashedX(wheres ...ScopeMethod) *T // FirstByIDX 根据ID查询单条数据 FirstByIDX(id uint32, wheres ...ScopeMethod) *T // FirstByIDWithTrashedX 根据ID查询单条数据(包含软删除数据) FirstByIDWithTrashedX(id uint32, wheres ...ScopeMethod) *T // LastX 查询单条数据 LastX(wheres ...ScopeMethod) *T // LastWithTrashedX 查询单条数据(包含软删除数据) LastWithTrashedX(wheres ...ScopeMethod) *T // LastByIDX 根据ID查询单条数据 LastByIDX(id uint32, wheres ...ScopeMethod) *T // LastByIDWithTrashedX 根据ID查询单条数据(包含软删除数据) LastByIDWithTrashedX(id uint32, wheres ...ScopeMethod) *T // ListX 查询多条数据 ListX(pgInfo Pagination, wheres ...ScopeMethod) []*T // ListWithTrashedX 查询多条数据(包含软删除数据) ListWithTrashedX(pgInfo Pagination, wheres ...ScopeMethod) []*T // CountX 查询数量 CountX(wheres ...ScopeMethod) int64 // CountWithTrashedX 查询数量(包含软删除数据) CountWithTrashedX(wheres ...ScopeMethod) int64 GetQueryErr() error }
IOperationQueryX 扩展查询操作, 不返回error
func NewOperationQueryX ¶ added in v0.4.0
func NewOperationQueryX[T any](opts ...OperationQueryXOption[T]) IOperationQueryX[T]
NewOperationQueryX 实例化查询操作
type IOperationX ¶ added in v0.4.0
type IOperationX[T any] interface { IOperationQueryX[T] IOperationMutationX[T] Err() error }
IOperationX 扩展操作, 不返回error
func NewOperationXImpl ¶ added in v0.4.0
func NewOperationXImpl[T any](opts ...OperationXImplOption[T]) IOperationX[T]
NewOperationXImpl 实例化操作
type OpentracingPlugin ¶ added in v0.1.0
type OpentracingPlugin struct{}
func NewOpentracingPlugin ¶ added in v0.1.0
func NewOpentracingPlugin() *OpentracingPlugin
NewOpentracingPlugin 创建一个opentracing插件
func (*OpentracingPlugin) Initialize ¶ added in v0.1.0
func (op *OpentracingPlugin) Initialize(db *gorm.DB) (err error)
func (*OpentracingPlugin) Name ¶ added in v0.1.0
func (op *OpentracingPlugin) Name() string
type OperationImpl ¶ added in v0.4.0
type OperationImpl[T any] struct { IOperationQuery[T] IOperationMutation[T] }
type OperationImplOption ¶ added in v0.4.0
type OperationImplOption[T any] func(*OperationImpl[T])
func WithOperationMutation ¶ added in v0.4.0
func WithOperationMutation[T any](mutation IOperationMutation[T]) OperationImplOption[T]
WithOperationMutation 设置变更
func WithOperationQuery ¶ added in v0.4.0
func WithOperationQuery[T any](query IOperationQuery[T]) OperationImplOption[T]
WithOperationQuery 设置查询
type OperationMutationOption ¶ added in v0.4.0
type OperationMutationOption[T any] func(*operationMutation[T])
func WithOperationMutationIBind ¶ added in v0.4.1
WithOperationMutationIBind 设置数据库
func WithOperationMutationICtx ¶ added in v0.4.1
WithOperationMutationICtx 设置上下文
func WithOperationMutationTracer ¶ added in v0.4.0
WithOperationMutationTracer 设置跟踪
type OperationMutationXOption ¶ added in v0.4.0
type OperationMutationXOption[T any] func(*operationMutationX[T])
func WithOperationMutationXIBind ¶ added in v0.4.1
WithOperationMutationXIBind 设置绑定
func WithOperationMutationXICtx ¶ added in v0.4.1
WithOperationMutationXICtx 设置上下文
func WithOperationMutationXTracer ¶ added in v0.4.0
WithOperationMutationXTracer 设置跟踪
type OperationQueryOption ¶ added in v0.4.0
type OperationQueryOption[T any] func(*operationQuery[T])
func WithOperationQueryIBind ¶ added in v0.4.0
WithOperationQueryIBind 设置IBind
func WithOperationQueryICtx ¶ added in v0.4.0
WithOperationQueryICtx 设置ICtx
func WithOperationQueryTracer ¶ added in v0.4.0
WithOperationQueryTracer 设置Tracer
type OperationQueryXOption ¶ added in v0.4.0
type OperationQueryXOption[T any] func(*operationQueryX[T])
func WithOperationQueryXIBind ¶ added in v0.4.0
WithOperationQueryXIBind 设置IBind
func WithOperationQueryXICtx ¶ added in v0.4.0
WithOperationQueryXICtx 设置ICtx
func WithOperationQueryXTracer ¶ added in v0.4.0
WithOperationQueryXTracer 设置Tracer
type OperationXImplOption ¶ added in v0.4.0
type OperationXImplOption[T any] func(*operationXImpl[T])
func WithOperationMutationX ¶ added in v0.4.0
func WithOperationMutationX[T any](mutation IOperationMutationX[T]) OperationXImplOption[T]
WithOperationMutationX 设置变更
func WithOperationQueryX ¶ added in v0.4.0
func WithOperationQueryX[T any](query IOperationQueryX[T]) OperationXImplOption[T]
WithOperationQueryX 设置查询
type Order ¶ added in v0.1.0
func (*Order[T]) WithIAction ¶ added in v0.1.0
func (o *Order[T]) WithIAction(action IAction[T]) *Order[T]
type Pagination ¶
type ScopeMethod ¶ added in v0.4.0
func BetweenColumn ¶ added in v0.1.0
func BetweenColumn[T any](column string, min, max T) ScopeMethod
BetweenColumn 通过字段名和值列表进行查询
func WhereColumn ¶ added in v0.1.0
func WhereColumn[T any](column string, val ...T) ScopeMethod
WhereColumn 通过字段名和值进行查询
func WhereInColumn ¶
func WhereInColumn[T any](column string, values ...T) ScopeMethod
WhereInColumn 通过字段名和值列表进行查询
func WhereLikeKeyword ¶
func WhereLikeKeyword(keyword string, columns ...string) ScopeMethod
WhereLikeKeyword 模糊查询