Documentation
¶
Overview ¶
Package orm 提供独立的 MyBatis/MyBatis-Plus 风格 Go ORM 运行时。
包内包含实体元数据、Configuration、GlobalConfig/DbConfig、结构化错误层级、Statement 编译、SQL Provider、参数路径绑定、MetaObjectHandler 自动填充、ResultMap constructor/association/collection 嵌套映射和 discriminator 分派、SQLSession、执行器/Handler SPI、REUSE 预编译语句复用、事务 Session、BatchSession、游标流式查询、显式 Lazy 延迟加载、一级缓存、Mapper namespace 二级缓存、条件构造器、分页模型、主键策略、Service 层和拦截器 SPI。 生成器输出的 Mapper 只依赖 Session 接口,因此自动提交 Session、事务 Session、BatchSession 和流式查询签名可以共用同一套生成代码。
Index ¶
- Constants
- Variables
- func BetweenTypedValues[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], left V, right V) W
- func BetweenTypedValuesIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], left V, right V) W
- func EqTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
- func EqTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
- func GeTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
- func GeTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
- func GtTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
- func GtTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
- func InTypedValues[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], values ...V) W
- func InTypedValuesIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], values ...V) W
- func LeTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
- func LeTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
- func LikeLeftTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
- func LikeLeftTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
- func LikeRightTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
- func LikeRightTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
- func LikeTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
- func LikeTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
- func LtTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
- func LtTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
- func NeTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
- func NeTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
- func NotBetweenTypedValues[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], left V, right V) W
- func NotBetweenTypedValuesIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], left V, right V) W
- func NotInTypedValues[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], values ...V) W
- func NotInTypedValuesIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], values ...V) W
- func NotLikeTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
- func NotLikeTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
- func QueryEach[T any](ctx context.Context, session Session, statement string, args NamedArgs, ...) error
- func RegisterInjectedStatements(registry *Registry, namespace string, entity EntityMeta, injector SQLInjector, ...) error
- func StatementInterceptorIgnored(statement StatementMeta, name string) bool
- func WithDataSource(ctx context.Context, key DataSourceKey) context.Context
- func WithPageRequest(ctx context.Context, page PageRequest) context.Context
- type BaseMapper
- func (m *BaseMapper[T, ID]) Count(ctx context.Context, wrapper *QueryWrapper[T]) (int64, error)
- func (m *BaseMapper[T, ID]) Delete(ctx context.Context, wrapper *QueryWrapper[T]) (int64, error)
- func (m *BaseMapper[T, ID]) DeleteBatchIDs(ctx context.Context, ids []ID) (int64, error)
- func (m *BaseMapper[T, ID]) DeleteByEntity(ctx context.Context, entity *T) (int64, error)
- func (m *BaseMapper[T, ID]) DeleteByID(ctx context.Context, id ID) (int64, error)
- func (m *BaseMapper[T, ID]) DeleteByMap(ctx context.Context, columnMap map[string]any) (int64, error)
- func (m *BaseMapper[T, ID]) EntityQueryWrapper(entity *T) (*QueryWrapper[T], error)
- func (m *BaseMapper[T, ID]) Insert(ctx context.Context, entity *T) (Result, error)
- func (m *BaseMapper[T, ID]) InsertBatch(ctx context.Context, entities []T) (int64, error)
- func (m *BaseMapper[T, ID]) InsertBatchSize(ctx context.Context, entities []T, batchSize int) (int64, error)
- func (m *BaseMapper[T, ID]) SaveOrUpdate(ctx context.Context, entity *T) (Result, error)
- func (m *BaseMapper[T, ID]) SaveOrUpdateBatch(ctx context.Context, entities []T) (int64, error)
- func (m *BaseMapper[T, ID]) SaveOrUpdateBatchSize(ctx context.Context, entities []T, batchSize int) (int64, error)
- func (m *BaseMapper[T, ID]) SelectBatchIDs(ctx context.Context, ids []ID) ([]T, error)
- func (m *BaseMapper[T, ID]) SelectByID(ctx context.Context, id ID) (*T, error)
- func (m *BaseMapper[T, ID]) SelectByMap(ctx context.Context, columnMap map[string]any) ([]T, error)
- func (m *BaseMapper[T, ID]) SelectCount(ctx context.Context, wrapper *QueryWrapper[T]) (int64, error)
- func (m *BaseMapper[T, ID]) SelectCountByEntity(ctx context.Context, entity *T) (int64, error)
- func (m *BaseMapper[T, ID]) SelectList(ctx context.Context, wrapper *QueryWrapper[T]) ([]T, error)
- func (m *BaseMapper[T, ID]) SelectListByEntity(ctx context.Context, entity *T) ([]T, error)
- func (m *BaseMapper[T, ID]) SelectMaps(ctx context.Context, wrapper *QueryWrapper[T]) ([]map[string]any, error)
- func (m *BaseMapper[T, ID]) SelectMapsPage(ctx context.Context, page PageRequest, wrapper *QueryWrapper[T]) (Page[map[string]any], error)
- func (m *BaseMapper[T, ID]) SelectObjs(ctx context.Context, wrapper *QueryWrapper[T]) ([]any, error)
- func (m *BaseMapper[T, ID]) SelectOne(ctx context.Context, wrapper *QueryWrapper[T]) (*T, error)
- func (m *BaseMapper[T, ID]) SelectPage(ctx context.Context, page PageRequest, wrapper *QueryWrapper[T]) (Page[T], error)
- func (m *BaseMapper[T, ID]) Update(ctx context.Context, entity *T, wrapper *QueryWrapper[T]) (int64, error)
- func (m *BaseMapper[T, ID]) UpdateBatchByID(ctx context.Context, entities []T) (int64, error)
- func (m *BaseMapper[T, ID]) UpdateBatchByIDSize(ctx context.Context, entities []T, batchSize int) (int64, error)
- func (m *BaseMapper[T, ID]) UpdateByID(ctx context.Context, entity *T) (int64, error)
- func (m *BaseMapper[T, ID]) UpdateWithWrapper(ctx context.Context, wrapper *UpdateWrapper[T]) (int64, error)
- type BaseMapperOption
- func WithBaseMapperClock(clock func() time.Time) BaseMapperOption
- func WithBaseMapperDialect(dialect Dialect) BaseMapperOption
- func WithBaseMapperGlobalConfig(global GlobalConfig) BaseMapperOption
- func WithBaseMapperIdentifierGenerator(generator IdentifierGenerator) BaseMapperOption
- func WithBaseMapperMetaObjectHandler(handler MetaObjectHandler) BaseMapperOption
- type BatchError
- type BatchResult
- type BatchSession
- func (s *BatchSession) Call(ctx context.Context, statement string, args NamedArgs, resultSets ...any) (CallResult, error)
- func (s *BatchSession) CallStatement(ctx context.Context, statement StatementMeta, args NamedArgs, ...) (CallResult, error)
- func (s *BatchSession) Clear()
- func (s *BatchSession) Close() error
- func (s *BatchSession) Commit() error
- func (s *BatchSession) CommitContext(ctx context.Context) error
- func (s *BatchSession) Dialect() Dialect
- func (s *BatchSession) Exec(ctx context.Context, statement string, args NamedArgs) (Result, error)
- func (s *BatchSession) ExecStatement(ctx context.Context, statement StatementMeta, args NamedArgs) (Result, error)
- func (s *BatchSession) Flush(ctx context.Context) ([]BatchResult, error)
- func (s *BatchSession) Len() int
- func (s *BatchSession) Query(ctx context.Context, statement string, args NamedArgs, dest any) error
- func (s *BatchSession) QueryCursor(ctx context.Context, statement string, args NamedArgs) (*RowCursor, error)
- func (s *BatchSession) QueryOne(ctx context.Context, statement string, args NamedArgs, dest any) error
- func (s *BatchSession) QueryOneStatement(ctx context.Context, statement StatementMeta, args NamedArgs, dest any) error
- func (s *BatchSession) QueryPage(ctx context.Context, statement string, args NamedArgs, page PageRequest, ...) (PageQueryResult, error)
- func (s *BatchSession) QueryStatement(ctx context.Context, statement StatementMeta, args NamedArgs, dest any) error
- func (s *BatchSession) Rollback() error
- type BindingError
- type BlockingCache
- func (c *BlockingCache) Clear(ctx context.Context) error
- func (c *BlockingCache) Get(ctx context.Context, key string) (any, bool, error)
- func (c *BlockingCache) Put(ctx context.Context, key string, value any) error
- func (c *BlockingCache) ReleaseMiss(ctx context.Context, key string) error
- func (c *BlockingCache) Remove(ctx context.Context, key string) error
- func (c *BlockingCache) Stats() CacheStats
- type Cache
- type CacheMeta
- type CacheMissReleaser
- type CacheStats
- type CacheStatsProvider
- type CallResult
- type CallSession
- type ColumnMeta
- type CompiledSQL
- type Configuration
- type ConfigurationError
- type Cursor
- type CursorQuerySession
- type DataPermissionProvider
- type DataSourceKey
- type DataSourceResolver
- type Db
- type DbConfig
- type DbType
- type DefaultIdentifierGenerator
- type Dialect
- type DialectCapabilities
- type DialectCapabilitiesProvider
- type DialectGeneratedKeyStyle
- type DialectIdentifierQuoteStyle
- type DialectJSONStyle
- type DialectPlaceholderStyle
- type DialectRowLockStyle
- type DialectUpsertStyle
- type DynamicSQLNode
- type DynamicSQLNodeKind
- type EntityMeta
- type EntitySemanticInterceptorOption
- type EnumValuer
- type EnumValuerContext
- type ExecutorError
- type ExecutorType
- type Field
- type FieldFill
- type FieldStrategy
- type GlobalConfig
- type IDType
- type IdentifierGenerator
- type IllegalSQLOption
- type InjectOption
- type Lazy
- type LazySlice
- type LocalCacheScope
- type LogicDeleteByIDInjector
- type ManagedSession
- type MapperMeta
- type MapperRef
- type MappingError
- type MemoryCache
- func (c *MemoryCache) Clear(ctx context.Context) error
- func (c *MemoryCache) Get(ctx context.Context, key string) (any, bool, error)
- func (c *MemoryCache) Put(ctx context.Context, key string, value any) error
- func (c *MemoryCache) Remove(ctx context.Context, key string) error
- func (c *MemoryCache) Stats() CacheStats
- type MemoryCacheOption
- type MetaObject
- func (m *MetaObject) Args() NamedArgs
- func (m *MetaObject) Entity() EntityMeta
- func (m *MetaObject) FieldValue(name string) (any, bool, error)
- func (m *MetaObject) HasField(name string) bool
- func (m *MetaObject) SetField(name string, value any) error
- func (m *MetaObject) SetFieldIfZero(name string, value any) error
- func (m *MetaObject) StrictInsertFill(name string, value any) error
- func (m *MetaObject) StrictUpdateFill(name string, value any) error
- type MetaObjectHandler
- type MetaObjectHandlerFuncs
- type MyBatisConfig
- type MyBatisEnvironment
- type MyBatisSettings
- type NamedArgs
- type Page
- type PageQueryResult
- type PageQuerySession
- type PageRequest
- type ParameterHandler
- type ParameterHandlerMiddleware
- type ParameterHandlerMiddlewareFunc
- type ParameterMeta
- type ParameterMode
- type QueryChain
- func (c *QueryChain[T, ID]) Count(ctx context.Context) (int64, error)
- func (c *QueryChain[T, ID]) Eq(field Field[T], value any) *QueryChain[T, ID]
- func (c *QueryChain[T, ID]) First(ctx context.Context) (*T, error)
- func (c *QueryChain[T, ID]) Like(field Field[T], value any) *QueryChain[T, ID]
- func (c *QueryChain[T, ID]) List(ctx context.Context) ([]T, error)
- func (c *QueryChain[T, ID]) Map(ctx context.Context) (map[string]any, error)
- func (c *QueryChain[T, ID]) Maps(ctx context.Context) ([]map[string]any, error)
- func (c *QueryChain[T, ID]) Obj(ctx context.Context) (any, error)
- func (c *QueryChain[T, ID]) Objs(ctx context.Context) ([]any, error)
- func (c *QueryChain[T, ID]) One(ctx context.Context) (*T, error)
- func (c *QueryChain[T, ID]) OrderByAsc(field Field[T]) *QueryChain[T, ID]
- func (c *QueryChain[T, ID]) OrderByDesc(field Field[T]) *QueryChain[T, ID]
- func (c *QueryChain[T, ID]) Page(ctx context.Context, page PageRequest) (Page[T], error)
- func (c *QueryChain[T, ID]) Where(apply func(*QueryWrapper[T])) *QueryChain[T, ID]
- func (c *QueryChain[T, ID]) Wrapper() *QueryWrapper[T]
- type QueryWrapper
- func (w *QueryWrapper[T]) AllEq(values map[Field[T]]any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) And(apply func(*QueryWrapper[T])) *QueryWrapper[T]
- func (w *QueryWrapper[T]) Apply(sqlText string, args NamedArgs) *QueryWrapper[T]
- func (w *QueryWrapper[T]) Between(field Field[T], left any, right any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) BetweenTyped(field TypedFieldRef[T], left any, right any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) Empty() bool
- func (w *QueryWrapper[T]) Eq(field Field[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) EqIf(condition bool, field Field[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) EqTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) Exists(sqlText string, args NamedArgs) *QueryWrapper[T]
- func (w *QueryWrapper[T]) Ge(field Field[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) GeTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) GroupBy(fields ...Field[T]) *QueryWrapper[T]
- func (w *QueryWrapper[T]) GroupByTyped(fields ...TypedFieldRef[T]) *QueryWrapper[T]
- func (w *QueryWrapper[T]) Gt(field Field[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) GtTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) Having(sqlText string, args NamedArgs) *QueryWrapper[T]
- func (w *QueryWrapper[T]) In(field Field[T], values any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) InTyped(field TypedFieldRef[T], values any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) IsNotNull(field Field[T]) *QueryWrapper[T]
- func (w *QueryWrapper[T]) IsNotNullTyped(field TypedFieldRef[T]) *QueryWrapper[T]
- func (w *QueryWrapper[T]) IsNull(field Field[T]) *QueryWrapper[T]
- func (w *QueryWrapper[T]) IsNullTyped(field TypedFieldRef[T]) *QueryWrapper[T]
- func (w *QueryWrapper[T]) Last(sqlText string) *QueryWrapper[T]
- func (w *QueryWrapper[T]) Le(field Field[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) LeTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) Like(field Field[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) LikeLeft(field Field[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) LikeLeftTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) LikeRight(field Field[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) LikeRightTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) LikeTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) Lt(field Field[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) LtTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) Ne(field Field[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) NeTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) Nested(apply func(*QueryWrapper[T])) *QueryWrapper[T]
- func (w *QueryWrapper[T]) NotBetween(field Field[T], left any, right any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) NotBetweenTyped(field TypedFieldRef[T], left any, right any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) NotExists(sqlText string, args NamedArgs) *QueryWrapper[T]
- func (w *QueryWrapper[T]) NotIn(field Field[T], values any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) NotInTyped(field TypedFieldRef[T], values any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) NotLike(field Field[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) NotLikeTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
- func (w *QueryWrapper[T]) Or(apply func(*QueryWrapper[T])) *QueryWrapper[T]
- func (w *QueryWrapper[T]) OrderBy(condition bool, asc bool, fields ...Field[T]) *QueryWrapper[T]
- func (w *QueryWrapper[T]) OrderByAsc(field Field[T]) *QueryWrapper[T]
- func (w *QueryWrapper[T]) OrderByAscTyped(field TypedFieldRef[T]) *QueryWrapper[T]
- func (w *QueryWrapper[T]) OrderByDesc(field Field[T]) *QueryWrapper[T]
- func (w *QueryWrapper[T]) OrderByDescTyped(field TypedFieldRef[T]) *QueryWrapper[T]
- func (w *QueryWrapper[T]) OrderByTyped(condition bool, asc bool, fields ...TypedFieldRef[T]) *QueryWrapper[T]
- func (w *QueryWrapper[T]) Select(fields ...Field[T]) *QueryWrapper[T]
- func (w *QueryWrapper[T]) SelectTyped(fields ...TypedFieldRef[T]) *QueryWrapper[T]
- func (w *QueryWrapper[T]) When(condition bool, apply func(*QueryWrapper[T])) *QueryWrapper[T]
- type RawIdentifier
- type RawOrderBy
- type RawOrderItem
- type RawSQLToken
- type Registry
- func (r *Registry) Cache(namespace string) (Cache, string, bool)
- func (r *Registry) Entities() []EntityMeta
- func (r *Registry) Entity(typeName string) (EntityMeta, bool)
- func (r *Registry) Mapper(namespace string) (MapperMeta, bool)
- func (r *Registry) Mappers() []MapperMeta
- func (r *Registry) RegisterCache(namespace string, cache Cache) error
- func (r *Registry) RegisterEntity(meta EntityMeta) error
- func (r *Registry) RegisterMapper(meta MapperMeta) error
- func (r *Registry) RegisterRowScanner(typeName string, scanner RowScanner) error
- func (r *Registry) RegisterSQLProvider(name string, provider SQLProvider) error
- func (r *Registry) RegisterTypeHandler(name string, handler TypeHandler) error
- func (r *Registry) RegisterTypeHandlers(handlers map[string]TypeHandler) error
- func (r *Registry) RowScanner(typeName string) (RowScanner, bool)
- func (r *Registry) SQLProvider(name string) (SQLProvider, bool)
- func (r *Registry) Statement(fullName string) (StatementMeta, bool)
- func (r *Registry) TypeHandler(name string) (TypeHandler, bool)
- func (r *Registry) TypeHandlers() map[string]TypeHandler
- type RegistryError
- type RenderedSQL
- type Result
- type ResultArgMeta
- type ResultAssociationMeta
- type ResultCollectionMeta
- type ResultConstructorMeta
- type ResultDiscriminatorCaseMeta
- type ResultDiscriminatorMeta
- type ResultFieldMeta
- type ResultHandler
- type ResultMapMeta
- type ResultSetHandler
- type ResultSetHandlerMiddleware
- type ResultSetHandlerMiddlewareFunc
- type ResultSetMeta
- type ResultSetRows
- type ResultSetType
- type RoutingOperation
- type RoutingOperationKind
- type RoutingSession
- func (s *RoutingSession) Call(ctx context.Context, statement string, args NamedArgs, resultSets ...any) (CallResult, error)
- func (s *RoutingSession) Close() error
- func (s *RoutingSession) Exec(ctx context.Context, statement string, args NamedArgs) (Result, error)
- func (s *RoutingSession) Query(ctx context.Context, statement string, args NamedArgs, dest any) error
- func (s *RoutingSession) QueryOne(ctx context.Context, statement string, args NamedArgs, dest any) error
- func (s *RoutingSession) QueryPage(ctx context.Context, statement string, args NamedArgs, page PageRequest, ...) (PageQueryResult, error)
- type RoutingSessionFactory
- type RoutingSessionOption
- type RowCursor
- type RowScanner
- type RowScannerFunc
- type RowScannerRow
- type Rows
- type SQLCondition
- type SQLExecutor
- type SQLFetchSizeApplier
- type SQLGuardRule
- type SQLGuardRuleFunc
- type SQLInjector
- type SQLInjectorFunc
- type SQLObservation
- type SQLPreparer
- type SQLProvider
- type SQLSession
- func (s *SQLSession) Call(ctx context.Context, statement string, args NamedArgs, resultSets ...any) (CallResult, error)
- func (s *SQLSession) CallStatement(ctx context.Context, meta StatementMeta, args NamedArgs, resultSets ...any) (CallResult, error)
- func (s *SQLSession) Close() error
- func (s *SQLSession) Commit() error
- func (s *SQLSession) Configuration() Configuration
- func (s *SQLSession) Dialect() Dialect
- func (s *SQLSession) Exec(ctx context.Context, statement string, args NamedArgs) (Result, error)
- func (s *SQLSession) ExecStatement(ctx context.Context, meta StatementMeta, args NamedArgs) (Result, error)
- func (s *SQLSession) GlobalConfig() GlobalConfig
- func (s *SQLSession) IdentifierGenerator() IdentifierGenerator
- func (s *SQLSession) MetaObjectHandler() MetaObjectHandler
- func (s *SQLSession) Query(ctx context.Context, statement string, args NamedArgs, dest any) error
- func (s *SQLSession) QueryCursor(ctx context.Context, statement string, args NamedArgs) (*RowCursor, error)
- func (s *SQLSession) QueryCursorStatement(ctx context.Context, meta StatementMeta, args NamedArgs) (*RowCursor, error)
- func (s *SQLSession) QueryOne(ctx context.Context, statement string, args NamedArgs, dest any) error
- func (s *SQLSession) QueryOneStatement(ctx context.Context, meta StatementMeta, args NamedArgs, dest any) error
- func (s *SQLSession) QueryPage(ctx context.Context, statement string, args NamedArgs, page PageRequest, ...) (PageQueryResult, error)
- func (s *SQLSession) QueryPageStatement(ctx context.Context, meta StatementMeta, args NamedArgs, page PageRequest, ...) (PageQueryResult, error)
- func (s *SQLSession) QueryStatement(ctx context.Context, meta StatementMeta, args NamedArgs, dest any) error
- func (s *SQLSession) Rollback() error
- type SQLSessionFactory
- func (f *SQLSessionFactory) BeginBatchTx(ctx context.Context, opts *sql.TxOptions) (*BatchSession, error)
- func (f *SQLSessionFactory) BeginTx(ctx context.Context, opts *sql.TxOptions) (*TxSession, error)
- func (f *SQLSessionFactory) InTx(ctx context.Context, opts *sql.TxOptions, ...) error
- func (f *SQLSessionFactory) OpenBatchSession() (*BatchSession, error)
- func (f *SQLSessionFactory) OpenConfiguredSession() (Session, error)
- func (f *SQLSessionFactory) OpenSession() (*SQLSession, error)
- func (f *SQLSessionFactory) SetTransactionFactory(factory TransactionFactory) error
- type SQLSessionOption
- func WithConfiguration(config Configuration) SQLSessionOption
- func WithIdentifierGenerator(generator IdentifierGenerator) SQLSessionOption
- func WithInterceptors(interceptors ...StatementInterceptor) SQLSessionOption
- func WithLocalCache(enabled bool) SQLSessionOption
- func WithMetaObjectHandler(handler MetaObjectHandler) SQLSessionOption
- func WithParameterHandler(handler ParameterHandler) SQLSessionOption
- func WithParameterHandlerMiddleware(middleware ...ParameterHandlerMiddleware) SQLSessionOption
- func WithResultSetHandler(handler ResultSetHandler) SQLSessionOption
- func WithResultSetHandlerMiddleware(middleware ...ResultSetHandlerMiddleware) SQLSessionOption
- func WithStatementExecutor(executor StatementExecutor) SQLSessionOption
- func WithStatementExecutorMiddleware(middleware ...StatementExecutorMiddleware) SQLSessionOption
- func WithStatementHandler(handler StatementHandler) SQLSessionOption
- func WithStatementHandlerMiddleware(middleware ...StatementHandlerMiddleware) SQLSessionOption
- func WithTypeHandler(name string, handler TypeHandler) SQLSessionOption
- func WithTypeHandlers(handlers map[string]TypeHandler) SQLSessionOption
- type SQLSource
- type SQLStatementOptionsApplier
- type SQLTransactionFactory
- type SelectKeyMeta
- type SelectKeyOrder
- type Service
- func (s *Service[T, ID]) BaseMapper() *BaseMapper[T, ID]
- func (s *Service[T, ID]) ChainQuery() *QueryChain[T, ID]
- func (s *Service[T, ID]) ChainUpdate() *UpdateChain[T, ID]
- func (s *Service[T, ID]) Count(ctx context.Context, wrapper *QueryWrapper[T]) (int64, error)
- func (s *Service[T, ID]) CountByEntity(ctx context.Context, entity *T) (int64, error)
- func (s *Service[T, ID]) GetByID(ctx context.Context, id ID) (*T, error)
- func (s *Service[T, ID]) GetMap(ctx context.Context, wrapper *QueryWrapper[T]) (map[string]any, error)
- func (s *Service[T, ID]) GetMapOrFirst(ctx context.Context, wrapper *QueryWrapper[T]) (map[string]any, error)
- func (s *Service[T, ID]) GetObj(ctx context.Context, wrapper *QueryWrapper[T]) (any, error)
- func (s *Service[T, ID]) GetObjOrFirst(ctx context.Context, wrapper *QueryWrapper[T]) (any, error)
- func (s *Service[T, ID]) GetOne(ctx context.Context, wrapper *QueryWrapper[T]) (*T, error)
- func (s *Service[T, ID]) GetOneOrFirst(ctx context.Context, wrapper *QueryWrapper[T]) (*T, error)
- func (s *Service[T, ID]) List(ctx context.Context, wrapper *QueryWrapper[T]) ([]T, error)
- func (s *Service[T, ID]) ListByEntity(ctx context.Context, entity *T) ([]T, error)
- func (s *Service[T, ID]) ListByIDs(ctx context.Context, ids []ID) ([]T, error)
- func (s *Service[T, ID]) ListByMap(ctx context.Context, columnMap map[string]any) ([]T, error)
- func (s *Service[T, ID]) ListMaps(ctx context.Context, wrapper *QueryWrapper[T]) ([]map[string]any, error)
- func (s *Service[T, ID]) ListObjs(ctx context.Context, wrapper *QueryWrapper[T]) ([]any, error)
- func (s *Service[T, ID]) Page(ctx context.Context, page PageRequest, wrapper *QueryWrapper[T]) (Page[T], error)
- func (s *Service[T, ID]) PageMaps(ctx context.Context, page PageRequest, wrapper *QueryWrapper[T]) (Page[map[string]any], error)
- func (s *Service[T, ID]) Remove(ctx context.Context, wrapper *QueryWrapper[T]) (int64, error)
- func (s *Service[T, ID]) RemoveBatchByIDs(ctx context.Context, ids []ID) (int64, error)
- func (s *Service[T, ID]) RemoveByEntity(ctx context.Context, entity *T) (int64, error)
- func (s *Service[T, ID]) RemoveByID(ctx context.Context, id ID) (bool, error)
- func (s *Service[T, ID]) RemoveByIDs(ctx context.Context, ids []ID) (int64, error)
- func (s *Service[T, ID]) RemoveByMap(ctx context.Context, columnMap map[string]any) (int64, error)
- func (s *Service[T, ID]) Save(ctx context.Context, entity *T) (bool, error)
- func (s *Service[T, ID]) SaveBatch(ctx context.Context, entities []T) (int64, error)
- func (s *Service[T, ID]) SaveBatchSize(ctx context.Context, entities []T, batchSize int) (int64, error)
- func (s *Service[T, ID]) SaveOrUpdate(ctx context.Context, entity *T) (bool, error)
- func (s *Service[T, ID]) SaveOrUpdateBatch(ctx context.Context, entities []T) (int64, error)
- func (s *Service[T, ID]) SaveOrUpdateBatchSize(ctx context.Context, entities []T, batchSize int) (int64, error)
- func (s *Service[T, ID]) Update(ctx context.Context, entity *T, wrapper *QueryWrapper[T]) (int64, error)
- func (s *Service[T, ID]) UpdateBatchByID(ctx context.Context, entities []T) (int64, error)
- func (s *Service[T, ID]) UpdateBatchByIDSize(ctx context.Context, entities []T, batchSize int) (int64, error)
- func (s *Service[T, ID]) UpdateByID(ctx context.Context, entity *T) (bool, error)
- func (s *Service[T, ID]) UpdateWithWrapper(ctx context.Context, wrapper *UpdateWrapper[T]) (int64, error)
- type Session
- type SessionOpenFunc
- type StatementCachePolicy
- type StatementCallSession
- type StatementCommand
- type StatementExecutor
- type StatementExecutorMiddleware
- type StatementExecutorMiddlewareFunc
- type StatementHandler
- type StatementHandlerMiddleware
- type StatementHandlerMiddlewareFunc
- type StatementInterceptor
- func NewBlockAttackInterceptor() StatementInterceptor
- func NewDataPermissionInterceptor(provider DataPermissionProvider) StatementInterceptor
- func NewDynamicTableInterceptor(tables map[string]string) StatementInterceptor
- func NewEntitySemanticInterceptor(registry *Registry, options ...EntitySemanticInterceptorOption) StatementInterceptor
- func NewIllegalSQLInterceptor(options ...IllegalSQLOption) StatementInterceptor
- func NewPaginationInterceptor() StatementInterceptor
- func NewReadOnlyInterceptor() StatementInterceptor
- func NewSQLGuardInterceptor(rules ...SQLGuardRule) StatementInterceptor
- func NewSQLObserverInterceptor(observe func(context.Context, SQLObservation) error) StatementInterceptor
- func NewTenantInterceptor(column string, value any) StatementInterceptor
- type StatementInterceptorFunc
- type StatementInvocation
- type StatementMeta
- type StatementNotFoundError
- type StatementOptions
- type StatementRuntime
- type StatementSession
- type StatementSource
- type StatementType
- type TooManyResultsError
- type Transaction
- type TransactionFactory
- type TransactionSource
- type TxSession
- func (s *TxSession) Call(ctx context.Context, statement string, args NamedArgs, resultSets ...any) (CallResult, error)
- func (s *TxSession) CallStatement(ctx context.Context, statement StatementMeta, args NamedArgs, ...) (CallResult, error)
- func (s *TxSession) Close() error
- func (s *TxSession) Commit() error
- func (s *TxSession) Dialect() Dialect
- func (s *TxSession) Exec(ctx context.Context, statement string, args NamedArgs) (Result, error)
- func (s *TxSession) ExecStatement(ctx context.Context, statement StatementMeta, args NamedArgs) (Result, error)
- func (s *TxSession) Query(ctx context.Context, statement string, args NamedArgs, dest any) error
- func (s *TxSession) QueryCursor(ctx context.Context, statement string, args NamedArgs) (*RowCursor, error)
- func (s *TxSession) QueryOne(ctx context.Context, statement string, args NamedArgs, dest any) error
- func (s *TxSession) QueryOneStatement(ctx context.Context, statement StatementMeta, args NamedArgs, dest any) error
- func (s *TxSession) QueryPage(ctx context.Context, statement string, args NamedArgs, page PageRequest, ...) (PageQueryResult, error)
- func (s *TxSession) QueryStatement(ctx context.Context, statement StatementMeta, args NamedArgs, dest any) error
- func (s *TxSession) Rollback() error
- type TypeAlias
- type TypeHandler
- func NewBoolTypeHandler() TypeHandler
- func NewBytesTypeHandler() TypeHandler
- func NewDecimalTypeHandler() TypeHandler
- func NewJSONTypeHandler() TypeHandler
- func NewStringTypeHandler() TypeHandler
- func NewTimeTypeHandler() TypeHandler
- func NewTypeHandler(toDB func(context.Context, any) (any, error), ...) TypeHandler
- type TypeHandlerAdapter
- type TypedField
- type TypedFieldRef
- type UpdateChain
- func (c *UpdateChain[T, ID]) Eq(field Field[T], value any) *UpdateChain[T, ID]
- func (c *UpdateChain[T, ID]) Set(field Field[T], value any) *UpdateChain[T, ID]
- func (c *UpdateChain[T, ID]) SetDecrBy(field Field[T], value any) *UpdateChain[T, ID]
- func (c *UpdateChain[T, ID]) SetIncrBy(field Field[T], value any) *UpdateChain[T, ID]
- func (c *UpdateChain[T, ID]) Update(ctx context.Context) (int64, error)
- func (c *UpdateChain[T, ID]) Where(apply func(*UpdateWrapper[T])) *UpdateChain[T, ID]
- func (c *UpdateChain[T, ID]) Wrapper() *UpdateWrapper[T]
- type UpdateWrapper
- func NewUpdateWrapper[T any]() *UpdateWrapper[T]
- func SetDecrByTypedValue[T any, V any](w *UpdateWrapper[T], field TypedField[T, V], value V) *UpdateWrapper[T]
- func SetDecrByTypedValueIf[T any, V any](condition bool, w *UpdateWrapper[T], field TypedField[T, V], value V) *UpdateWrapper[T]
- func SetIncrByTypedValue[T any, V any](w *UpdateWrapper[T], field TypedField[T, V], value V) *UpdateWrapper[T]
- func SetIncrByTypedValueIf[T any, V any](condition bool, w *UpdateWrapper[T], field TypedField[T, V], value V) *UpdateWrapper[T]
- func SetTypedValue[T any, V any](w *UpdateWrapper[T], field TypedField[T, V], value V) *UpdateWrapper[T]
- func SetTypedValueIf[T any, V any](condition bool, w *UpdateWrapper[T], field TypedField[T, V], value V) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) And(apply func(*UpdateWrapper[T])) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) Apply(sqlText string, args NamedArgs) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) Between(field Field[T], left any, right any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) BetweenTyped(field TypedFieldRef[T], left any, right any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) Empty() bool
- func (w *UpdateWrapper[T]) Eq(field Field[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) EqIf(condition bool, field Field[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) EqTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) Exists(sqlText string, args NamedArgs) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) Ge(field Field[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) GeTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) Gt(field Field[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) GtTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) In(field Field[T], values any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) InTyped(field TypedFieldRef[T], values any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) IsNotNull(field Field[T]) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) IsNotNullTyped(field TypedFieldRef[T]) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) IsNull(field Field[T]) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) IsNullTyped(field TypedFieldRef[T]) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) Last(sqlText string) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) Le(field Field[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) LeTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) Like(field Field[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) LikeLeft(field Field[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) LikeLeftTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) LikeRight(field Field[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) LikeRightTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) LikeTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) Lt(field Field[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) LtTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) Ne(field Field[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) NeTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) Nested(apply func(*UpdateWrapper[T])) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) NotBetween(field Field[T], left any, right any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) NotBetweenTyped(field TypedFieldRef[T], left any, right any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) NotExists(sqlText string, args NamedArgs) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) NotIn(field Field[T], values any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) NotInTyped(field TypedFieldRef[T], values any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) NotLike(field Field[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) NotLikeTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) Or(apply func(*UpdateWrapper[T])) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) Set(field Field[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) SetDecrBy(field Field[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) SetDecrByTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) SetEmpty() bool
- func (w *UpdateWrapper[T]) SetIf(condition bool, field Field[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) SetIncrBy(field Field[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) SetIncrByTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) SetSQL(sqlText string, args NamedArgs) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) SetTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) SetTypedIf(condition bool, field TypedFieldRef[T], value any) *UpdateWrapper[T]
- func (w *UpdateWrapper[T]) When(condition bool, apply func(*UpdateWrapper[T])) *UpdateWrapper[T]
Constants ¶
const ( // ModulePath 是 goark-orm 的稳定 Go module 路径。 ModulePath = "goark.dev/orm" // APIVersion 表示当前承诺兼容的公共 API 主版本。 APIVersion = "v1" )
const ( // InterceptorNameAll 表示忽略全部可命名拦截器。 InterceptorNameAll = "all" // InterceptorNameSQLObserver 表示 SQL 模板观察拦截器。 InterceptorNameSQLObserver = "sql-observer" // InterceptorNameBlockAttack 表示全表更新/删除保护拦截器。 InterceptorNameBlockAttack = "block-attack" // InterceptorNameDataPermission 表示数据权限条件拦截器。 InterceptorNameDataPermission = "data-permission" // InterceptorNameTenant 表示租户条件拦截器。 InterceptorNameTenant = "tenant" // InterceptorNameDynamicTable 表示动态表名拦截器。 InterceptorNameDynamicTable = "dynamic-table" // InterceptorNamePagination 表示分页拦截器。 InterceptorNamePagination = "pagination" // InterceptorNameEntitySemantic 表示实体语义拦截器。 InterceptorNameEntitySemantic = "entity-semantic" // InterceptorNameSQLGuard 表示通用 SQL 治理规则拦截器。 InterceptorNameSQLGuard = "sql-guard" // InterceptorNameIllegalSQL 表示非法 SQL 治理拦截器。 InterceptorNameIllegalSQL = "illegal-sql" // InterceptorNameReadOnly 表示只读治理拦截器。 InterceptorNameReadOnly = "read-only" )
const (
// DefaultBatchSize 是批量写入默认 flush 大小,对齐 MyBatis-Plus 常用默认值。
DefaultBatchSize = 1000
)
Variables ¶
var ( // ErrORM 是 goark-orm 所有结构化错误的根分类。 ErrORM = errors.New("goark-orm: orm error") // ErrConfiguration 表示运行期配置、选项或框架装配错误。 ErrConfiguration = errors.New("goark-orm: configuration error") // ErrRegistry 表示元数据注册和查找错误。 ErrRegistry = errors.New("goark-orm: registry error") // ErrStatementNotFound 表示 Mapper Statement 或 Provider 未注册。 ErrStatementNotFound = errors.New("goark-orm: statement not found") // ErrBinding 表示 SQL 参数解析、绑定或占位符编译错误。 ErrBinding = errors.New("goark-orm: binding error") // ErrMapping 表示结果集扫描、字段赋值或 TypeHandler 结果转换错误。 ErrMapping = errors.New("goark-orm: mapping error") // ErrExecutor 表示数据库执行、预编译语句或行集生命周期错误。 ErrExecutor = errors.New("goark-orm: executor error") // ErrTooManyResults 表示 QueryOne 返回了超过一行结果。 ErrTooManyResults = errors.New("goark-orm: too many results") )
var ErrTransactionCompleted = errors.New("goark-orm: transaction already completed")
ErrTransactionCompleted 表示事务已经提交或回滚。
Functions ¶
func BetweenTypedValues ¶
func BetweenTypedValues[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], left V, right V) W
BetweenTypedValues 用泛型函数保留字段值类型约束并添加 BETWEEN 条件。
func BetweenTypedValuesIf ¶
func BetweenTypedValuesIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], left V, right V) W
BetweenTypedValuesIf 在 condition 为 true 时添加类型安全的 BETWEEN 条件。
func EqTypedValue ¶
func EqTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
EqTypedValue 用泛型函数为 QueryWrapper 和 UpdateWrapper 保留字段值类型约束。
func EqTypedValueIf ¶
func EqTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
EqTypedValueIf 在 condition 为 true 时添加类型安全的等值条件。
func GeTypedValue ¶
func GeTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
GeTypedValue 用泛型函数保留字段值类型约束并添加大于等于条件。
func GeTypedValueIf ¶
func GeTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
GeTypedValueIf 在 condition 为 true 时添加类型安全的大于等于条件。
func GtTypedValue ¶
func GtTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
GtTypedValue 用泛型函数保留字段值类型约束并添加大于条件。
func GtTypedValueIf ¶
func GtTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
GtTypedValueIf 在 condition 为 true 时添加类型安全的大于条件。
func InTypedValues ¶
func InTypedValues[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], values ...V) W
InTypedValues 用泛型函数保留字段值类型约束并添加 IN 条件。
func InTypedValuesIf ¶
func InTypedValuesIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], values ...V) W
InTypedValuesIf 在 condition 为 true 时添加类型安全的 IN 条件。
func LeTypedValue ¶
func LeTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
LeTypedValue 用泛型函数保留字段值类型约束并添加小于等于条件。
func LeTypedValueIf ¶
func LeTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
LeTypedValueIf 在 condition 为 true 时添加类型安全的小于等于条件。
func LikeLeftTypedValue ¶
func LikeLeftTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
LikeLeftTypedValue 用泛型函数保留字段值类型约束并添加左侧模糊匹配条件。
func LikeLeftTypedValueIf ¶
func LikeLeftTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
LikeLeftTypedValueIf 在 condition 为 true 时添加类型安全的左侧模糊匹配条件。
func LikeRightTypedValue ¶
func LikeRightTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
LikeRightTypedValue 用泛型函数保留字段值类型约束并添加右侧模糊匹配条件。
func LikeRightTypedValueIf ¶
func LikeRightTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
LikeRightTypedValueIf 在 condition 为 true 时添加类型安全的右侧模糊匹配条件。
func LikeTypedValue ¶
func LikeTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
LikeTypedValue 用泛型函数保留字段值类型约束并添加 LIKE 条件。
func LikeTypedValueIf ¶
func LikeTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
LikeTypedValueIf 在 condition 为 true 时添加类型安全的 LIKE 条件。
func LtTypedValue ¶
func LtTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
LtTypedValue 用泛型函数保留字段值类型约束并添加小于条件。
func LtTypedValueIf ¶
func LtTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
LtTypedValueIf 在 condition 为 true 时添加类型安全的小于条件。
func NeTypedValue ¶
func NeTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
NeTypedValue 用泛型函数保留字段值类型约束并添加不等条件。
func NeTypedValueIf ¶
func NeTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
NeTypedValueIf 在 condition 为 true 时添加类型安全的不等条件。
func NotBetweenTypedValues ¶
func NotBetweenTypedValues[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], left V, right V) W
NotBetweenTypedValues 用泛型函数保留字段值类型约束并添加 NOT BETWEEN 条件。
func NotBetweenTypedValuesIf ¶
func NotBetweenTypedValuesIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], left V, right V) W
NotBetweenTypedValuesIf 在 condition 为 true 时添加类型安全的 NOT BETWEEN 条件。
func NotInTypedValues ¶
func NotInTypedValues[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], values ...V) W
NotInTypedValues 用泛型函数保留字段值类型约束并添加 NOT IN 条件。
func NotInTypedValuesIf ¶
func NotInTypedValuesIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], values ...V) W
NotInTypedValuesIf 在 condition 为 true 时添加类型安全的 NOT IN 条件。
func NotLikeTypedValue ¶
func NotLikeTypedValue[T any, V any, W typedConditionTarget[T, W]](w W, field TypedField[T, V], value V) W
NotLikeTypedValue 用泛型函数保留字段值类型约束并添加 NOT LIKE 条件。
func NotLikeTypedValueIf ¶
func NotLikeTypedValueIf[T any, V any, W typedConditionTarget[T, W]](condition bool, w W, field TypedField[T, V], value V) W
NotLikeTypedValueIf 在 condition 为 true 时添加类型安全的 NOT LIKE 条件。
func QueryEach ¶
func QueryEach[T any](ctx context.Context, session Session, statement string, args NamedArgs, handler ResultHandler[T]) error
QueryEach 逐条扫描并回调处理查询结果。
func RegisterInjectedStatements ¶
func RegisterInjectedStatements(registry *Registry, namespace string, entity EntityMeta, injector SQLInjector, options ...InjectOption) error
RegisterInjectedStatements 将注入器生成的通用 Statement 注册到 Registry。
func StatementInterceptorIgnored ¶
func StatementInterceptorIgnored(statement StatementMeta, name string) bool
StatementInterceptorIgnored 判断语句是否声明跳过指定拦截器。
func WithDataSource ¶
func WithDataSource(ctx context.Context, key DataSourceKey) context.Context
WithDataSource 在 context 中声明本次 ORM 调用使用的数据源。
func WithPageRequest ¶
func WithPageRequest(ctx context.Context, page PageRequest) context.Context
WithPageRequest 将分页请求挂到 context,供分页拦截器读取。
Types ¶
type BaseMapper ¶
BaseMapper 提供 MyBatis-Plus 风格的实体通用 CRUD。
func NewBaseMapper ¶
func NewBaseMapper[T any, ID any](session StatementSession, entity EntityMeta, options ...BaseMapperOption) (*BaseMapper[T, ID], error)
NewBaseMapper 创建实体通用 Mapper。
func (*BaseMapper[T, ID]) Count ¶
func (m *BaseMapper[T, ID]) Count(ctx context.Context, wrapper *QueryWrapper[T]) (int64, error)
Count 按条件统计记录数。
func (*BaseMapper[T, ID]) Delete ¶
func (m *BaseMapper[T, ID]) Delete(ctx context.Context, wrapper *QueryWrapper[T]) (int64, error)
Delete 按条件删除记录,空条件会被拒绝。
func (*BaseMapper[T, ID]) DeleteBatchIDs ¶
func (m *BaseMapper[T, ID]) DeleteBatchIDs(ctx context.Context, ids []ID) (int64, error)
DeleteBatchIDs 按主键集合删除记录。
func (*BaseMapper[T, ID]) DeleteByEntity ¶
func (m *BaseMapper[T, ID]) DeleteByEntity(ctx context.Context, entity *T) (int64, error)
DeleteByEntity 按实体非零字段删除记录,空条件仍由 Delete 保持 fail-fast。
func (*BaseMapper[T, ID]) DeleteByID ¶
func (m *BaseMapper[T, ID]) DeleteByID(ctx context.Context, id ID) (int64, error)
DeleteByID 按主键删除记录。
func (*BaseMapper[T, ID]) DeleteByMap ¶
func (m *BaseMapper[T, ID]) DeleteByMap(ctx context.Context, columnMap map[string]any) (int64, error)
DeleteByMap 按列名 map 等值删除记录,空 map 会被拒绝。
func (*BaseMapper[T, ID]) EntityQueryWrapper ¶
func (m *BaseMapper[T, ID]) EntityQueryWrapper(entity *T) (*QueryWrapper[T], error)
EntityQueryWrapper 按实体字段值构造查询条件,字段 whereStrategy 决定是否参与 WHERE。
func (*BaseMapper[T, ID]) Insert ¶
func (m *BaseMapper[T, ID]) Insert(ctx context.Context, entity *T) (Result, error)
Insert 插入实体,返回写入结果。
func (*BaseMapper[T, ID]) InsertBatch ¶
func (m *BaseMapper[T, ID]) InsertBatch(ctx context.Context, entities []T) (int64, error)
InsertBatch 按默认批量大小插入实体。
func (*BaseMapper[T, ID]) InsertBatchSize ¶
func (m *BaseMapper[T, ID]) InsertBatchSize(ctx context.Context, entities []T, batchSize int) (int64, error)
InsertBatchSize 按指定批量大小插入实体。底层 Session 支持批处理时会分批 flush。
func (*BaseMapper[T, ID]) SaveOrUpdate ¶
func (m *BaseMapper[T, ID]) SaveOrUpdate(ctx context.Context, entity *T) (Result, error)
SaveOrUpdate 根据主键零值判断插入或按主键更新。
func (*BaseMapper[T, ID]) SaveOrUpdateBatch ¶
func (m *BaseMapper[T, ID]) SaveOrUpdateBatch(ctx context.Context, entities []T) (int64, error)
SaveOrUpdateBatch 按默认批量大小保存或更新实体。
func (*BaseMapper[T, ID]) SaveOrUpdateBatchSize ¶
func (m *BaseMapper[T, ID]) SaveOrUpdateBatchSize(ctx context.Context, entities []T, batchSize int) (int64, error)
SaveOrUpdateBatchSize 保存或更新实体。该方法保留逐条语义,确保更新 0 行时再插入。
func (*BaseMapper[T, ID]) SelectBatchIDs ¶
func (m *BaseMapper[T, ID]) SelectBatchIDs(ctx context.Context, ids []ID) ([]T, error)
SelectBatchIDs 按主键集合查询记录。
func (*BaseMapper[T, ID]) SelectByID ¶
func (m *BaseMapper[T, ID]) SelectByID(ctx context.Context, id ID) (*T, error)
SelectByID 按主键查询单条记录。
func (*BaseMapper[T, ID]) SelectByMap ¶
SelectByMap 按列名 map 等值查询记录。
func (*BaseMapper[T, ID]) SelectCount ¶
func (m *BaseMapper[T, ID]) SelectCount(ctx context.Context, wrapper *QueryWrapper[T]) (int64, error)
SelectCount 是 Count 的 MyBatis-Plus 命名别名。
func (*BaseMapper[T, ID]) SelectCountByEntity ¶
func (m *BaseMapper[T, ID]) SelectCountByEntity(ctx context.Context, entity *T) (int64, error)
SelectCountByEntity 按实体非零字段统计记录数。
func (*BaseMapper[T, ID]) SelectList ¶
func (m *BaseMapper[T, ID]) SelectList(ctx context.Context, wrapper *QueryWrapper[T]) ([]T, error)
SelectList 按条件查询记录列表。
func (*BaseMapper[T, ID]) SelectListByEntity ¶
func (m *BaseMapper[T, ID]) SelectListByEntity(ctx context.Context, entity *T) ([]T, error)
SelectListByEntity 按实体非零字段查询列表。
func (*BaseMapper[T, ID]) SelectMaps ¶
func (m *BaseMapper[T, ID]) SelectMaps(ctx context.Context, wrapper *QueryWrapper[T]) ([]map[string]any, error)
SelectMaps 按条件查询 map 结果列表。
func (*BaseMapper[T, ID]) SelectMapsPage ¶
func (m *BaseMapper[T, ID]) SelectMapsPage(ctx context.Context, page PageRequest, wrapper *QueryWrapper[T]) (Page[map[string]any], error)
SelectMapsPage 按条件执行 map 结果分页查询。
func (*BaseMapper[T, ID]) SelectObjs ¶
func (m *BaseMapper[T, ID]) SelectObjs(ctx context.Context, wrapper *QueryWrapper[T]) ([]any, error)
SelectObjs 按条件查询首列结果列表,默认选择实体主键列。
func (*BaseMapper[T, ID]) SelectOne ¶
func (m *BaseMapper[T, ID]) SelectOne(ctx context.Context, wrapper *QueryWrapper[T]) (*T, error)
SelectOne 按条件查询单条记录。
func (*BaseMapper[T, ID]) SelectPage ¶
func (m *BaseMapper[T, ID]) SelectPage(ctx context.Context, page PageRequest, wrapper *QueryWrapper[T]) (Page[T], error)
SelectPage 按条件执行分页查询。
func (*BaseMapper[T, ID]) Update ¶
func (m *BaseMapper[T, ID]) Update(ctx context.Context, entity *T, wrapper *QueryWrapper[T]) (int64, error)
Update 按条件更新实体非主键字段,空条件会被拒绝。
func (*BaseMapper[T, ID]) UpdateBatchByID ¶
func (m *BaseMapper[T, ID]) UpdateBatchByID(ctx context.Context, entities []T) (int64, error)
UpdateBatchByID 按默认批量大小根据主键更新实体。
func (*BaseMapper[T, ID]) UpdateBatchByIDSize ¶
func (m *BaseMapper[T, ID]) UpdateBatchByIDSize(ctx context.Context, entities []T, batchSize int) (int64, error)
UpdateBatchByIDSize 按指定批量大小根据主键更新实体。底层 Session 支持批处理时会分批 flush。
func (*BaseMapper[T, ID]) UpdateByID ¶
func (m *BaseMapper[T, ID]) UpdateByID(ctx context.Context, entity *T) (int64, error)
UpdateByID 按主键更新实体非主键字段。
func (*BaseMapper[T, ID]) UpdateWithWrapper ¶
func (m *BaseMapper[T, ID]) UpdateWithWrapper(ctx context.Context, wrapper *UpdateWrapper[T]) (int64, error)
UpdateWithWrapper 按 UpdateWrapper 的 SET 和 WHERE 执行局部更新。
type BaseMapperOption ¶
type BaseMapperOption func(*baseMapperOptions)
BaseMapperOption 配置 BaseMapper。
func WithBaseMapperClock ¶
func WithBaseMapperClock(clock func() time.Time) BaseMapperOption
WithBaseMapperClock 指定自动时间字段使用的时钟。
func WithBaseMapperDialect ¶
func WithBaseMapperDialect(dialect Dialect) BaseMapperOption
WithBaseMapperDialect 指定 BaseMapper 生成 SQL 使用的数据库方言。
func WithBaseMapperGlobalConfig ¶
func WithBaseMapperGlobalConfig(global GlobalConfig) BaseMapperOption
WithBaseMapperGlobalConfig 指定 BaseMapper 使用的全局配置。
func WithBaseMapperIdentifierGenerator ¶
func WithBaseMapperIdentifierGenerator(generator IdentifierGenerator) BaseMapperOption
WithBaseMapperIdentifierGenerator 指定 BaseMapper 插入前主键生成器。
func WithBaseMapperMetaObjectHandler ¶
func WithBaseMapperMetaObjectHandler(handler MetaObjectHandler) BaseMapperOption
WithBaseMapperMetaObjectHandler 指定 BaseMapper 自动填充处理器。
type BatchError ¶
type BatchError struct {
Index int
Statement string
StatementMeta StatementMeta
Err error
}
BatchError 描述批处理在指定下标语句上的执行失败。
func (*BatchError) Error ¶
func (e *BatchError) Error() string
type BatchResult ¶
type BatchResult struct {
Statement string
StatementMeta StatementMeta
Args NamedArgs
Result Result
}
BatchResult 表示批处理中单条语句的执行结果。
type BatchSession ¶
type BatchSession struct {
// contains filtered or unexported fields
}
BatchSession 提供 MyBatis BatchExecutor 风格的批处理 Session。
func NewBatchSession ¶
func NewBatchSession(session Session) (*BatchSession, error)
NewBatchSession 创建批处理 Session。
func (*BatchSession) Call ¶
func (s *BatchSession) Call(ctx context.Context, statement string, args NamedArgs, resultSets ...any) (CallResult, error)
Call 会先刷新批处理队列,再转发存储过程调用。
func (*BatchSession) CallStatement ¶
func (s *BatchSession) CallStatement(ctx context.Context, statement StatementMeta, args NamedArgs, resultSets ...any) (CallResult, error)
CallStatement 会先刷新批处理队列,再转发 StatementMeta 调用。
func (*BatchSession) Commit ¶
func (s *BatchSession) Commit() error
Commit 使用后台上下文刷新批处理并提交底层 Session。
func (*BatchSession) CommitContext ¶
func (s *BatchSession) CommitContext(ctx context.Context) error
CommitContext 刷新批处理并提交底层 Session。
func (*BatchSession) Dialect ¶
func (s *BatchSession) Dialect() Dialect
Dialect 返回底层 Session 的数据库方言。
func (*BatchSession) ExecStatement ¶
func (s *BatchSession) ExecStatement(ctx context.Context, statement StatementMeta, args NamedArgs) (Result, error)
ExecStatement 将 StatementMeta 加入批处理队列。
func (*BatchSession) Flush ¶
func (s *BatchSession) Flush(ctx context.Context) ([]BatchResult, error)
Flush 按入队顺序执行所有待处理写语句。
func (*BatchSession) QueryCursor ¶
func (*BatchSession) QueryOne ¶
func (s *BatchSession) QueryOne(ctx context.Context, statement string, args NamedArgs, dest any) error
QueryOne 会先刷新待执行写语句,再执行单行查询。
func (*BatchSession) QueryOneStatement ¶
func (s *BatchSession) QueryOneStatement(ctx context.Context, statement StatementMeta, args NamedArgs, dest any) error
QueryOneStatement 会先刷新待执行写语句,再执行单行查询语句元数据。
func (*BatchSession) QueryPage ¶
func (s *BatchSession) QueryPage(ctx context.Context, statement string, args NamedArgs, page PageRequest, dest any) (PageQueryResult, error)
QueryPage 会先刷新待执行写语句,再执行分页查询。
func (*BatchSession) QueryStatement ¶
func (s *BatchSession) QueryStatement(ctx context.Context, statement StatementMeta, args NamedArgs, dest any) error
QueryStatement 会先刷新待执行写语句,再执行查询语句元数据。
func (*BatchSession) Rollback ¶
func (s *BatchSession) Rollback() error
Rollback 丢弃待执行语句并回滚底层 Session。
type BindingError ¶
type BindingError struct {
Statement string
Operation string
Parameter string
Column string
Field string
Message string
Err error
}
BindingError 携带参数绑定和 SQL 编译阶段的定位信息。
func (*BindingError) Error ¶
func (e *BindingError) Error() string
func (*BindingError) Is ¶
func (e *BindingError) Is(target error) bool
func (*BindingError) Unwrap ¶
func (e *BindingError) Unwrap() error
type BlockingCache ¶
type BlockingCache struct {
// contains filtered or unexported fields
}
BlockingCache 使用每个 key 一个加载权来合并并发缓存 miss。
func NewBlockingCache ¶
func NewBlockingCache(delegate Cache) *BlockingCache
NewBlockingCache 创建缓存 miss 合并装饰器。
func (*BlockingCache) Clear ¶
func (c *BlockingCache) Clear(ctx context.Context) error
Clear 清空缓存并释放全部等待者。
func (*BlockingCache) ReleaseMiss ¶
func (c *BlockingCache) ReleaseMiss(ctx context.Context, key string) error
ReleaseMiss 释放一次未写入缓存的 miss 加载权。
type Cache ¶
type Cache interface {
Get(ctx context.Context, key string) (any, bool, error)
Put(ctx context.Context, key string, value any) error
Remove(ctx context.Context, key string) error
Clear(ctx context.Context) error
}
Cache 定义 Mapper namespace 级二级缓存 SPI。
type CacheMeta ¶
type CacheMeta struct {
Enabled bool
RefNamespace string
Eviction string
Size int
FlushIntervalMillis int64
ReadOnly bool
Blocking bool
}
CacheMeta 描述 Mapper namespace 级二级缓存配置。
type CacheMissReleaser ¶
CacheMissReleaser 描述可显式释放缓存 miss 加载权的可选能力。
type CacheStats ¶
type CacheStats struct {
ID string
MaxEntries int
Len int
Hits uint64
Misses uint64
Puts uint64
Removes uint64
Clears uint64
Evictions uint64
Expirations uint64
}
CacheStats 描述缓存运行期统计快照。
type CacheStatsProvider ¶
type CacheStatsProvider interface {
Stats() CacheStats
}
CacheStatsProvider 描述可导出缓存统计快照的可选能力。
type CallSession ¶
type CallSession interface {
Call(ctx context.Context, statement string, args NamedArgs, resultSets ...any) (CallResult, error)
}
CallSession 描述支持按 Statement 名称调用存储过程的 Session。
type ColumnMeta ¶
type ColumnMeta struct {
FieldName string
FieldType string
ColumnName string
KeyColumn string
PrimaryKey bool
AutoIncrement bool
IDType IDType
Nullable *bool
Size *int
NumericScale *int
DBType string
DefaultValue string
TypeHandler string
Condition string
SelectDisabled bool
InsertStrategy FieldStrategy
UpdateStrategy FieldStrategy
WhereStrategy FieldStrategy
Version bool
SoftDelete bool
CreatedAt bool
UpdatedAt bool
Fill FieldFill
}
ColumnMeta 描述实体字段与数据库列的静态映射。
type CompiledSQL ¶
CompiledSQL 表示已经完成占位符改写和参数排序的 SQL。
func CompileSQL ¶
func CompileSQL(query string, args NamedArgs, dialect Dialect) (CompiledSQL, error)
CompileSQL 将 #{name} 改写为数据库方言占位符,并按出现顺序绑定参数。
func CompileSQLContext ¶
func CompileSQLContext(ctx context.Context, query string, args NamedArgs, dialect Dialect) (CompiledSQL, error)
CompileSQLContext 将 #{name} 改写为数据库方言占位符,并使用调用方上下文完成参数转换。
type Configuration ¶
type Configuration struct {
Dialect Dialect
DatabaseID string
GlobalConfig GlobalConfig
LocalCacheEnabled *bool
LocalCacheScope LocalCacheScope
CacheEnabled *bool
MapUnderscoreToCamelCase bool
UseGeneratedKeys bool
LazyLoadingEnabled bool
DefaultExecutorType ExecutorType
DefaultStatementTimeout time.Duration
DefaultFetchSize int
MetaObjectHandler MetaObjectHandler
}
Configuration 描述 MyBatis 风格的 ORM 运行期配置。
func DefaultConfiguration ¶
func DefaultConfiguration() Configuration
DefaultConfiguration 返回独立 ORM 的默认运行期配置。
func (Configuration) WithGlobalConfig ¶
func (c Configuration) WithGlobalConfig(global GlobalConfig) Configuration
WithGlobalConfig 返回设置 MyBatis-Plus 风格全局配置后的配置副本。
func (Configuration) WithLocalCache ¶
func (c Configuration) WithLocalCache(enabled bool) Configuration
WithLocalCache 返回显式设置一级缓存开关后的配置副本。
func (Configuration) WithMapUnderscoreToCamelCase ¶
func (c Configuration) WithMapUnderscoreToCamelCase(enabled bool) Configuration
WithMapUnderscoreToCamelCase 返回设置下划线转驼峰自动映射后的配置副本。
func (Configuration) WithSecondLevelCache ¶
func (c Configuration) WithSecondLevelCache(enabled bool) Configuration
WithSecondLevelCache 返回显式设置二级缓存总开关后的配置副本。
type ConfigurationError ¶
ConfigurationError 携带配置项名称和底层原因。
func (*ConfigurationError) Error ¶
func (e *ConfigurationError) Error() string
func (*ConfigurationError) Is ¶
func (e *ConfigurationError) Is(target error) bool
func (*ConfigurationError) Unwrap ¶
func (e *ConfigurationError) Unwrap() error
type Cursor ¶
type Cursor[T any] struct { // contains filtered or unexported fields }
Cursor 是类型安全的查询游标。
type CursorQuerySession ¶
type CursorQuerySession interface {
QueryCursor(ctx context.Context, statement string, args NamedArgs) (*RowCursor, error)
}
CursorQuerySession 描述支持游标查询的 Session。
type DataPermissionProvider ¶
type DataPermissionProvider func(ctx context.Context, statement StatementMeta) (SQLCondition, error)
DataPermissionProvider 根据当前语句生成数据权限条件。
type DataSourceKey ¶
type DataSourceKey string
DataSourceKey 表示一个逻辑数据源名称。
const ( // DefaultDataSourceKey 表示默认逻辑数据源。 DefaultDataSourceKey DataSourceKey = "default" )
func DataSourceFromContext ¶
func DataSourceFromContext(ctx context.Context) (DataSourceKey, bool)
DataSourceFromContext 从 context 读取数据源声明。
type DataSourceResolver ¶
type DataSourceResolver func(ctx context.Context, operation RoutingOperation) (DataSourceKey, error)
DataSourceResolver 根据 ORM 操作选择逻辑数据源。
func ReadWriteDataSourceResolver ¶
func ReadWriteDataSourceResolver(read DataSourceKey, write DataSourceKey) DataSourceResolver
ReadWriteDataSourceResolver 按读写操作拆分数据源。
func StatementDataSourceResolver ¶
func StatementDataSourceResolver(routes map[string]DataSourceKey, fallback DataSourceResolver) DataSourceResolver
StatementDataSourceResolver 按 Statement 全名优先路由,未命中时回退到 fallback。
func StaticDataSourceResolver ¶
func StaticDataSourceResolver(key DataSourceKey) DataSourceResolver
StaticDataSourceResolver 始终返回固定数据源。
type Db ¶
type Db struct {
// contains filtered or unexported fields
}
Db 是 MyBatis-Plus Db Kit 的 Go 化门面,不持有全局会话。
type DbConfig ¶
type DbConfig struct {
IDType IDType
TablePrefix string
Schema string
LogicDeleteField string
LogicDeleteValue any
LogicNotDeleteValue any
InsertStrategy FieldStrategy
UpdateStrategy FieldStrategy
WhereStrategy FieldStrategy
}
DbConfig 描述数据库命名、主键和逻辑删除默认策略。
type DefaultIdentifierGenerator ¶
type DefaultIdentifierGenerator struct {
// contains filtered or unexported fields
}
DefaultIdentifierGenerator 是无外部依赖的默认主键生成器。
func NewDefaultIdentifierGenerator ¶
func NewDefaultIdentifierGenerator() *DefaultIdentifierGenerator
NewDefaultIdentifierGenerator 创建默认主键生成器。
func (*DefaultIdentifierGenerator) NextID ¶
func (g *DefaultIdentifierGenerator) NextID(ctx context.Context, entity EntityMeta, column ColumnMeta) (any, error)
NextID 生成 Snowflake 风格 64 位整数主键。
func (*DefaultIdentifierGenerator) NextUUID ¶
func (g *DefaultIdentifierGenerator) NextUUID(ctx context.Context, entity EntityMeta, column ColumnMeta) (string, error)
NextUUID 生成 RFC 4122 Version 4 UUID。
type Dialect ¶
type Dialect interface {
Name() string
Placeholder(index int) string
QuoteIdent(identifier string) string
}
Dialect 封装数据库方言差异。
type DialectCapabilities ¶
type DialectCapabilities struct {
DBType DbType
Placeholder DialectPlaceholderStyle
IdentifierQuote DialectIdentifierQuoteStyle
LimitOffset bool
LimitOffsetRequiresOrderBy bool
GeneratedKey DialectGeneratedKeyStyle
Upsert DialectUpsertStyle
RowLock DialectRowLockStyle
JSON DialectJSONStyle
BatchInsert bool
Savepoint bool
SkipLocked bool
NoWait bool
}
DialectCapabilities 描述数据库方言的可用能力,不绑定具体 driver。
func DialectCapabilitiesOf ¶
func DialectCapabilitiesOf(dialect Dialect) DialectCapabilities
DialectCapabilitiesOf 返回方言能力;未知自定义方言只保留名称。
func NewDialectCapabilities ¶
func NewDialectCapabilities(dbType DbType) (DialectCapabilities, error)
NewDialectCapabilities 根据数据库类型返回内置方言能力。
func (DialectCapabilities) SupportsGeneratedKey ¶
func (c DialectCapabilities) SupportsGeneratedKey() bool
SupportsGeneratedKey 返回方言是否声明了主键回读能力。
func (DialectCapabilities) SupportsJSON ¶
func (c DialectCapabilities) SupportsJSON() bool
SupportsJSON 返回方言是否声明了 JSON 能力。
func (DialectCapabilities) SupportsRowLock ¶
func (c DialectCapabilities) SupportsRowLock() bool
SupportsRowLock 返回方言是否声明了行锁能力。
func (DialectCapabilities) SupportsUpsert ¶
func (c DialectCapabilities) SupportsUpsert() bool
SupportsUpsert 返回方言是否声明了原生 UPSERT 能力。
type DialectCapabilitiesProvider ¶
type DialectCapabilitiesProvider interface {
DialectCapabilities() DialectCapabilities
}
DialectCapabilitiesProvider 由支持能力查询的方言可选实现。
type DialectGeneratedKeyStyle ¶
type DialectGeneratedKeyStyle string
DialectGeneratedKeyStyle 描述主键回读能力。
const ( // DialectGeneratedKeyNone 表示方言没有声明统一主键回读能力。 DialectGeneratedKeyNone DialectGeneratedKeyStyle = "" // DialectGeneratedKeyLastInsertID 表示依赖 database/sql Result.LastInsertId。 DialectGeneratedKeyLastInsertID DialectGeneratedKeyStyle = "last_insert_id" // DialectGeneratedKeyReturning 表示支持 INSERT ... RETURNING。 DialectGeneratedKeyReturning DialectGeneratedKeyStyle = "returning" // DialectGeneratedKeyOutput 表示 SQL Server OUTPUT inserted.<column>。 DialectGeneratedKeyOutput DialectGeneratedKeyStyle = "output" // DialectGeneratedKeyReturningInto 表示 Oracle RETURNING ... INTO。 DialectGeneratedKeyReturningInto DialectGeneratedKeyStyle = "returning_into" )
type DialectIdentifierQuoteStyle ¶
type DialectIdentifierQuoteStyle string
DialectIdentifierQuoteStyle 描述标识符引用风格。
const ( // DialectIdentifierQuoteBacktick 表示反引号标识符。 DialectIdentifierQuoteBacktick DialectIdentifierQuoteStyle = "backtick" // DialectIdentifierQuoteDouble 表示双引号标识符。 DialectIdentifierQuoteDouble DialectIdentifierQuoteStyle = "double_quote" // DialectIdentifierQuoteBracket 表示 SQL Server 方括号标识符。 DialectIdentifierQuoteBracket DialectIdentifierQuoteStyle = "bracket" )
type DialectJSONStyle ¶
type DialectJSONStyle string
DialectJSONStyle 描述 JSON 列支持级别。
const ( // DialectJSONNone 表示方言没有声明 JSON 能力。 DialectJSONNone DialectJSONStyle = "" // DialectJSONNative 表示数据库内建 JSON 类型或函数。 DialectJSONNative DialectJSONStyle = "native" // DialectJSONExtension 表示 JSON 能力依赖数据库扩展或构建选项。 DialectJSONExtension DialectJSONStyle = "extension" )
type DialectPlaceholderStyle ¶
type DialectPlaceholderStyle string
DialectPlaceholderStyle 描述方言占位符风格。
const ( // DialectPlaceholderQuestion 表示 `?` 占位符。 DialectPlaceholderQuestion DialectPlaceholderStyle = "question" // DialectPlaceholderDollarNumber 表示 PostgreSQL `$1` 风格占位符。 DialectPlaceholderDollarNumber DialectPlaceholderStyle = "dollar_number" // DialectPlaceholderAtPNumber 表示 SQL Server `@p1` 风格占位符。 DialectPlaceholderAtPNumber DialectPlaceholderStyle = "at_p_number" // DialectPlaceholderColonNumber 表示 Oracle `:1` 风格占位符。 DialectPlaceholderColonNumber DialectPlaceholderStyle = "colon_number" )
type DialectRowLockStyle ¶
type DialectRowLockStyle string
DialectRowLockStyle 描述行锁语义。
const ( // DialectRowLockNone 表示方言没有声明统一行锁语义。 DialectRowLockNone DialectRowLockStyle = "" // DialectRowLockForUpdate 表示 SELECT ... FOR UPDATE。 DialectRowLockForUpdate DialectRowLockStyle = "for_update" // DialectRowLockHints 表示 SQL Server WITH (...) 锁提示。 DialectRowLockHints DialectRowLockStyle = "lock_hints" )
type DialectUpsertStyle ¶
type DialectUpsertStyle string
DialectUpsertStyle 描述方言原生 UPSERT 语义。
const ( // DialectUpsertNone 表示方言没有声明统一 UPSERT 语义。 DialectUpsertNone DialectUpsertStyle = "" // DialectUpsertOnConflict 表示 ON CONFLICT 语义。 DialectUpsertOnConflict DialectUpsertStyle = "on_conflict" // DialectUpsertOnDuplicateKey 表示 ON DUPLICATE KEY UPDATE 语义。 DialectUpsertOnDuplicateKey DialectUpsertStyle = "on_duplicate_key" // DialectUpsertMerge 表示 MERGE 语义。 DialectUpsertMerge DialectUpsertStyle = "merge" )
type DynamicSQLNode ¶
type DynamicSQLNode struct {
Kind DynamicSQLNodeKind
Text string
Test string
Prefix string
Suffix string
PrefixOverrides string
SuffixOverrides string
Collection string
Item string
Index string
Name string
Value string
Open string
Close string
Separator string
RefID string
Children []DynamicSQLNode
}
DynamicSQLNode 描述 XML 动态 SQL 的静态节点树。
type DynamicSQLNodeKind ¶
type DynamicSQLNodeKind string
DynamicSQLNodeKind 表示动态 SQL 节点类型。
const ( // DynamicSQLNodeText 表示普通 SQL 文本。 DynamicSQLNodeText DynamicSQLNodeKind = "text" // DynamicSQLNodeIf 表示条件 SQL 节点。 DynamicSQLNodeIf DynamicSQLNodeKind = "if" // DynamicSQLNodeWhere 表示 WHERE 包装节点。 DynamicSQLNodeWhere DynamicSQLNodeKind = "where" // DynamicSQLNodeSet 表示 SET 包装节点。 DynamicSQLNodeSet DynamicSQLNodeKind = "set" // DynamicSQLNodeTrim 表示通用前后缀修剪节点。 DynamicSQLNodeTrim DynamicSQLNodeKind = "trim" // DynamicSQLNodeForeach 表示集合展开节点。 DynamicSQLNodeForeach DynamicSQLNodeKind = "foreach" // DynamicSQLNodeChoose 表示分支选择节点。 DynamicSQLNodeChoose DynamicSQLNodeKind = "choose" // DynamicSQLNodeWhen 表示 choose 的条件分支。 DynamicSQLNodeWhen DynamicSQLNodeKind = "when" // DynamicSQLNodeOtherwise 表示 choose 的默认分支。 DynamicSQLNodeOtherwise DynamicSQLNodeKind = "otherwise" // DynamicSQLNodeInclude 表示 XML sql 片段引用,生成期应展开。 DynamicSQLNodeInclude DynamicSQLNodeKind = "include" // DynamicSQLNodeBind 表示 XML bind 变量绑定节点。 DynamicSQLNodeBind DynamicSQLNodeKind = "bind" )
type EntityMeta ¶
type EntityMeta struct {
TypeName string
Table string
Columns []ColumnMeta
}
EntityMeta 描述一个实体类型的 ORM 映射。
type EntitySemanticInterceptorOption ¶
type EntitySemanticInterceptorOption func(*entitySemanticInterceptor)
EntitySemanticInterceptorOption 配置实体语义拦截器。
func WithEntitySemanticClock ¶
func WithEntitySemanticClock(clock func() time.Time) EntitySemanticInterceptorOption
WithEntitySemanticClock 配置自动填充时间使用的时钟。
type EnumValuer ¶
type EnumValuer interface {
EnumValue() any
}
EnumValuer 对齐 MyBatis-Plus IEnum/@EnumValue 的 Go 化枚举值接口。
type EnumValuerContext ¶
EnumValuerContext 支持需要上下文的枚举值转换。
type ExecutorError ¶
ExecutorError 携带数据库执行阶段的操作、SQL 和底层原因。
func (*ExecutorError) Error ¶
func (e *ExecutorError) Error() string
func (*ExecutorError) Is ¶
func (e *ExecutorError) Is(target error) bool
func (*ExecutorError) Unwrap ¶
func (e *ExecutorError) Unwrap() error
type ExecutorType ¶
type ExecutorType string
ExecutorType 描述默认执行器类型。
const ( // ExecutorTypeSimple 表示普通即时执行器。 ExecutorTypeSimple ExecutorType = "SIMPLE" // ExecutorTypeReuse 表示可复用预编译语句执行器。 ExecutorTypeReuse ExecutorType = "REUSE" // ExecutorTypeBatch 表示批量执行器。 ExecutorTypeBatch ExecutorType = "BATCH" )
func ParseExecutorType ¶
func ParseExecutorType(value string) (ExecutorType, error)
ParseExecutorType 解析 MyBatis defaultExecutorType 配置值。
type FieldFill ¶
type FieldFill string
FieldFill 描述 MyBatis-Plus 风格字段自动填充时机。
const ( // FieldFillDefault 表示字段不参与严格自动填充。 FieldFillDefault FieldFill = "" // FieldFillInsert 表示字段仅在 INSERT 时参与自动填充。 FieldFillInsert FieldFill = "INSERT" // FieldFillUpdate 表示字段仅在 UPDATE 时参与自动填充。 FieldFillUpdate FieldFill = "UPDATE" // FieldFillInsertUpdate 表示字段在 INSERT 和 UPDATE 时都参与自动填充。 FieldFillInsertUpdate FieldFill = "INSERT_UPDATE" )
func ParseFieldFill ¶
ParseFieldFill 解析字段填充策略,兼容大小写、短横线和下划线。
type FieldStrategy ¶
type FieldStrategy string
FieldStrategy 描述字段参与 INSERT、UPDATE、WHERE 片段的策略。
const ( // FieldStrategyDefault 表示沿用调用方或全局默认策略。 FieldStrategyDefault FieldStrategy = "" // FieldStrategyAlways 表示字段始终参与 SQL。 FieldStrategyAlways FieldStrategy = "ALWAYS" // FieldStrategyNotNull 表示字段值非 nil 时参与 SQL。 FieldStrategyNotNull FieldStrategy = "NOT_NULL" // FieldStrategyNotEmpty 表示字段值非 nil 且非空字符串、切片、数组或 map 时参与 SQL。 FieldStrategyNotEmpty FieldStrategy = "NOT_EMPTY" // FieldStrategyNotZero 表示字段值非 nil 且非 Go 零值时参与 SQL。 FieldStrategyNotZero FieldStrategy = "NOT_ZERO" // FieldStrategyNever 表示字段永不参与对应 SQL。 FieldStrategyNever FieldStrategy = "NEVER" )
func ParseFieldStrategy ¶
func ParseFieldStrategy(value string) (FieldStrategy, error)
ParseFieldStrategy 解析 MyBatis-Plus 风格字段策略。
type GlobalConfig ¶
type GlobalConfig struct {
DbConfig DbConfig
IdentifierGenerator IdentifierGenerator
MetaObjectHandler MetaObjectHandler
}
GlobalConfig 描述 MyBatis-Plus 风格全局配置。
func DefaultGlobalConfig ¶
func DefaultGlobalConfig() GlobalConfig
DefaultGlobalConfig 返回独立 ORM 的全局默认配置。
type IDType ¶
type IDType string
IDType 表示 MyBatis-Plus 风格主键生成策略。
const ( // IDTypeNone 表示未指定主键策略。 IDTypeNone IDType = "" // IDTypeAuto 表示数据库自增或数据库端生成主键。 IDTypeAuto IDType = "AUTO" // IDTypeInput 表示调用方显式传入主键。 IDTypeInput IDType = "INPUT" // IDTypeAssignID 表示 ORM 在插入前分配整数主键。 IDTypeAssignID IDType = "ASSIGN_ID" // IDTypeAssignUUID 表示 ORM 在插入前分配 UUID 字符串主键。 IDTypeAssignUUID IDType = "ASSIGN_UUID" )
type IdentifierGenerator ¶
type IdentifierGenerator interface {
NextID(ctx context.Context, entity EntityMeta, column ColumnMeta) (any, error)
NextUUID(ctx context.Context, entity EntityMeta, column ColumnMeta) (string, error)
}
IdentifierGenerator 为 ASSIGN_ID 和 ASSIGN_UUID 提供插入前主键。
type IllegalSQLOption ¶
type IllegalSQLOption func(*illegalSQLConfig)
IllegalSQLOption 配置非法 SQL 治理拦截器。
func WithIllegalSQLDenyMultipleStatements ¶
func WithIllegalSQLDenyMultipleStatements(enabled bool) IllegalSQLOption
WithIllegalSQLDenyMultipleStatements 配置是否拒绝多语句 SQL 模板。
func WithIllegalSQLDenySelectWildcard ¶
func WithIllegalSQLDenySelectWildcard(enabled bool) IllegalSQLOption
WithIllegalSQLDenySelectWildcard 配置是否拒绝顶层 SELECT *。
func WithIllegalSQLDenyWriteWithoutWhere ¶
func WithIllegalSQLDenyWriteWithoutWhere(enabled bool) IllegalSQLOption
WithIllegalSQLDenyWriteWithoutWhere 配置是否拒绝无 WHERE 的 UPDATE/DELETE。
type InjectOption ¶
type InjectOption func(*injectOptions)
InjectOption 配置 SQL 注入行为。
func WithInjectDialect ¶
func WithInjectDialect(dialect Dialect) InjectOption
WithInjectDialect 指定注入器使用的数据库方言。
func WithInjectGlobalConfig ¶
func WithInjectGlobalConfig(global GlobalConfig) InjectOption
WithInjectGlobalConfig 指定注入器使用的全局配置。
type Lazy ¶
type Lazy[T any] struct { // contains filtered or unexported fields }
Lazy 表示显式延迟加载的单值关联。
type LazySlice ¶
type LazySlice[T any] struct { // contains filtered or unexported fields }
LazySlice 表示显式延迟加载的集合关联。
func NewLazySlice ¶
NewLazySlice 创建集合延迟加载器。
type LocalCacheScope ¶
type LocalCacheScope string
LocalCacheScope 描述一级缓存作用域。
const ( // LocalCacheScopeSession 表示一级缓存跨同一 Session 的多次语句复用。 LocalCacheScopeSession LocalCacheScope = "SESSION" // LocalCacheScopeStatement 表示一级缓存只服务单次语句执行。 LocalCacheScopeStatement LocalCacheScope = "STATEMENT" )
func ParseLocalCacheScope ¶
func ParseLocalCacheScope(value string) (LocalCacheScope, error)
ParseLocalCacheScope 解析 MyBatis localCacheScope 配置值。
type LogicDeleteByIDInjector ¶
type LogicDeleteByIDInjector struct{}
LogicDeleteByIDInjector 生成按主键逻辑删除语句。
func (LogicDeleteByIDInjector) Inspect ¶
func (LogicDeleteByIDInjector) Inspect(entity EntityMeta, dialect Dialect, global GlobalConfig) ([]StatementMeta, error)
Inspect 生成 LogicDeleteByID Statement。
type ManagedSession ¶
ManagedSession 描述具备 MyBatis 风格生命周期的 Session。
type MapperMeta ¶
type MapperMeta struct {
TypeName string
Namespace string
XML string
Cache CacheMeta
ResultMaps []ResultMapMeta
Statements []StatementMeta
ImplTypeName string
}
MapperMeta 描述一个 Mapper 接口及其语句集合。
type MappingError ¶
type MappingError struct {
Statement string
ResultMap string
Column string
Field string
Message string
Err error
}
MappingError 携带结果映射阶段的 Statement、列名、字段名和 resultMap 信息。
func (*MappingError) Error ¶
func (e *MappingError) Error() string
func (*MappingError) Is ¶
func (e *MappingError) Is(target error) bool
func (*MappingError) Unwrap ¶
func (e *MappingError) Unwrap() error
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache 是并发安全的有界 LRU 二级缓存。
func NewMemoryCache ¶
func NewMemoryCache(id string, options ...MemoryCacheOption) *MemoryCache
NewMemoryCache 创建默认内存二级缓存。
type MemoryCacheOption ¶
type MemoryCacheOption func(*MemoryCache)
MemoryCacheOption 配置默认内存二级缓存。
func WithMemoryCacheMaxEntries ¶
func WithMemoryCacheMaxEntries(maxEntries int) MemoryCacheOption
WithMemoryCacheMaxEntries 设置最大缓存条数,0 表示不缓存任何条目。
func WithMemoryCacheTTL ¶
func WithMemoryCacheTTL(ttl time.Duration) MemoryCacheOption
WithMemoryCacheTTL 设置缓存条目的存活时间。
type MetaObject ¶
type MetaObject struct {
// contains filtered or unexported fields
}
MetaObject 暴露实体字段和 SQL 命名参数的统一填充视图。
func NewMetaObject ¶
func NewMetaObject(entity EntityMeta, target any) (*MetaObject, error)
NewMetaObject 基于实体指针创建可直接填充的元对象。
func (*MetaObject) FieldValue ¶
func (m *MetaObject) FieldValue(name string) (any, bool, error)
FieldValue 读取字段当前值,优先读取实体指针,其次读取命名参数。
func (*MetaObject) HasField ¶
func (m *MetaObject) HasField(name string) bool
HasField 判断实体元数据中是否存在指定字段或列。
func (*MetaObject) SetField ¶
func (m *MetaObject) SetField(name string, value any) error
SetField 覆盖写入指定字段,并同步命名参数中的字段名和 lower-camel 别名。
func (*MetaObject) SetFieldIfZero ¶
func (m *MetaObject) SetFieldIfZero(name string, value any) error
SetFieldIfZero 仅在当前字段为零值时写入指定字段。
func (*MetaObject) StrictInsertFill ¶
func (m *MetaObject) StrictInsertFill(name string, value any) error
StrictInsertFill 在字段允许 INSERT 填充且当前为零值时写入。
func (*MetaObject) StrictUpdateFill ¶
func (m *MetaObject) StrictUpdateFill(name string, value any) error
StrictUpdateFill 在字段允许 UPDATE 填充时覆盖写入。
type MetaObjectHandler ¶
type MetaObjectHandler interface {
InsertFill(ctx context.Context, meta *MetaObject) error
UpdateFill(ctx context.Context, meta *MetaObject) error
}
MetaObjectHandler 按 INSERT/UPDATE 时机填充实体字段或命名参数。
type MetaObjectHandlerFuncs ¶
type MetaObjectHandlerFuncs struct {
Insert func(ctx context.Context, meta *MetaObject) error
Update func(ctx context.Context, meta *MetaObject) error
}
MetaObjectHandlerFuncs 使用函数组合构造 MetaObjectHandler。
func (MetaObjectHandlerFuncs) InsertFill ¶
func (h MetaObjectHandlerFuncs) InsertFill(ctx context.Context, meta *MetaObject) error
InsertFill 执行 INSERT 填充函数。
func (MetaObjectHandlerFuncs) UpdateFill ¶
func (h MetaObjectHandlerFuncs) UpdateFill(ctx context.Context, meta *MetaObject) error
UpdateFill 执行 UPDATE 填充函数。
type MyBatisConfig ¶
type MyBatisConfig struct {
Settings MyBatisSettings
Environment MyBatisEnvironment
TypeAliases []TypeAlias
Mappers []MapperRef
Global GlobalConfig
}
MyBatisConfig 是 MyBatis 配置文件的 Go 化声明模型。
func DefaultMyBatisConfig ¶
func DefaultMyBatisConfig() MyBatisConfig
DefaultMyBatisConfig 返回可直接构建运行期配置的默认声明模型。
func (MyBatisConfig) BuildConfiguration ¶
func (c MyBatisConfig) BuildConfiguration() (Configuration, error)
BuildConfiguration 将声明模型转换为运行期 Configuration。
func (MyBatisConfig) TypeAliasMap ¶
func (c MyBatisConfig) TypeAliasMap() (map[string]string, error)
TypeAliasMap 返回规范化后的别名映射,并拒绝重复别名。
func (MyBatisConfig) Validate ¶
func (c MyBatisConfig) Validate() error
Validate 校验声明模型中的稳定契约,不触发任何文件系统扫描。
type MyBatisEnvironment ¶
MyBatisEnvironment 描述数据库环境配置。Dialect 显式指定时优先于 DbType。
type MyBatisSettings ¶
type MyBatisSettings struct {
CacheEnabled *bool
LocalCacheEnabled *bool
LocalCacheScope LocalCacheScope
MapUnderscoreToCamelCase bool
UseGeneratedKeys bool
LazyLoadingEnabled bool
DefaultExecutorType ExecutorType
DefaultStatementTimeout time.Duration
DefaultFetchSize int
DatabaseID string
}
MyBatisSettings 描述 MyBatis settings 的 Go 化配置子集。
type PageQueryResult ¶
PageQueryResult 描述分页查询除记录外的统计信息。
type PageQuerySession ¶
type PageQuerySession interface {
QueryPage(ctx context.Context, statement string, args NamedArgs, page PageRequest, dest any) (PageQueryResult, error)
}
PageQuerySession 描述支持直接分页查询的 Session。
type PageRequest ¶
PageRequest 描述分页查询输入。
func NewPageRequest ¶
func NewPageRequest(current int64, size int64) PageRequest
NewPageRequest 创建分页请求,页码从 1 开始。
func PageRequestFromContext ¶
func PageRequestFromContext(ctx context.Context) (PageRequest, bool)
PageRequestFromContext 从 context 读取分页请求。
type ParameterHandler ¶
type ParameterHandler interface {
Bind(ctx context.Context, statement StatementMeta, args NamedArgs) (NamedArgs, error)
}
ParameterHandler 负责根据参数类型和 TypeHandler 绑定数据库参数。
type ParameterHandlerMiddleware ¶
type ParameterHandlerMiddleware interface {
WrapParameterHandler(next ParameterHandler) ParameterHandler
}
ParameterHandlerMiddleware 包装参数处理器,用于扩展实体参数绑定和 TypeHandler 入库转换层。
type ParameterHandlerMiddlewareFunc ¶
type ParameterHandlerMiddlewareFunc func(next ParameterHandler) ParameterHandler
ParameterHandlerMiddlewareFunc 将函数适配为 ParameterHandlerMiddleware。
func (ParameterHandlerMiddlewareFunc) WrapParameterHandler ¶
func (f ParameterHandlerMiddlewareFunc) WrapParameterHandler(next ParameterHandler) ParameterHandler
WrapParameterHandler 执行函数式参数处理器包装。
type ParameterMeta ¶
type ParameterMeta struct {
Name string
Mode ParameterMode
JDBCType string
TypeHandler string
}
ParameterMeta 描述可调用语句中的单个参数。
type ParameterMode ¶
type ParameterMode string
ParameterMode 表示可调用语句参数方向。
const ( // ParameterModeIn 表示普通输入参数。 ParameterModeIn ParameterMode = "IN" // ParameterModeOut 表示仅输出参数。 ParameterModeOut ParameterMode = "OUT" // ParameterModeInOut 表示既输入又输出的参数。 ParameterModeInOut ParameterMode = "INOUT" )
func NormalizeParameterMode ¶
func NormalizeParameterMode(mode ParameterMode) ParameterMode
NormalizeParameterMode 返回参数方向的安全默认值。
func ParseParameterMode ¶
func ParseParameterMode(value string) (ParameterMode, error)
ParseParameterMode 解析可调用语句参数方向。
type QueryChain ¶
QueryChain 提供 MyBatis-Plus QueryChainWrapper 风格的查询链。
func (*QueryChain[T, ID]) Count ¶
func (c *QueryChain[T, ID]) Count(ctx context.Context) (int64, error)
Count 执行链式计数查询。
func (*QueryChain[T, ID]) Eq ¶
func (c *QueryChain[T, ID]) Eq(field Field[T], value any) *QueryChain[T, ID]
Eq 添加等值条件。
func (*QueryChain[T, ID]) First ¶
func (c *QueryChain[T, ID]) First(ctx context.Context) (*T, error)
First 执行链式单条查询,多行时返回第一行。
func (*QueryChain[T, ID]) Like ¶
func (c *QueryChain[T, ID]) Like(field Field[T], value any) *QueryChain[T, ID]
Like 添加 LIKE 条件。
func (*QueryChain[T, ID]) List ¶
func (c *QueryChain[T, ID]) List(ctx context.Context) ([]T, error)
List 执行链式列表查询。
func (*QueryChain[T, ID]) Obj ¶
func (c *QueryChain[T, ID]) Obj(ctx context.Context) (any, error)
Obj 执行链式首列单值查询。
func (*QueryChain[T, ID]) Objs ¶
func (c *QueryChain[T, ID]) Objs(ctx context.Context) ([]any, error)
Objs 执行链式首列列表查询。
func (*QueryChain[T, ID]) One ¶
func (c *QueryChain[T, ID]) One(ctx context.Context) (*T, error)
One 执行链式单条查询。
func (*QueryChain[T, ID]) OrderByAsc ¶
func (c *QueryChain[T, ID]) OrderByAsc(field Field[T]) *QueryChain[T, ID]
OrderByAsc 添加升序排序。
func (*QueryChain[T, ID]) OrderByDesc ¶
func (c *QueryChain[T, ID]) OrderByDesc(field Field[T]) *QueryChain[T, ID]
OrderByDesc 添加降序排序。
func (*QueryChain[T, ID]) Page ¶
func (c *QueryChain[T, ID]) Page(ctx context.Context, page PageRequest) (Page[T], error)
Page 执行链式分页查询。
func (*QueryChain[T, ID]) Where ¶
func (c *QueryChain[T, ID]) Where(apply func(*QueryWrapper[T])) *QueryChain[T, ID]
Where 使用底层 QueryWrapper 添加复杂条件。
func (*QueryChain[T, ID]) Wrapper ¶
func (c *QueryChain[T, ID]) Wrapper() *QueryWrapper[T]
Wrapper 返回底层查询 Wrapper。
type QueryWrapper ¶
type QueryWrapper[T any] struct { // contains filtered or unexported fields }
QueryWrapper 是 MyBatis-Plus Wrapper 的 Go 化条件构造器。
func (*QueryWrapper[T]) AllEq ¶
func (w *QueryWrapper[T]) AllEq(values map[Field[T]]any) *QueryWrapper[T]
AllEq 按 map 批量添加等值条件。
func (*QueryWrapper[T]) And ¶
func (w *QueryWrapper[T]) And(apply func(*QueryWrapper[T])) *QueryWrapper[T]
And 添加 AND 连接的嵌套条件组。
func (*QueryWrapper[T]) Apply ¶
func (w *QueryWrapper[T]) Apply(sqlText string, args NamedArgs) *QueryWrapper[T]
Apply 添加自定义条件片段,SQL 仅允许 #{name} 参数占位符。
func (*QueryWrapper[T]) Between ¶
func (w *QueryWrapper[T]) Between(field Field[T], left any, right any) *QueryWrapper[T]
Between 添加 BETWEEN 条件。
func (*QueryWrapper[T]) BetweenTyped ¶
func (w *QueryWrapper[T]) BetweenTyped(field TypedFieldRef[T], left any, right any) *QueryWrapper[T]
BetweenTyped 添加类型化字段引用的 BETWEEN 条件。
func (*QueryWrapper[T]) Eq ¶
func (w *QueryWrapper[T]) Eq(field Field[T], value any) *QueryWrapper[T]
Eq 添加等值条件。
func (*QueryWrapper[T]) EqIf ¶
func (w *QueryWrapper[T]) EqIf(condition bool, field Field[T], value any) *QueryWrapper[T]
EqIf 在 condition 为 true 时添加等值条件。
func (*QueryWrapper[T]) EqTyped ¶
func (w *QueryWrapper[T]) EqTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
EqTyped 添加类型化字段引用的等值条件。
func (*QueryWrapper[T]) Exists ¶
func (w *QueryWrapper[T]) Exists(sqlText string, args NamedArgs) *QueryWrapper[T]
Exists 添加 EXISTS 子查询条件,SQL 仅允许 #{name} 参数占位符。
func (*QueryWrapper[T]) Ge ¶
func (w *QueryWrapper[T]) Ge(field Field[T], value any) *QueryWrapper[T]
Ge 添加大于等于条件。
func (*QueryWrapper[T]) GeTyped ¶
func (w *QueryWrapper[T]) GeTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
GeTyped 添加类型化字段引用的大于等于条件。
func (*QueryWrapper[T]) GroupBy ¶
func (w *QueryWrapper[T]) GroupBy(fields ...Field[T]) *QueryWrapper[T]
GroupBy 添加 GROUP BY 字段。
func (*QueryWrapper[T]) GroupByTyped ¶
func (w *QueryWrapper[T]) GroupByTyped(fields ...TypedFieldRef[T]) *QueryWrapper[T]
GroupByTyped 添加类型化字段引用的 GROUP BY 字段。
func (*QueryWrapper[T]) Gt ¶
func (w *QueryWrapper[T]) Gt(field Field[T], value any) *QueryWrapper[T]
Gt 添加大于条件。
func (*QueryWrapper[T]) GtTyped ¶
func (w *QueryWrapper[T]) GtTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
GtTyped 添加类型化字段引用的大于条件。
func (*QueryWrapper[T]) Having ¶
func (w *QueryWrapper[T]) Having(sqlText string, args NamedArgs) *QueryWrapper[T]
Having 添加 HAVING 条件片段,SQL 仅允许 #{name} 参数占位符。
func (*QueryWrapper[T]) In ¶
func (w *QueryWrapper[T]) In(field Field[T], values any) *QueryWrapper[T]
In 添加 IN 条件。空集合会渲染为 1 = 0,避免意外全量命中。
func (*QueryWrapper[T]) InTyped ¶
func (w *QueryWrapper[T]) InTyped(field TypedFieldRef[T], values any) *QueryWrapper[T]
InTyped 添加类型化字段引用的 IN 条件。
func (*QueryWrapper[T]) IsNotNull ¶
func (w *QueryWrapper[T]) IsNotNull(field Field[T]) *QueryWrapper[T]
IsNotNull 添加 IS NOT NULL 条件。
func (*QueryWrapper[T]) IsNotNullTyped ¶
func (w *QueryWrapper[T]) IsNotNullTyped(field TypedFieldRef[T]) *QueryWrapper[T]
IsNotNullTyped 添加类型化字段引用的 IS NOT NULL 条件。
func (*QueryWrapper[T]) IsNull ¶
func (w *QueryWrapper[T]) IsNull(field Field[T]) *QueryWrapper[T]
IsNull 添加 IS NULL 条件。
func (*QueryWrapper[T]) IsNullTyped ¶
func (w *QueryWrapper[T]) IsNullTyped(field TypedFieldRef[T]) *QueryWrapper[T]
IsNullTyped 添加类型化字段引用的 IS NULL 条件。
func (*QueryWrapper[T]) Last ¶
func (w *QueryWrapper[T]) Last(sqlText string) *QueryWrapper[T]
Last 添加 SQL 尾部片段,例如 FOR UPDATE。尾部不支持参数绑定。
func (*QueryWrapper[T]) Le ¶
func (w *QueryWrapper[T]) Le(field Field[T], value any) *QueryWrapper[T]
Le 添加小于等于条件。
func (*QueryWrapper[T]) LeTyped ¶
func (w *QueryWrapper[T]) LeTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
LeTyped 添加类型化字段引用的小于等于条件。
func (*QueryWrapper[T]) Like ¶
func (w *QueryWrapper[T]) Like(field Field[T], value any) *QueryWrapper[T]
Like 添加 LIKE 条件,通配符由调用方显式传入。
func (*QueryWrapper[T]) LikeLeft ¶
func (w *QueryWrapper[T]) LikeLeft(field Field[T], value any) *QueryWrapper[T]
LikeLeft 添加左侧模糊匹配条件。
func (*QueryWrapper[T]) LikeLeftTyped ¶
func (w *QueryWrapper[T]) LikeLeftTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
LikeLeftTyped 添加类型化字段引用的左侧模糊匹配条件。
func (*QueryWrapper[T]) LikeRight ¶
func (w *QueryWrapper[T]) LikeRight(field Field[T], value any) *QueryWrapper[T]
LikeRight 添加右侧模糊匹配条件。
func (*QueryWrapper[T]) LikeRightTyped ¶
func (w *QueryWrapper[T]) LikeRightTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
LikeRightTyped 添加类型化字段引用的右侧模糊匹配条件。
func (*QueryWrapper[T]) LikeTyped ¶
func (w *QueryWrapper[T]) LikeTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
LikeTyped 添加类型化字段引用的 LIKE 条件。
func (*QueryWrapper[T]) Lt ¶
func (w *QueryWrapper[T]) Lt(field Field[T], value any) *QueryWrapper[T]
Lt 添加小于条件。
func (*QueryWrapper[T]) LtTyped ¶
func (w *QueryWrapper[T]) LtTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
LtTyped 添加类型化字段引用的小于条件。
func (*QueryWrapper[T]) Ne ¶
func (w *QueryWrapper[T]) Ne(field Field[T], value any) *QueryWrapper[T]
Ne 添加不等条件。
func (*QueryWrapper[T]) NeTyped ¶
func (w *QueryWrapper[T]) NeTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
NeTyped 添加类型化字段引用的不等条件。
func (*QueryWrapper[T]) Nested ¶
func (w *QueryWrapper[T]) Nested(apply func(*QueryWrapper[T])) *QueryWrapper[T]
Nested 添加默认 AND 连接的嵌套条件组。
func (*QueryWrapper[T]) NotBetween ¶
func (w *QueryWrapper[T]) NotBetween(field Field[T], left any, right any) *QueryWrapper[T]
NotBetween 添加 NOT BETWEEN 条件。
func (*QueryWrapper[T]) NotBetweenTyped ¶
func (w *QueryWrapper[T]) NotBetweenTyped(field TypedFieldRef[T], left any, right any) *QueryWrapper[T]
NotBetweenTyped 添加类型化字段引用的 NOT BETWEEN 条件。
func (*QueryWrapper[T]) NotExists ¶
func (w *QueryWrapper[T]) NotExists(sqlText string, args NamedArgs) *QueryWrapper[T]
NotExists 添加 NOT EXISTS 子查询条件,SQL 仅允许 #{name} 参数占位符。
func (*QueryWrapper[T]) NotIn ¶
func (w *QueryWrapper[T]) NotIn(field Field[T], values any) *QueryWrapper[T]
NotIn 添加 NOT IN 条件。空集合会渲染为 1 = 0,避免写操作意外放大。
func (*QueryWrapper[T]) NotInTyped ¶
func (w *QueryWrapper[T]) NotInTyped(field TypedFieldRef[T], values any) *QueryWrapper[T]
NotInTyped 添加类型化字段引用的 NOT IN 条件。
func (*QueryWrapper[T]) NotLike ¶
func (w *QueryWrapper[T]) NotLike(field Field[T], value any) *QueryWrapper[T]
NotLike 添加 NOT LIKE 条件。
func (*QueryWrapper[T]) NotLikeTyped ¶
func (w *QueryWrapper[T]) NotLikeTyped(field TypedFieldRef[T], value any) *QueryWrapper[T]
NotLikeTyped 添加类型化字段引用的 NOT LIKE 条件。
func (*QueryWrapper[T]) Or ¶
func (w *QueryWrapper[T]) Or(apply func(*QueryWrapper[T])) *QueryWrapper[T]
Or 添加 OR 连接的嵌套条件组。
func (*QueryWrapper[T]) OrderBy ¶
func (w *QueryWrapper[T]) OrderBy(condition bool, asc bool, fields ...Field[T]) *QueryWrapper[T]
OrderBy 按条件和方向添加排序。
func (*QueryWrapper[T]) OrderByAsc ¶
func (w *QueryWrapper[T]) OrderByAsc(field Field[T]) *QueryWrapper[T]
OrderByAsc 添加升序排序。
func (*QueryWrapper[T]) OrderByAscTyped ¶
func (w *QueryWrapper[T]) OrderByAscTyped(field TypedFieldRef[T]) *QueryWrapper[T]
OrderByAscTyped 添加类型化字段引用的升序排序。
func (*QueryWrapper[T]) OrderByDesc ¶
func (w *QueryWrapper[T]) OrderByDesc(field Field[T]) *QueryWrapper[T]
OrderByDesc 添加降序排序。
func (*QueryWrapper[T]) OrderByDescTyped ¶
func (w *QueryWrapper[T]) OrderByDescTyped(field TypedFieldRef[T]) *QueryWrapper[T]
OrderByDescTyped 添加类型化字段引用的降序排序。
func (*QueryWrapper[T]) OrderByTyped ¶
func (w *QueryWrapper[T]) OrderByTyped(condition bool, asc bool, fields ...TypedFieldRef[T]) *QueryWrapper[T]
OrderByTyped 按条件和方向添加类型化字段排序。
func (*QueryWrapper[T]) Select ¶
func (w *QueryWrapper[T]) Select(fields ...Field[T]) *QueryWrapper[T]
Select 指定查询投影字段。
func (*QueryWrapper[T]) SelectTyped ¶
func (w *QueryWrapper[T]) SelectTyped(fields ...TypedFieldRef[T]) *QueryWrapper[T]
SelectTyped 指定类型化字段查询投影。
func (*QueryWrapper[T]) When ¶
func (w *QueryWrapper[T]) When(condition bool, apply func(*QueryWrapper[T])) *QueryWrapper[T]
When 在 condition 为 true 时应用构造逻辑。
type RawIdentifier ¶
type RawIdentifier struct {
// contains filtered or unexported fields
}
RawIdentifier 表示表名、列名或 schema.table 形式的标识符。
func NewRawIdentifier ¶
func NewRawIdentifier(name string) (RawIdentifier, error)
NewRawIdentifier 创建受控 SQL 标识符 token。
type RawOrderBy ¶
type RawOrderBy struct {
// contains filtered or unexported fields
}
RawOrderBy 表示 ORDER BY 子句后的受控字段列表。
func NewRawOrderBy ¶
func NewRawOrderBy(items ...RawOrderItem) RawOrderBy
NewRawOrderBy 创建受控 ORDER BY token。
type RawOrderItem ¶
type RawOrderItem struct {
Column RawIdentifier
Desc bool
}
RawOrderItem 表示 ORDER BY 中的一个受控字段。
func NewRawOrderItem ¶
func NewRawOrderItem(column string, desc bool) (RawOrderItem, error)
NewRawOrderItem 创建受控排序字段。
type RawSQLToken ¶
type RawSQLToken interface {
// contains filtered or unexported methods
}
RawSQLToken 表示允许进入 ${} 的受控 SQL 片段。
接口包含非导出方法,外部包只能通过本包构造器创建安全 token。
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry 保存编译期生成的 ORM 元数据。
func (*Registry) Entity ¶
func (r *Registry) Entity(typeName string) (EntityMeta, bool)
Entity 按实体类型名读取元数据。
func (*Registry) Mapper ¶
func (r *Registry) Mapper(namespace string) (MapperMeta, bool)
Mapper 按 namespace 读取 Mapper 元数据。
func (*Registry) RegisterCache ¶
RegisterCache 注册或替换指定 namespace 的二级缓存实现。
func (*Registry) RegisterEntity ¶
func (r *Registry) RegisterEntity(meta EntityMeta) error
RegisterEntity 注册实体元数据。
func (*Registry) RegisterMapper ¶
func (r *Registry) RegisterMapper(meta MapperMeta) error
RegisterMapper 注册 Mapper 元数据,并同步注册内部 Statement。
func (*Registry) RegisterRowScanner ¶
func (r *Registry) RegisterRowScanner(typeName string, scanner RowScanner) error
RegisterRowScanner 注册或替换指定实体类型的生成式行扫描器。
func (*Registry) RegisterSQLProvider ¶
func (r *Registry) RegisterSQLProvider(name string, provider SQLProvider) error
RegisterSQLProvider 注册或替换全局 SQL Provider。
func (*Registry) RegisterTypeHandler ¶
func (r *Registry) RegisterTypeHandler(name string, handler TypeHandler) error
RegisterTypeHandler 注册或替换全局 TypeHandler。
func (*Registry) RegisterTypeHandlers ¶
func (r *Registry) RegisterTypeHandlers(handlers map[string]TypeHandler) error
RegisterTypeHandlers 批量注册或替换全局 TypeHandler。
func (*Registry) RowScanner ¶
func (r *Registry) RowScanner(typeName string) (RowScanner, bool)
RowScanner 按实体类型名读取生成式行扫描器。
func (*Registry) SQLProvider ¶
func (r *Registry) SQLProvider(name string) (SQLProvider, bool)
SQLProvider 按名称读取全局 SQL Provider。
func (*Registry) Statement ¶
func (r *Registry) Statement(fullName string) (StatementMeta, bool)
Statement 按完整 Statement 名称读取语句元数据。
func (*Registry) TypeHandler ¶
func (r *Registry) TypeHandler(name string) (TypeHandler, bool)
TypeHandler 按名称读取全局 TypeHandler。
func (*Registry) TypeHandlers ¶
func (r *Registry) TypeHandlers() map[string]TypeHandler
TypeHandlers 返回全局 TypeHandler 快照。
type RegistryError ¶
RegistryError 携带元数据资源类型、名称和底层原因。
func (*RegistryError) Error ¶
func (e *RegistryError) Error() string
func (*RegistryError) Is ¶
func (e *RegistryError) Is(target error) bool
func (*RegistryError) Unwrap ¶
func (e *RegistryError) Unwrap() error
type RenderedSQL ¶
RenderedSQL 表示动态 SQL 渲染后的 SQL 和参数。
func RenderDynamicSQL ¶
func RenderDynamicSQL(nodes []DynamicSQLNode, args NamedArgs) (RenderedSQL, error)
RenderDynamicSQL 将动态 SQL 节点树渲染为可继续参数编译的 SQL。
type ResultArgMeta ¶
ResultArgMeta 描述 constructor 中的 arg 或 idArg。
type ResultAssociationMeta ¶
type ResultAssociationMeta struct {
Property string
TypeName string
Column string
ColumnPrefix string
NotNullColumns []string
Select string
FetchType string
Fields []ResultFieldMeta
Associations []ResultAssociationMeta
Collections []ResultCollectionMeta
}
ResultAssociationMeta 描述 resultMap 中的嵌套对象映射。
type ResultCollectionMeta ¶
type ResultCollectionMeta struct {
Property string
TypeName string
Column string
ColumnPrefix string
NotNullColumns []string
Select string
FetchType string
Fields []ResultFieldMeta
Associations []ResultAssociationMeta
Collections []ResultCollectionMeta
}
ResultCollectionMeta 描述 resultMap 中的嵌套集合映射。
type ResultConstructorMeta ¶
type ResultConstructorMeta struct {
Args []ResultArgMeta
}
ResultConstructorMeta 描述 resultMap 的构造参数映射。
type ResultDiscriminatorCaseMeta ¶
type ResultDiscriminatorCaseMeta struct {
Value string
ResultMap string
ResultType string
Fields []ResultFieldMeta
Associations []ResultAssociationMeta
Collections []ResultCollectionMeta
}
ResultDiscriminatorCaseMeta 描述 discriminator 的单个 case。
type ResultDiscriminatorMeta ¶
type ResultDiscriminatorMeta struct {
Column string
TypeName string
TypeHandler string
Cases []ResultDiscriminatorCaseMeta
}
ResultDiscriminatorMeta 描述 MyBatis resultMap discriminator。
type ResultFieldMeta ¶
ResultFieldMeta 描述 XML resultMap 中的一项结果映射。
type ResultHandler ¶
ResultHandler 逐条消费查询结果。
type ResultMapMeta ¶
type ResultMapMeta struct {
ID string
TypeName string
Extends string
AutoMapping *bool
Constructor ResultConstructorMeta
Fields []ResultFieldMeta
Associations []ResultAssociationMeta
Collections []ResultCollectionMeta
Discriminator ResultDiscriminatorMeta
}
ResultMapMeta 描述 XML resultMap。
type ResultSetHandler ¶
type ResultSetHandler interface {
ScanRows(ctx context.Context, rows Rows, statement StatementMeta, dest any) error
ScanOne(ctx context.Context, rows Rows, statement StatementMeta, dest any) error
}
ResultSetHandler 负责把 database/sql 行集扫描到调用方目标对象。
type ResultSetHandlerMiddleware ¶
type ResultSetHandlerMiddleware interface {
WrapResultSetHandler(next ResultSetHandler) ResultSetHandler
}
ResultSetHandlerMiddleware 包装结果集处理器,用于扩展行扫描和结果映射层。
type ResultSetHandlerMiddlewareFunc ¶
type ResultSetHandlerMiddlewareFunc func(next ResultSetHandler) ResultSetHandler
ResultSetHandlerMiddlewareFunc 将函数适配为 ResultSetHandlerMiddleware。
func (ResultSetHandlerMiddlewareFunc) WrapResultSetHandler ¶
func (f ResultSetHandlerMiddlewareFunc) WrapResultSetHandler(next ResultSetHandler) ResultSetHandler
WrapResultSetHandler 执行函数式结果集处理器包装。
type ResultSetMeta ¶
ResultSetMeta 描述存储过程返回的一个结果集。
type ResultSetRows ¶
ResultSetRows 描述支持多结果集前进的行集。
type ResultSetType ¶
type ResultSetType string
ResultSetType 描述 Statement 期望的结果集游标类型。
const ( // ResultSetTypeForwardOnly 表示只向前读取的结果集。 ResultSetTypeForwardOnly ResultSetType = "FORWARD_ONLY" // ResultSetTypeScrollInsensitive 表示可滚动且不感知底层数据变化的结果集。 ResultSetTypeScrollInsensitive ResultSetType = "SCROLL_INSENSITIVE" // ResultSetTypeScrollSensitive 表示可滚动且感知底层数据变化的结果集。 ResultSetTypeScrollSensitive ResultSetType = "SCROLL_SENSITIVE" )
func ParseResultSetType ¶
func ParseResultSetType(value string) (ResultSetType, error)
ParseResultSetType 解析 MyBatis resultSetType 配置值。
type RoutingOperation ¶
type RoutingOperation struct {
Kind RoutingOperationKind
Statement string
Command StatementCommand
Args NamedArgs
Page PageRequest
}
RoutingOperation 描述一次待路由的 ORM 操作。
type RoutingOperationKind ¶
type RoutingOperationKind string
RoutingOperationKind 表示路由时的 ORM 操作类型。
const ( // RoutingOperationQuery 表示多行查询。 RoutingOperationQuery RoutingOperationKind = "query" // RoutingOperationQueryOne 表示单行查询。 RoutingOperationQueryOne RoutingOperationKind = "query-one" // RoutingOperationExec 表示写语句执行。 RoutingOperationExec RoutingOperationKind = "exec" // RoutingOperationCall 表示存储过程调用。 RoutingOperationCall RoutingOperationKind = "call" // RoutingOperationPage 表示分页查询。 RoutingOperationPage RoutingOperationKind = "page" )
type RoutingSession ¶
type RoutingSession struct {
// contains filtered or unexported fields
}
RoutingSession 按 context 和路由规则把 ORM 操作转发到具体 Session。
func NewRoutingSession ¶
func NewRoutingSession(sessions map[DataSourceKey]Session, resolver DataSourceResolver, options ...RoutingSessionOption) (*RoutingSession, error)
NewRoutingSession 创建多数据源路由 Session。
func (*RoutingSession) Call ¶
func (s *RoutingSession) Call(ctx context.Context, statement string, args NamedArgs, resultSets ...any) (CallResult, error)
Call 路由并执行存储过程调用。
func (*RoutingSession) Close ¶
func (s *RoutingSession) Close() error
Close 关闭所有实现 Close 方法的委托 Session。
func (*RoutingSession) Exec ¶
func (s *RoutingSession) Exec(ctx context.Context, statement string, args NamedArgs) (Result, error)
Exec 路由并执行写语句。
func (*RoutingSession) Query ¶
func (s *RoutingSession) Query(ctx context.Context, statement string, args NamedArgs, dest any) error
Query 路由并执行多行查询。
func (*RoutingSession) QueryOne ¶
func (s *RoutingSession) QueryOne(ctx context.Context, statement string, args NamedArgs, dest any) error
QueryOne 路由并执行单行查询。
func (*RoutingSession) QueryPage ¶
func (s *RoutingSession) QueryPage(ctx context.Context, statement string, args NamedArgs, page PageRequest, dest any) (PageQueryResult, error)
QueryPage 路由并执行分页查询。
type RoutingSessionFactory ¶
type RoutingSessionFactory struct {
// contains filtered or unexported fields
}
RoutingSessionFactory 创建多数据源路由 Session。
func NewRoutingSessionFactory ¶
func NewRoutingSessionFactory(openers map[DataSourceKey]SessionOpenFunc, resolver DataSourceResolver, options ...RoutingSessionOption) (*RoutingSessionFactory, error)
NewRoutingSessionFactory 创建多数据源路由 SessionFactory。
func (*RoutingSessionFactory) OpenSession ¶
func (f *RoutingSessionFactory) OpenSession() (*RoutingSession, error)
OpenSession 打开所有委托 Session,并返回路由 Session。
type RoutingSessionOption ¶
type RoutingSessionOption func(*RoutingSession) error
RoutingSessionOption 配置多数据源路由 Session。
func WithRoutingDefaultDataSource ¶
func WithRoutingDefaultDataSource(key DataSourceKey) RoutingSessionOption
WithRoutingDefaultDataSource 配置默认数据源。
func WithRoutingRegistry ¶
func WithRoutingRegistry(registry *Registry) RoutingSessionOption
WithRoutingRegistry 配置用于读取 StatementCommand 的 Registry。
type RowCursor ¶
type RowCursor struct {
// contains filtered or unexported fields
}
RowCursor 暴露非泛型行游标,供框架扩展和自定义扫描使用。
type RowScanner ¶
type RowScanner interface {
ScanRow(ctx context.Context, columns []string, row RowScannerRow, dest any) error
}
RowScanner 描述由生成器输出的实体行扫描器。
type RowScannerFunc ¶
RowScannerFunc 将函数适配为 RowScanner。
func (RowScannerFunc) ScanRow ¶
func (f RowScannerFunc) ScanRow(ctx context.Context, columns []string, row RowScannerRow, dest any) error
ScanRow 执行函数式行扫描器。
type RowScannerRow ¶
RowScannerRow 是生成式行扫描器需要的最小行读取契约。
type Rows ¶
type Rows interface {
Columns() ([]string, error)
Next() bool
Scan(dest ...any) error
Err() error
Close() error
}
Rows 是 *sql.Rows 的最小扫描接口,便于测试和自定义执行器复用扫描器。
type SQLCondition ¶
SQLCondition 描述可注入到 WHERE 子句的 SQL 条件。
type SQLExecutor ¶
type SQLExecutor interface {
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}
SQLExecutor 是 *sql.DB 和 *sql.Tx 共同满足的最小执行接口。
type SQLFetchSizeApplier ¶
type SQLFetchSizeApplier interface {
ApplyFetchSize(ctx context.Context, query string, fetchSize int) error
}
SQLFetchSizeApplier 是支持查询级 fetch size 的可选执行器能力。
type SQLGuardRule ¶
type SQLGuardRule interface {
CheckSQL(ctx context.Context, statement StatementMeta, sql string) error
}
SQLGuardRule 表示一条可组合的 SQL 治理规则。
type SQLGuardRuleFunc ¶
type SQLGuardRuleFunc func(ctx context.Context, statement StatementMeta, sql string) error
SQLGuardRuleFunc 将函数适配为 SQLGuardRule。
func (SQLGuardRuleFunc) CheckSQL ¶
func (f SQLGuardRuleFunc) CheckSQL(ctx context.Context, statement StatementMeta, sql string) error
CheckSQL 执行函数式 SQL 治理规则。
type SQLInjector ¶
type SQLInjector interface {
Inspect(entity EntityMeta, dialect Dialect, global GlobalConfig) ([]StatementMeta, error)
}
SQLInjector 对齐 MyBatis-Plus SQL Injector,用于为实体生成通用方法语句。
type SQLInjectorFunc ¶
type SQLInjectorFunc func(entity EntityMeta, dialect Dialect, global GlobalConfig) ([]StatementMeta, error)
SQLInjectorFunc 允许用函数声明轻量注入器。
func (SQLInjectorFunc) Inspect ¶
func (f SQLInjectorFunc) Inspect(entity EntityMeta, dialect Dialect, global GlobalConfig) ([]StatementMeta, error)
Inspect 执行函数式 SQL 注入器。
type SQLObservation ¶
type SQLObservation struct {
Statement StatementMeta
SQL string
Args NamedArgs
Dialect Dialect
}
SQLObservation 描述一次 SQL 模板观察事件。
type SQLPreparer ¶
SQLPreparer 是支持预编译语句的可选执行器能力。
type SQLProvider ¶
type SQLProvider func(ctx context.Context, statement StatementMeta, args NamedArgs) (SQLSource, error)
SQLProvider 按 Statement 和入参在运行期生成 SQL。
type SQLSession ¶
type SQLSession struct {
// contains filtered or unexported fields
}
SQLSession 基于 database/sql 执行已经注册的 Statement。
func NewSQLSession ¶
func NewSQLSession(registry *Registry, executor SQLExecutor, dialect Dialect, options ...SQLSessionOption) (*SQLSession, error)
NewSQLSession 创建可独立使用的 database/sql ORM Session。
func (*SQLSession) Call ¶
func (s *SQLSession) Call(ctx context.Context, statement string, args NamedArgs, resultSets ...any) (CallResult, error)
Call 执行存储过程或可调用语句。
func (*SQLSession) CallStatement ¶
func (s *SQLSession) CallStatement(ctx context.Context, meta StatementMeta, args NamedArgs, resultSets ...any) (CallResult, error)
CallStatement 基于 StatementMeta 执行存储过程或可调用语句。
func (*SQLSession) Close ¶
func (s *SQLSession) Close() error
Close 关闭自动提交 Session。底层连接由 database/sql 管理。
func (*SQLSession) Configuration ¶
func (s *SQLSession) Configuration() Configuration
Configuration 返回当前 Session 使用的配置快照。
func (*SQLSession) ExecStatement ¶
func (s *SQLSession) ExecStatement(ctx context.Context, meta StatementMeta, args NamedArgs) (Result, error)
ExecStatement 执行写入语句元数据。
func (*SQLSession) GlobalConfig ¶
func (s *SQLSession) GlobalConfig() GlobalConfig
GlobalConfig 返回当前 Session 使用的全局配置快照。
func (*SQLSession) IdentifierGenerator ¶
func (s *SQLSession) IdentifierGenerator() IdentifierGenerator
IdentifierGenerator 返回当前 Session 使用的主键生成器。
func (*SQLSession) MetaObjectHandler ¶
func (s *SQLSession) MetaObjectHandler() MetaObjectHandler
MetaObjectHandler 返回当前 Session 使用的自动填充处理器。
func (*SQLSession) QueryCursor ¶
func (s *SQLSession) QueryCursor(ctx context.Context, statement string, args NamedArgs) (*RowCursor, error)
QueryCursor 执行查询并返回非泛型行游标。
func (*SQLSession) QueryCursorStatement ¶
func (s *SQLSession) QueryCursorStatement(ctx context.Context, meta StatementMeta, args NamedArgs) (*RowCursor, error)
QueryCursorStatement 基于 StatementMeta 打开非泛型行游标。
func (*SQLSession) QueryOne ¶
func (s *SQLSession) QueryOne(ctx context.Context, statement string, args NamedArgs, dest any) error
QueryOne 执行查询语句并要求最多返回一行。
func (*SQLSession) QueryOneStatement ¶
func (s *SQLSession) QueryOneStatement(ctx context.Context, meta StatementMeta, args NamedArgs, dest any) error
QueryOneStatement 执行查询语句元数据并要求最多返回一行。
func (*SQLSession) QueryPage ¶
func (s *SQLSession) QueryPage(ctx context.Context, statement string, args NamedArgs, page PageRequest, dest any) (PageQueryResult, error)
QueryPage 执行分页查询并把记录扫描到 dest。
func (*SQLSession) QueryPageStatement ¶
func (s *SQLSession) QueryPageStatement(ctx context.Context, meta StatementMeta, args NamedArgs, page PageRequest, dest any) (PageQueryResult, error)
QueryPageStatement 基于 StatementMeta 执行分页查询。
func (*SQLSession) QueryStatement ¶
func (s *SQLSession) QueryStatement(ctx context.Context, meta StatementMeta, args NamedArgs, dest any) error
QueryStatement 执行查询语句元数据并扫描多行结果。
type SQLSessionFactory ¶
type SQLSessionFactory struct {
// contains filtered or unexported fields
}
SQLSessionFactory 创建普通 Session 和事务 Session。
func NewSQLSessionFactory ¶
func NewSQLSessionFactory(registry *Registry, db *sql.DB, dialect Dialect, options ...SQLSessionOption) (*SQLSessionFactory, error)
NewSQLSessionFactory 创建基于 database/sql 的 SessionFactory。
func (*SQLSessionFactory) BeginBatchTx ¶
func (f *SQLSessionFactory) BeginBatchTx(ctx context.Context, opts *sql.TxOptions) (*BatchSession, error)
BeginBatchTx 打开手动事务批处理 Session。
func (*SQLSessionFactory) InTx ¶
func (f *SQLSessionFactory) InTx(ctx context.Context, opts *sql.TxOptions, fn func(context.Context, Session) error) error
InTx 在事务中执行回调,回调返回错误时自动回滚。
func (*SQLSessionFactory) OpenBatchSession ¶
func (f *SQLSessionFactory) OpenBatchSession() (*BatchSession, error)
OpenBatchSession 打开自动提交批处理 Session。
func (*SQLSessionFactory) OpenConfiguredSession ¶
func (f *SQLSessionFactory) OpenConfiguredSession() (Session, error)
OpenConfiguredSession 按运行期 Configuration 打开 Session。
当 DefaultExecutorType 为 BATCH 时返回 BatchSession;其他执行器类型返回普通 SQLSession。 该方法保留 OpenSession 的既有返回类型,避免破坏 V1 公共契约。
func (*SQLSessionFactory) OpenSession ¶
func (f *SQLSessionFactory) OpenSession() (*SQLSession, error)
OpenSession 打开自动提交 Session。
func (*SQLSessionFactory) SetTransactionFactory ¶
func (f *SQLSessionFactory) SetTransactionFactory(factory TransactionFactory) error
SetTransactionFactory 替换事务工厂,供外部集成层适配自定义事务来源。
type SQLSessionOption ¶
type SQLSessionOption func(*SQLSession) error
SQLSessionOption 配置 SQLSession。
func WithConfiguration ¶
func WithConfiguration(config Configuration) SQLSessionOption
WithConfiguration 应用独立 ORM 配置。
func WithIdentifierGenerator ¶
func WithIdentifierGenerator(generator IdentifierGenerator) SQLSessionOption
WithIdentifierGenerator 替换 Session 级主键生成器。
func WithInterceptors ¶
func WithInterceptors(interceptors ...StatementInterceptor) SQLSessionOption
WithInterceptors 为 SQLSession 注册 Statement 拦截器。
func WithLocalCache ¶
func WithLocalCache(enabled bool) SQLSessionOption
WithLocalCache 配置 Session 级一级缓存。
func WithMetaObjectHandler ¶
func WithMetaObjectHandler(handler MetaObjectHandler) SQLSessionOption
WithMetaObjectHandler 配置 Session 级自动填充处理器。
func WithParameterHandler ¶
func WithParameterHandler(handler ParameterHandler) SQLSessionOption
WithParameterHandler 替换参数绑定处理器。
func WithParameterHandlerMiddleware ¶
func WithParameterHandlerMiddleware(middleware ...ParameterHandlerMiddleware) SQLSessionOption
WithParameterHandlerMiddleware 按声明顺序包装 ParameterHandler。
func WithResultSetHandler ¶
func WithResultSetHandler(handler ResultSetHandler) SQLSessionOption
WithResultSetHandler 替换结果集扫描处理器。
func WithResultSetHandlerMiddleware ¶
func WithResultSetHandlerMiddleware(middleware ...ResultSetHandlerMiddleware) SQLSessionOption
WithResultSetHandlerMiddleware 按声明顺序包装 ResultSetHandler。
func WithStatementExecutor ¶
func WithStatementExecutor(executor StatementExecutor) SQLSessionOption
WithStatementExecutor 替换 Session 级 Statement 执行器。
func WithStatementExecutorMiddleware ¶
func WithStatementExecutorMiddleware(middleware ...StatementExecutorMiddleware) SQLSessionOption
WithStatementExecutorMiddleware 按声明顺序包装 StatementExecutor。
func WithStatementHandler ¶
func WithStatementHandler(handler StatementHandler) SQLSessionOption
WithStatementHandler 替换 Statement 编译处理器。
func WithStatementHandlerMiddleware ¶
func WithStatementHandlerMiddleware(middleware ...StatementHandlerMiddleware) SQLSessionOption
WithStatementHandlerMiddleware 按声明顺序包装 StatementHandler。
func WithTypeHandler ¶
func WithTypeHandler(name string, handler TypeHandler) SQLSessionOption
WithTypeHandler 注册运行时 TypeHandler。
func WithTypeHandlers ¶
func WithTypeHandlers(handlers map[string]TypeHandler) SQLSessionOption
WithTypeHandlers 批量注册 Session 级 TypeHandler。
type SQLSource ¶
type SQLSource struct {
SQL string
DynamicSQL []DynamicSQLNode
}
SQLSource 表示 Provider 在运行期返回的 SQL 来源。
type SQLStatementOptionsApplier ¶
type SQLStatementOptionsApplier interface {
ApplyStatementOptions(ctx context.Context, query string, options StatementOptions) error
}
SQLStatementOptionsApplier 是支持完整语句级执行选项的可选执行器能力。
type SQLTransactionFactory ¶
type SQLTransactionFactory struct{}
SQLTransactionFactory 基于 database/sql 创建事务。
func NewSQLTransactionFactory ¶
func NewSQLTransactionFactory() SQLTransactionFactory
NewSQLTransactionFactory 创建默认 database/sql 事务工厂。
func (SQLTransactionFactory) Begin ¶
func (SQLTransactionFactory) Begin(ctx context.Context, source TransactionSource, opts *sql.TxOptions) (Transaction, error)
Begin 开启 database/sql 事务。
type SelectKeyMeta ¶
type SelectKeyMeta struct {
Enabled bool
KeyProperty string
ResultType string
Order SelectKeyOrder
SQL string
DynamicSQL []DynamicSQLNode
}
SelectKeyMeta 描述 MyBatis 风格 selectKey 主键生成语句。
type SelectKeyOrder ¶
type SelectKeyOrder string
SelectKeyOrder 表示 selectKey 的执行时机。
const ( // SelectKeyOrderBefore 表示先生成主键再执行主写入语句。 SelectKeyOrderBefore SelectKeyOrder = "BEFORE" // SelectKeyOrderAfter 表示主写入语句执行后再查询生成主键。 SelectKeyOrderAfter SelectKeyOrder = "AFTER" )
type Service ¶
Service 提供 MyBatis-Plus IService 风格的实体服务层。
func NewService ¶
func NewService[T any, ID any](mapper *BaseMapper[T, ID]) (*Service[T, ID], error)
NewService 基于 BaseMapper 创建服务层实例。
func (*Service[T, ID]) BaseMapper ¶
func (s *Service[T, ID]) BaseMapper() *BaseMapper[T, ID]
BaseMapper 返回底层通用 Mapper。
func (*Service[T, ID]) ChainQuery ¶
func (s *Service[T, ID]) ChainQuery() *QueryChain[T, ID]
ChainQuery 创建链式查询。
func (*Service[T, ID]) ChainUpdate ¶
func (s *Service[T, ID]) ChainUpdate() *UpdateChain[T, ID]
ChainUpdate 创建链式更新。
func (*Service[T, ID]) CountByEntity ¶
CountByEntity 按实体非零字段统计记录数。
func (*Service[T, ID]) GetMap ¶
func (s *Service[T, ID]) GetMap(ctx context.Context, wrapper *QueryWrapper[T]) (map[string]any, error)
GetMap 按条件查询单条 map 结果。
func (*Service[T, ID]) GetMapOrFirst ¶
func (s *Service[T, ID]) GetMapOrFirst(ctx context.Context, wrapper *QueryWrapper[T]) (map[string]any, error)
GetMapOrFirst 按条件查询 map 结果,多行时返回第一行。
func (*Service[T, ID]) GetObjOrFirst ¶
GetObjOrFirst 按条件查询首列值,多行时返回第一行。
func (*Service[T, ID]) GetOne ¶
func (s *Service[T, ID]) GetOne(ctx context.Context, wrapper *QueryWrapper[T]) (*T, error)
GetOne 按条件查询单条实体。
func (*Service[T, ID]) GetOneOrFirst ¶
func (s *Service[T, ID]) GetOneOrFirst(ctx context.Context, wrapper *QueryWrapper[T]) (*T, error)
GetOneOrFirst 按条件查询单条实体,多行时返回第一行。
func (*Service[T, ID]) List ¶
func (s *Service[T, ID]) List(ctx context.Context, wrapper *QueryWrapper[T]) ([]T, error)
List 按条件查询实体列表。wrapper 为 nil 时查询全部记录。
func (*Service[T, ID]) ListByEntity ¶
ListByEntity 按实体非零字段查询实体列表。
func (*Service[T, ID]) ListMaps ¶
func (s *Service[T, ID]) ListMaps(ctx context.Context, wrapper *QueryWrapper[T]) ([]map[string]any, error)
ListMaps 按条件查询 map 列表。
func (*Service[T, ID]) Page ¶
func (s *Service[T, ID]) Page(ctx context.Context, page PageRequest, wrapper *QueryWrapper[T]) (Page[T], error)
Page 按条件分页查询实体列表。
func (*Service[T, ID]) PageMaps ¶
func (s *Service[T, ID]) PageMaps(ctx context.Context, page PageRequest, wrapper *QueryWrapper[T]) (Page[map[string]any], error)
PageMaps 按条件分页查询 map 结果。
func (*Service[T, ID]) RemoveBatchByIDs ¶
RemoveBatchByIDs 是 RemoveByIDs 的 MyBatis-Plus 命名别名。
func (*Service[T, ID]) RemoveByEntity ¶
RemoveByEntity 按实体非零字段删除实体。
func (*Service[T, ID]) RemoveByID ¶
RemoveByID 按主键删除实体。
func (*Service[T, ID]) RemoveByIDs ¶
RemoveByIDs 按主键集合删除实体。
func (*Service[T, ID]) RemoveByMap ¶
RemoveByMap 按列名 map 等值删除实体。
func (*Service[T, ID]) SaveBatchSize ¶
func (s *Service[T, ID]) SaveBatchSize(ctx context.Context, entities []T, batchSize int) (int64, error)
SaveBatchSize 按指定批量大小插入实体。
func (*Service[T, ID]) SaveOrUpdate ¶
SaveOrUpdate 根据主键零值选择插入或更新。
func (*Service[T, ID]) SaveOrUpdateBatch ¶
SaveOrUpdateBatch 按顺序批量保存或更新实体。
func (*Service[T, ID]) SaveOrUpdateBatchSize ¶
func (s *Service[T, ID]) SaveOrUpdateBatchSize(ctx context.Context, entities []T, batchSize int) (int64, error)
SaveOrUpdateBatchSize 按指定批量大小保存或更新实体。
func (*Service[T, ID]) Update ¶
func (s *Service[T, ID]) Update(ctx context.Context, entity *T, wrapper *QueryWrapper[T]) (int64, error)
Update 按实体和条件更新记录。
func (*Service[T, ID]) UpdateBatchByID ¶
UpdateBatchByID 按默认批量大小根据主键更新实体。
func (*Service[T, ID]) UpdateBatchByIDSize ¶
func (s *Service[T, ID]) UpdateBatchByIDSize(ctx context.Context, entities []T, batchSize int) (int64, error)
UpdateBatchByIDSize 按指定批量大小根据主键更新实体。
func (*Service[T, ID]) UpdateByID ¶
UpdateByID 按主键更新实体。
func (*Service[T, ID]) UpdateWithWrapper ¶
func (s *Service[T, ID]) UpdateWithWrapper(ctx context.Context, wrapper *UpdateWrapper[T]) (int64, error)
UpdateWithWrapper 按 UpdateWrapper 更新记录。
type Session ¶
type Session interface {
Query(ctx context.Context, statement string, args NamedArgs, dest any) error
QueryOne(ctx context.Context, statement string, args NamedArgs, dest any) error
Exec(ctx context.Context, statement string, args NamedArgs) (Result, error)
}
Session 是生成 Mapper 代码依赖的最小执行边界。
type SessionOpenFunc ¶
SessionOpenFunc 打开一个 ORM Session。
func (SessionOpenFunc) OpenSession ¶
func (f SessionOpenFunc) OpenSession() (Session, error)
OpenSession 执行函数式 Session 打开器。
type StatementCachePolicy ¶
type StatementCachePolicy string
StatementCachePolicy 描述 Statement 级缓存策略。
const ( // StatementCacheDefault 表示使用 MyBatis 风格默认缓存策略。 StatementCacheDefault StatementCachePolicy = "" // StatementCacheEnabled 表示显式启用缓存行为。 StatementCacheEnabled StatementCachePolicy = "enabled" // StatementCacheDisabled 表示显式禁用缓存行为。 StatementCacheDisabled StatementCachePolicy = "disabled" )
type StatementCallSession ¶
type StatementCallSession interface {
CallStatement(ctx context.Context, statement StatementMeta, args NamedArgs, resultSets ...any) (CallResult, error)
}
StatementCallSession 描述支持直接执行 StatementMeta 调用的 Session。
type StatementCommand ¶
type StatementCommand string
StatementCommand 表示 SQL 语句命令类型。
const ( // StatementCommandSelect 表示查询语句。 StatementCommandSelect StatementCommand = "select" // StatementCommandInsert 表示插入语句。 StatementCommandInsert StatementCommand = "insert" // StatementCommandUpdate 表示更新语句。 StatementCommandUpdate StatementCommand = "update" // StatementCommandDelete 表示删除语句。 StatementCommandDelete StatementCommand = "delete" // StatementCommandCall 表示存储过程或可调用语句。 StatementCommandCall StatementCommand = "call" )
type StatementExecutor ¶
type StatementExecutor interface {
Query(ctx context.Context, session *SQLSession, meta StatementMeta, args NamedArgs, dest any) error
QueryOne(ctx context.Context, session *SQLSession, meta StatementMeta, args NamedArgs, dest any) error
Exec(ctx context.Context, session *SQLSession, meta StatementMeta, args NamedArgs) (Result, error)
}
StatementExecutor 承担 Mapper Statement 的最终执行调度。
type StatementExecutorMiddleware ¶
type StatementExecutorMiddleware interface {
WrapStatementExecutor(next StatementExecutor) StatementExecutor
}
StatementExecutorMiddleware 包装最终执行器,用于扩展 Query、QueryOne 和 Exec 层。
type StatementExecutorMiddlewareFunc ¶
type StatementExecutorMiddlewareFunc func(next StatementExecutor) StatementExecutor
StatementExecutorMiddlewareFunc 将函数适配为 StatementExecutorMiddleware。
func (StatementExecutorMiddlewareFunc) WrapStatementExecutor ¶
func (f StatementExecutorMiddlewareFunc) WrapStatementExecutor(next StatementExecutor) StatementExecutor
WrapStatementExecutor 执行函数式执行器包装。
type StatementHandler ¶
type StatementHandler interface {
Prepare(ctx context.Context, meta StatementMeta, args NamedArgs) (*StatementRuntime, error)
Compile(ctx context.Context, runtime *StatementRuntime) (CompiledSQL, error)
CompileText(ctx context.Context, meta StatementMeta, dialect Dialect, sqlText string, args NamedArgs) (CompiledSQL, error)
}
StatementHandler 负责动态 SQL、拦截器和方言占位符编译。
type StatementHandlerMiddleware ¶
type StatementHandlerMiddleware interface {
WrapStatementHandler(next StatementHandler) StatementHandler
}
StatementHandlerMiddleware 包装语句处理器,用于扩展动态 SQL、拦截器和占位符编译层。
type StatementHandlerMiddlewareFunc ¶
type StatementHandlerMiddlewareFunc func(next StatementHandler) StatementHandler
StatementHandlerMiddlewareFunc 将函数适配为 StatementHandlerMiddleware。
func (StatementHandlerMiddlewareFunc) WrapStatementHandler ¶
func (f StatementHandlerMiddlewareFunc) WrapStatementHandler(next StatementHandler) StatementHandler
WrapStatementHandler 执行函数式语句处理器包装。
type StatementInterceptor ¶
type StatementInterceptor interface {
Intercept(ctx context.Context, invocation *StatementInvocation) error
}
StatementInterceptor 拦截并改写一次 Statement 执行。
func NewBlockAttackInterceptor ¶
func NewBlockAttackInterceptor() StatementInterceptor
NewBlockAttackInterceptor 创建全表更新/删除拦截器。
func NewDataPermissionInterceptor ¶
func NewDataPermissionInterceptor(provider DataPermissionProvider) StatementInterceptor
NewDataPermissionInterceptor 创建数据权限条件注入拦截器。
func NewDynamicTableInterceptor ¶
func NewDynamicTableInterceptor(tables map[string]string) StatementInterceptor
NewDynamicTableInterceptor 创建动态表名拦截器。
func NewEntitySemanticInterceptor ¶
func NewEntitySemanticInterceptor(registry *Registry, options ...EntitySemanticInterceptorOption) StatementInterceptor
NewEntitySemanticInterceptor 创建实体语义拦截器。
func NewIllegalSQLInterceptor ¶
func NewIllegalSQLInterceptor(options ...IllegalSQLOption) StatementInterceptor
NewIllegalSQLInterceptor 创建非法 SQL 治理拦截器。
func NewPaginationInterceptor ¶
func NewPaginationInterceptor() StatementInterceptor
NewPaginationInterceptor 创建分页拦截器。
func NewReadOnlyInterceptor ¶
func NewReadOnlyInterceptor() StatementInterceptor
NewReadOnlyInterceptor 创建只读治理拦截器。
func NewSQLGuardInterceptor ¶
func NewSQLGuardInterceptor(rules ...SQLGuardRule) StatementInterceptor
NewSQLGuardInterceptor 创建通用 SQL 治理拦截器。
func NewSQLObserverInterceptor ¶
func NewSQLObserverInterceptor(observe func(context.Context, SQLObservation) error) StatementInterceptor
NewSQLObserverInterceptor 创建 SQL 模板观察拦截器。
func NewTenantInterceptor ¶
func NewTenantInterceptor(column string, value any) StatementInterceptor
NewTenantInterceptor 创建多租户条件注入拦截器。
type StatementInterceptorFunc ¶
type StatementInterceptorFunc func(ctx context.Context, invocation *StatementInvocation) error
StatementInterceptorFunc 将函数适配为 StatementInterceptor。
func (StatementInterceptorFunc) Intercept ¶
func (f StatementInterceptorFunc) Intercept(ctx context.Context, invocation *StatementInvocation) error
Intercept 执行函数式拦截器。
type StatementInvocation ¶
type StatementInvocation struct {
// contains filtered or unexported fields
}
StatementInvocation 维护拦截器链的执行游标。
func (*StatementInvocation) Proceed ¶
func (i *StatementInvocation) Proceed(ctx context.Context) error
Proceed 执行链上的下一个拦截器。
func (*StatementInvocation) Statement ¶
func (i *StatementInvocation) Statement() *StatementRuntime
Statement 返回当前可变 SQL 模板。
type StatementMeta ¶
type StatementMeta struct {
ID string
Namespace string
FullName string
Command StatementCommand
StatementType StatementType
Source StatementSource
SQL string
Provider string
ResultMap string
ResultType string
ParameterType string
DatabaseID string
UseGeneratedKeys bool
KeyProperty string
Options StatementOptions
SelectKey SelectKeyMeta
UseCache StatementCachePolicy
FlushCache StatementCachePolicy
Parameters []string
ParameterModes []ParameterMeta
ResultSets []ResultSetMeta
DynamicSQL []DynamicSQLNode
InterceptorIgnores []string
}
StatementMeta 描述已经编译好的 Mapper 语句元数据。
type StatementNotFoundError ¶
StatementNotFoundError 表示指定 Statement 或 SQL Provider 没有注册。
func (*StatementNotFoundError) Error ¶
func (e *StatementNotFoundError) Error() string
func (*StatementNotFoundError) Is ¶
func (e *StatementNotFoundError) Is(target error) bool
func (*StatementNotFoundError) Unwrap ¶
func (e *StatementNotFoundError) Unwrap() error
type StatementOptions ¶
type StatementOptions struct {
Timeout time.Duration
FetchSize int
ResultSetType ResultSetType
ResultOrdered bool
KeyColumn string
}
StatementOptions 描述 MyBatis 风格的语句级执行选项。
type StatementRuntime ¶
type StatementRuntime struct {
Meta StatementMeta
SQL string
Args NamedArgs
Dialect Dialect
Configuration Configuration
}
StatementRuntime 描述一次执行中的可变 SQL 模板。
type StatementSession ¶
type StatementSession interface {
QueryStatement(ctx context.Context, statement StatementMeta, args NamedArgs, dest any) error
QueryOneStatement(ctx context.Context, statement StatementMeta, args NamedArgs, dest any) error
ExecStatement(ctx context.Context, statement StatementMeta, args NamedArgs) (Result, error)
}
StatementSession 执行已经构造好的 StatementMeta。
type StatementSource ¶
type StatementSource string
StatementSource 表示 SQL 语句来源。
const ( // StatementSourceXML 表示语句来源于 Mapper XML。 StatementSourceXML StatementSource = "xml" // StatementSourceAnnotation 表示语句来源于方法注解。 StatementSourceAnnotation StatementSource = "annotation" // StatementSourceBase 表示语句来源于通用 BaseMapper。 StatementSourceBase StatementSource = "base" )
type StatementType ¶
type StatementType string
StatementType 表示 Statement 的底层执行形态。
const ( // StatementTypePrepared 表示普通预编译 SQL 语句。 StatementTypePrepared StatementType = "PREPARED" // StatementTypeCallable 表示数据库存储过程或 callable statement。 StatementTypeCallable StatementType = "CALLABLE" )
type TooManyResultsError ¶
type TooManyResultsError struct {
Statement string
Expected int
Actual int
Message string
Err error
}
TooManyResultsError 表示单行查询返回了超过一行结果。
func (*TooManyResultsError) Error ¶
func (e *TooManyResultsError) Error() string
func (*TooManyResultsError) Is ¶
func (e *TooManyResultsError) Is(target error) bool
func (*TooManyResultsError) Unwrap ¶
func (e *TooManyResultsError) Unwrap() error
type Transaction ¶
type Transaction interface {
Executor() SQLExecutor
Commit() error
Rollback() error
}
Transaction 描述 ORM 自身独立事务抽象。
type TransactionFactory ¶
type TransactionFactory interface {
Begin(ctx context.Context, source TransactionSource, opts *sql.TxOptions) (Transaction, error)
}
TransactionFactory 创建事务实例。
type TransactionSource ¶
type TransactionSource interface {
BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
}
TransactionSource 是可以开启 database/sql 事务的最小边界。
type TxSession ¶
type TxSession struct {
// contains filtered or unexported fields
}
TxSession 是绑定单个事务的 Session。
func (*TxSession) Call ¶
func (s *TxSession) Call(ctx context.Context, statement string, args NamedArgs, resultSets ...any) (CallResult, error)
Call 执行事务内存储过程调用。
func (*TxSession) CallStatement ¶
func (s *TxSession) CallStatement(ctx context.Context, statement StatementMeta, args NamedArgs, resultSets ...any) (CallResult, error)
CallStatement 执行事务内 StatementMeta 存储过程调用。
func (*TxSession) ExecStatement ¶
func (s *TxSession) ExecStatement(ctx context.Context, statement StatementMeta, args NamedArgs) (Result, error)
ExecStatement 执行事务内写入语句元数据。
func (*TxSession) QueryCursor ¶
func (*TxSession) QueryOneStatement ¶
func (s *TxSession) QueryOneStatement(ctx context.Context, statement StatementMeta, args NamedArgs, dest any) error
QueryOneStatement 执行事务内查询语句元数据并要求最多返回一行。
func (*TxSession) QueryPage ¶
func (s *TxSession) QueryPage(ctx context.Context, statement string, args NamedArgs, page PageRequest, dest any) (PageQueryResult, error)
QueryPage 执行事务内分页查询。
func (*TxSession) QueryStatement ¶
func (s *TxSession) QueryStatement(ctx context.Context, statement StatementMeta, args NamedArgs, dest any) error
QueryStatement 执行事务内查询语句元数据并扫描多行结果。
type TypeHandler ¶
type TypeHandler interface {
ToDB(ctx context.Context, value any) (any, error)
FromDB(ctx context.Context, value any, target any) error
}
TypeHandler 负责 Go 值与数据库值之间的双向转换。
func NewDecimalTypeHandler ¶
func NewDecimalTypeHandler() TypeHandler
NewDecimalTypeHandler 创建无外部依赖的 Decimal 字段转换器。
func NewStringTypeHandler ¶
func NewStringTypeHandler() TypeHandler
NewStringTypeHandler 创建字符串字段转换器。
type TypeHandlerAdapter ¶
type TypeHandlerAdapter struct {
ToDBFunc func(context.Context, any) (any, error)
FromDBFunc func(context.Context, any, any) error
}
TypeHandlerAdapter 用函数适配自定义 TypeHandler。
type TypedField ¶
TypedField 描述带 Go 值类型的实体字段。
func NewTypedField ¶
func NewTypedField[T any, V any](column string) TypedField[T, V]
NewTypedField 创建带值类型约束的实体字段描述。
type TypedFieldRef ¶
TypedFieldRef 是可转换为普通字段的类型化字段引用。
type UpdateChain ¶
UpdateChain 提供 MyBatis-Plus UpdateChainWrapper 风格的更新链。
func (*UpdateChain[T, ID]) Eq ¶
func (c *UpdateChain[T, ID]) Eq(field Field[T], value any) *UpdateChain[T, ID]
Eq 添加等值条件。
func (*UpdateChain[T, ID]) Set ¶
func (c *UpdateChain[T, ID]) Set(field Field[T], value any) *UpdateChain[T, ID]
Set 添加字段赋值。
func (*UpdateChain[T, ID]) SetDecrBy ¶
func (c *UpdateChain[T, ID]) SetDecrBy(field Field[T], value any) *UpdateChain[T, ID]
SetDecrBy 添加字段自减赋值。
func (*UpdateChain[T, ID]) SetIncrBy ¶
func (c *UpdateChain[T, ID]) SetIncrBy(field Field[T], value any) *UpdateChain[T, ID]
SetIncrBy 添加字段自增赋值。
func (*UpdateChain[T, ID]) Update ¶
func (c *UpdateChain[T, ID]) Update(ctx context.Context) (int64, error)
Update 执行链式更新。
func (*UpdateChain[T, ID]) Where ¶
func (c *UpdateChain[T, ID]) Where(apply func(*UpdateWrapper[T])) *UpdateChain[T, ID]
Where 使用底层 UpdateWrapper 添加复杂条件。
func (*UpdateChain[T, ID]) Wrapper ¶
func (c *UpdateChain[T, ID]) Wrapper() *UpdateWrapper[T]
Wrapper 返回底层更新 Wrapper。
type UpdateWrapper ¶
type UpdateWrapper[T any] struct { // contains filtered or unexported fields }
UpdateWrapper 是 MyBatis-Plus UpdateWrapper 的 Go 化更新构造器。
func SetDecrByTypedValue ¶
func SetDecrByTypedValue[T any, V any](w *UpdateWrapper[T], field TypedField[T, V], value V) *UpdateWrapper[T]
SetDecrByTypedValue 用泛型函数保留字段值类型约束并添加字段自减 SET 片段。
func SetDecrByTypedValueIf ¶
func SetDecrByTypedValueIf[T any, V any](condition bool, w *UpdateWrapper[T], field TypedField[T, V], value V) *UpdateWrapper[T]
SetDecrByTypedValueIf 在 condition 为 true 时添加类型安全的字段自减 SET 片段。
func SetIncrByTypedValue ¶
func SetIncrByTypedValue[T any, V any](w *UpdateWrapper[T], field TypedField[T, V], value V) *UpdateWrapper[T]
SetIncrByTypedValue 用泛型函数保留字段值类型约束并添加字段自增 SET 片段。
func SetIncrByTypedValueIf ¶
func SetIncrByTypedValueIf[T any, V any](condition bool, w *UpdateWrapper[T], field TypedField[T, V], value V) *UpdateWrapper[T]
SetIncrByTypedValueIf 在 condition 为 true 时添加类型安全的字段自增 SET 片段。
func SetTypedValue ¶
func SetTypedValue[T any, V any](w *UpdateWrapper[T], field TypedField[T, V], value V) *UpdateWrapper[T]
SetTypedValue 用泛型函数保留字段值类型约束。
func SetTypedValueIf ¶
func SetTypedValueIf[T any, V any](condition bool, w *UpdateWrapper[T], field TypedField[T, V], value V) *UpdateWrapper[T]
SetTypedValueIf 在 condition 为 true 时添加类型安全的字段赋值。
func (*UpdateWrapper[T]) And ¶
func (w *UpdateWrapper[T]) And(apply func(*UpdateWrapper[T])) *UpdateWrapper[T]
And 添加 AND 连接的嵌套条件组。
func (*UpdateWrapper[T]) Apply ¶
func (w *UpdateWrapper[T]) Apply(sqlText string, args NamedArgs) *UpdateWrapper[T]
Apply 添加自定义条件片段,SQL 仅允许 #{name} 参数占位符。
func (*UpdateWrapper[T]) Between ¶
func (w *UpdateWrapper[T]) Between(field Field[T], left any, right any) *UpdateWrapper[T]
Between 添加 BETWEEN 条件。
func (*UpdateWrapper[T]) BetweenTyped ¶
func (w *UpdateWrapper[T]) BetweenTyped(field TypedFieldRef[T], left any, right any) *UpdateWrapper[T]
BetweenTyped 添加类型化字段引用的 BETWEEN 条件。
func (*UpdateWrapper[T]) Eq ¶
func (w *UpdateWrapper[T]) Eq(field Field[T], value any) *UpdateWrapper[T]
Eq 添加等值条件。
func (*UpdateWrapper[T]) EqIf ¶
func (w *UpdateWrapper[T]) EqIf(condition bool, field Field[T], value any) *UpdateWrapper[T]
EqIf 在 condition 为 true 时添加等值条件。
func (*UpdateWrapper[T]) EqTyped ¶
func (w *UpdateWrapper[T]) EqTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
EqTyped 添加类型化字段引用的等值条件。
func (*UpdateWrapper[T]) Exists ¶
func (w *UpdateWrapper[T]) Exists(sqlText string, args NamedArgs) *UpdateWrapper[T]
Exists 添加 EXISTS 子查询条件,SQL 仅允许 #{name} 参数占位符。
func (*UpdateWrapper[T]) Ge ¶
func (w *UpdateWrapper[T]) Ge(field Field[T], value any) *UpdateWrapper[T]
Ge 添加大于等于条件。
func (*UpdateWrapper[T]) GeTyped ¶
func (w *UpdateWrapper[T]) GeTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
GeTyped 添加类型化字段引用的大于等于条件。
func (*UpdateWrapper[T]) Gt ¶
func (w *UpdateWrapper[T]) Gt(field Field[T], value any) *UpdateWrapper[T]
Gt 添加大于条件。
func (*UpdateWrapper[T]) GtTyped ¶
func (w *UpdateWrapper[T]) GtTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
GtTyped 添加类型化字段引用的大于条件。
func (*UpdateWrapper[T]) In ¶
func (w *UpdateWrapper[T]) In(field Field[T], values any) *UpdateWrapper[T]
In 添加 IN 条件。空集合会渲染为 1 = 0,避免意外全量命中。
func (*UpdateWrapper[T]) InTyped ¶
func (w *UpdateWrapper[T]) InTyped(field TypedFieldRef[T], values any) *UpdateWrapper[T]
InTyped 添加类型化字段引用的 IN 条件。
func (*UpdateWrapper[T]) IsNotNull ¶
func (w *UpdateWrapper[T]) IsNotNull(field Field[T]) *UpdateWrapper[T]
IsNotNull 添加 IS NOT NULL 条件。
func (*UpdateWrapper[T]) IsNotNullTyped ¶
func (w *UpdateWrapper[T]) IsNotNullTyped(field TypedFieldRef[T]) *UpdateWrapper[T]
IsNotNullTyped 添加类型化字段引用的 IS NOT NULL 条件。
func (*UpdateWrapper[T]) IsNull ¶
func (w *UpdateWrapper[T]) IsNull(field Field[T]) *UpdateWrapper[T]
IsNull 添加 IS NULL 条件。
func (*UpdateWrapper[T]) IsNullTyped ¶
func (w *UpdateWrapper[T]) IsNullTyped(field TypedFieldRef[T]) *UpdateWrapper[T]
IsNullTyped 添加类型化字段引用的 IS NULL 条件。
func (*UpdateWrapper[T]) Last ¶
func (w *UpdateWrapper[T]) Last(sqlText string) *UpdateWrapper[T]
Last 添加 SQL 尾部片段,例如 RETURNING id。尾部不支持参数绑定。
func (*UpdateWrapper[T]) Le ¶
func (w *UpdateWrapper[T]) Le(field Field[T], value any) *UpdateWrapper[T]
Le 添加小于等于条件。
func (*UpdateWrapper[T]) LeTyped ¶
func (w *UpdateWrapper[T]) LeTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
LeTyped 添加类型化字段引用的小于等于条件。
func (*UpdateWrapper[T]) Like ¶
func (w *UpdateWrapper[T]) Like(field Field[T], value any) *UpdateWrapper[T]
Like 添加 LIKE 条件,通配符由调用方显式传入。
func (*UpdateWrapper[T]) LikeLeft ¶
func (w *UpdateWrapper[T]) LikeLeft(field Field[T], value any) *UpdateWrapper[T]
LikeLeft 添加左侧模糊匹配条件。
func (*UpdateWrapper[T]) LikeLeftTyped ¶
func (w *UpdateWrapper[T]) LikeLeftTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
LikeLeftTyped 添加类型化字段引用的左侧模糊匹配条件。
func (*UpdateWrapper[T]) LikeRight ¶
func (w *UpdateWrapper[T]) LikeRight(field Field[T], value any) *UpdateWrapper[T]
LikeRight 添加右侧模糊匹配条件。
func (*UpdateWrapper[T]) LikeRightTyped ¶
func (w *UpdateWrapper[T]) LikeRightTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
LikeRightTyped 添加类型化字段引用的右侧模糊匹配条件。
func (*UpdateWrapper[T]) LikeTyped ¶
func (w *UpdateWrapper[T]) LikeTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
LikeTyped 添加类型化字段引用的 LIKE 条件。
func (*UpdateWrapper[T]) Lt ¶
func (w *UpdateWrapper[T]) Lt(field Field[T], value any) *UpdateWrapper[T]
Lt 添加小于条件。
func (*UpdateWrapper[T]) LtTyped ¶
func (w *UpdateWrapper[T]) LtTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
LtTyped 添加类型化字段引用的小于条件。
func (*UpdateWrapper[T]) Ne ¶
func (w *UpdateWrapper[T]) Ne(field Field[T], value any) *UpdateWrapper[T]
Ne 添加不等条件。
func (*UpdateWrapper[T]) NeTyped ¶
func (w *UpdateWrapper[T]) NeTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
NeTyped 添加类型化字段引用的不等条件。
func (*UpdateWrapper[T]) Nested ¶
func (w *UpdateWrapper[T]) Nested(apply func(*UpdateWrapper[T])) *UpdateWrapper[T]
Nested 添加默认 AND 连接的嵌套条件组。
func (*UpdateWrapper[T]) NotBetween ¶
func (w *UpdateWrapper[T]) NotBetween(field Field[T], left any, right any) *UpdateWrapper[T]
NotBetween 添加 NOT BETWEEN 条件。
func (*UpdateWrapper[T]) NotBetweenTyped ¶
func (w *UpdateWrapper[T]) NotBetweenTyped(field TypedFieldRef[T], left any, right any) *UpdateWrapper[T]
NotBetweenTyped 添加类型化字段引用的 NOT BETWEEN 条件。
func (*UpdateWrapper[T]) NotExists ¶
func (w *UpdateWrapper[T]) NotExists(sqlText string, args NamedArgs) *UpdateWrapper[T]
NotExists 添加 NOT EXISTS 子查询条件,SQL 仅允许 #{name} 参数占位符。
func (*UpdateWrapper[T]) NotIn ¶
func (w *UpdateWrapper[T]) NotIn(field Field[T], values any) *UpdateWrapper[T]
NotIn 添加 NOT IN 条件。空集合会渲染为 1 = 0,避免写操作意外放大。
func (*UpdateWrapper[T]) NotInTyped ¶
func (w *UpdateWrapper[T]) NotInTyped(field TypedFieldRef[T], values any) *UpdateWrapper[T]
NotInTyped 添加类型化字段引用的 NOT IN 条件。
func (*UpdateWrapper[T]) NotLike ¶
func (w *UpdateWrapper[T]) NotLike(field Field[T], value any) *UpdateWrapper[T]
NotLike 添加 NOT LIKE 条件。
func (*UpdateWrapper[T]) NotLikeTyped ¶
func (w *UpdateWrapper[T]) NotLikeTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
NotLikeTyped 添加类型化字段引用的 NOT LIKE 条件。
func (*UpdateWrapper[T]) Or ¶
func (w *UpdateWrapper[T]) Or(apply func(*UpdateWrapper[T])) *UpdateWrapper[T]
Or 添加 OR 连接的嵌套条件组。
func (*UpdateWrapper[T]) Set ¶
func (w *UpdateWrapper[T]) Set(field Field[T], value any) *UpdateWrapper[T]
Set 添加字段赋值。
func (*UpdateWrapper[T]) SetDecrBy ¶
func (w *UpdateWrapper[T]) SetDecrBy(field Field[T], value any) *UpdateWrapper[T]
SetDecrBy 添加字段自减 SET 片段。
func (*UpdateWrapper[T]) SetDecrByTyped ¶
func (w *UpdateWrapper[T]) SetDecrByTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
SetDecrByTyped 添加类型化字段引用的字段自减 SET 片段。
func (*UpdateWrapper[T]) SetEmpty ¶
func (w *UpdateWrapper[T]) SetEmpty() bool
SetEmpty 返回是否没有任何更新字段。
func (*UpdateWrapper[T]) SetIf ¶
func (w *UpdateWrapper[T]) SetIf(condition bool, field Field[T], value any) *UpdateWrapper[T]
SetIf 在 condition 为 true 时添加字段赋值。
func (*UpdateWrapper[T]) SetIncrBy ¶
func (w *UpdateWrapper[T]) SetIncrBy(field Field[T], value any) *UpdateWrapper[T]
SetIncrBy 添加字段自增 SET 片段。
func (*UpdateWrapper[T]) SetIncrByTyped ¶
func (w *UpdateWrapper[T]) SetIncrByTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
SetIncrByTyped 添加类型化字段引用的字段自增 SET 片段。
func (*UpdateWrapper[T]) SetSQL ¶
func (w *UpdateWrapper[T]) SetSQL(sqlText string, args NamedArgs) *UpdateWrapper[T]
SetSQL 添加安全的原生 SET 片段,SQL 仅允许 #{name} 参数占位符。
func (*UpdateWrapper[T]) SetTyped ¶
func (w *UpdateWrapper[T]) SetTyped(field TypedFieldRef[T], value any) *UpdateWrapper[T]
SetTyped 添加类型化字段引用的字段赋值。
func (*UpdateWrapper[T]) SetTypedIf ¶
func (w *UpdateWrapper[T]) SetTypedIf(condition bool, field TypedFieldRef[T], value any) *UpdateWrapper[T]
SetTypedIf 在 condition 为 true 时添加类型化字段引用的字段赋值。
func (*UpdateWrapper[T]) When ¶
func (w *UpdateWrapper[T]) When(condition bool, apply func(*UpdateWrapper[T])) *UpdateWrapper[T]
When 在 condition 为 true 时应用构造逻辑。
Source Files
¶
- base_mapper.go
- base_mapper_batch.go
- base_mapper_map.go
- batch.go
- blocking_cache.go
- cache.go
- call.go
- compatibility.go
- configuration.go
- db.go
- dialect.go
- dialect_capabilities.go
- discriminator.go
- doc.go
- dynamic.go
- entity_condition.go
- entity_interceptor.go
- enum.go
- errors.go
- executor.go
- expression.go
- field_strategy.go
- field_strategy_runtime.go
- global_config.go
- handler_middleware.go
- identifier_generator.go
- interceptor.go
- interceptor_ignore.go
- key_generator.go
- lazy.go
- local_cache.go
- meta_object_handler.go
- metadata.go
- mybatis_config.go
- nested_select.go
- page.go
- page_session.go
- parameter_path.go
- prepared.go
- provider.go
- raw_sql.go
- registry.go
- registry_typehandler.go
- resultmap_association_row_scanner.go
- resultmap_row_scanner.go
- resultmap_scan.go
- routing.go
- row_scanner.go
- scan_plan.go
- second_level_cache.go
- service.go
- session.go
- sql_governance.go
- sql_injector.go
- sqlsession.go
- sqlsession_typehandler.go
- statement.go
- statement_options.go
- statement_plan.go
- streaming.go
- transaction.go
- typed_wrapper.go
- typehandler.go
- typehandler_ext.go
- update_wrapper.go
- wrapper.go