Documentation
¶
Index ¶
- Constants
- Variables
- func ASC(field any) any
- func AutoMigrate(d def.DatabaseClient, model any, opts ...migrate.AutoMigrateOption) error
- func ConvertToCountSQL(sqlStr string) string
- func DESC(field any) any
- func DetectSQLType(sql string) string
- func EnsureDBExists(v *def.DBConnection) error
- func FlushTableInfoCache()
- func GetDBLogger() *cylog.Logger
- func InMapParam(ids map[string]struct{}) string
- func InParam(ids []string) string
- func InParam2(ids [][]string) string
- func LeafDirs(efs *embed.FS) ([]string, error)
- func NormalData(d any, props *CLiExtendProps) any
- func NormalData2(d any, props *CLiExtendProps) any
- func ParseCount(row map[string]any) int64
- func Q(options ...QueryOption) def.SQLStmt
- func SplitSQLStatements(dbtype, sql string) []string
- func ToColumn[T any](qr QueryResult, columnName string) ([]T, error)
- func ToMigrationTableInfo(t def.TableInfo, opts ...migrate.ToMigrationTableInfoOption) def.TableInfo
- func ToResult[T any](qr QueryResult, opts ...cystructmap.Option) (T, error)
- func ToResultEx[T any](qr QueryResult, transform def.ItemTransformFunc, opts ...cystructmap.Option) (T, error)
- func ToValue[T any](qr QueryResult, columnName string, rowIndex ...int) (T, error)
- func WithTransaction[T IRepo](repo T, fn func(T) error) (err error)
- func WithTransactions[T IRepo](repos []T, fn func([]T) error) (err error)
- type BooleanCondition
- type CLiExtendProps
- type CLiExtendPropsFunc
- type CRUDSqlFuncName
- type ColumnExpr
- type ComparisonCondition
- type Config
- type DBCli
- func (d *DBCli) AnalyzeSQL(sql string) (*def.SQLImpact, error)
- func (d *DBCli) BatchInsert(tableName string, data []map[string]any, cc ...def.QueryOption) (int64, error)
- func (d *DBCli) BatchInsertContext(ctx context.Context, tableName string, data []map[string]any, ...) (int64, error)
- func (d *DBCli) BatchReplace(tableName string, data []map[string]any, cc ...def.QueryOption) (int64, error)
- func (d *DBCli) BatchReplaceContext(ctx context.Context, tableName string, data []map[string]any, ...) (int64, error)
- func (d *DBCli) BatchUpdate(tableName string, data []map[string]any, cc ...def.QueryOption) (int64, error)
- func (d *DBCli) BatchUpdateContext(ctx context.Context, tableName string, data []map[string]any, ...) (int64, error)
- func (d *DBCli) BeginTx() (r *DBCli, err error)
- func (d *DBCli) BeginTxContext(ctx context.Context) (r *DBCli, err error)
- func (d *DBCli) Close() error
- func (d *DBCli) ColumnExists(tableName string, columnName string) (bool, error)
- func (d *DBCli) Commit() error
- func (d *DBCli) CompatCollation() bool
- func (d *DBCli) Count(tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)
- func (d *DBCli) CountContext(ctx context.Context, tableName string, data map[string]any, ...) (int64, error)
- func (d *DBCli) DBSubType() string
- func (d *DBCli) DBType() string
- func (d *DBCli) Database() string
- func (d *DBCli) Delete(tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)
- func (d *DBCli) DeleteContext(ctx context.Context, tableName string, data map[string]any, ...) (int64, error)
- func (d *DBCli) DirectExcute(sql string, arguments ...any) (int64, error)deprecated
- func (d *DBCli) DirectExecute(sql string, arguments ...any) (int64, error)
- func (d *DBCli) DirectExecuteContext(ctx context.Context, sql string, arguments ...any) (int64, error)
- func (d *DBCli) DirectForEachQuery(tableName string, selectSQL string, fn func(RowData) error) error
- func (d *DBCli) DirectNQuery(sql string, data any) ([]map[string]any, error)deprecated
- func (d *DBCli) DirectNQueryContext(ctx context.Context, sql string, data any) ([]map[string]any, error)deprecated
- func (d *DBCli) DirectNQueryRow(sql string, data any) (map[string]any, error)
- func (d *DBCli) DirectNQueryRowContext(ctx context.Context, sql string, data any) (map[string]any, error)
- func (d *DBCli) DirectNamedExecute(sql string, data any) (int64, error)
- func (d *DBCli) DirectNamedExecuteContext(ctx context.Context, sql string, data any) (int64, error)
- func (d *DBCli) DirectNamedForEachQuery(tableName string, selectSQL string, data any, fn func(RowData) error) error
- func (d *DBCli) DirectNamedForEachQueryContext(ctx context.Context, tableName string, selectSQL string, data any, ...) error
- func (d *DBCli) DirectNamedInsert(sql string, data any) (int64, error)
- func (d *DBCli) DirectNamedInsertContext(ctx context.Context, sql string, data any) (int64, error)
- func (d *DBCli) DirectNamedQuery(sql string, data any) ([]map[string]any, error)
- func (d *DBCli) DirectNamedQueryAsResult(sql string, params any) def.QueryResult
- func (d *DBCli) DirectNamedQueryAsResultContext(ctx context.Context, sql string, params any) def.QueryResult
- func (d *DBCli) DirectNamedQueryContext(ctx context.Context, sql string, data any) ([]map[string]any, error)
- func (d *DBCli) DirectNamedQueryFast(sql string, data any) ([][]any, []string, error)
- func (d *DBCli) DirectNamedQueryFastContext(ctx context.Context, sql string, data any) ([][]any, []string, error)
- func (d *DBCli) DirectNamedQueryRow(sql string, data any) (map[string]any, error)
- func (d *DBCli) DirectNamedQueryRowContext(ctx context.Context, sql string, data any) (map[string]any, error)
- func (d *DBCli) DirectNamedQueryRowFast(sql string, data any) ([]any, []string, error)
- func (d *DBCli) DirectNamedQueryRowFastContext(ctx context.Context, sql string, data any) ([]any, []string, error)
- func (d *DBCli) DirectNamedSelect(dest any, query string, arg any) error
- func (d *DBCli) DirectQuery(sql string, arguments ...any) ([]map[string]any, error)
- func (d *DBCli) DirectQueryContext(ctx context.Context, sql string, arguments ...any) ([]map[string]any, error)
- func (d *DBCli) DirectQueryFast(sql string, arguments ...any) ([][]any, []string, error)
- func (d *DBCli) DirectQueryFastContext(ctx context.Context, sql string, arguments ...any) ([][]any, []string, error)
- func (d *DBCli) DirectQueryRow(sql string, args ...any) (map[string]any, error)
- func (d *DBCli) DirectQueryRowContext(ctx context.Context, sql string, args ...any) (map[string]any, error)
- func (d *DBCli) DirectQueryRowFast(sql string, args ...any) ([]any, []string, error)
- func (d *DBCli) DirectQueryRowFastContext(ctx context.Context, sql string, args ...any) ([]any, []string, error)
- func (d *DBCli) EnsureDBExists(dbName string) error
- func (d *DBCli) EnsureLimit(sql string, limit, offset int) (string, error)
- func (d *DBCli) Excute(sql string, arguments ...any) (int64, error)deprecated
- func (d *DBCli) Execute(sql string, arguments ...any) (int64, error)
- func (d *DBCli) ExecuteContext(ctx context.Context, sql string, arguments ...any) (int64, error)
- func (d *DBCli) Exists(tableName string, data map[string]any, cc ...def.QueryOption) (bool, error)
- func (d *DBCli) ExistsContext(ctx context.Context, tableName string, data map[string]any, ...) (bool, error)
- func (d *DBCli) ExplainSQL(sql string) def.QueryResult
- func (d *DBCli) First(tableName string, data map[string]any, cc ...def.QueryOption) (map[string]any, error)
- func (d *DBCli) FirstAsResult(tableName any, data map[string]any, cc ...QueryOption) QueryResult
- func (d *DBCli) FirstAsResultContext(ctx context.Context, tableName any, data map[string]any, cc ...QueryOption) QueryResult
- func (d *DBCli) FirstContext(ctx context.Context, tableName string, data map[string]any, ...) (map[string]any, error)
- func (d *DBCli) ForEachData(tableName string, data []map[string]any, fn func(RowData) error) error
- func (d *DBCli) ForEachQuery(tableName string, selectSQL string, fn func(RowData) error) error
- func (d *DBCli) ForEachQueryByWhere(tableName string, where []def.QueryOption, p P, fn func(RowData) error) error
- func (d *DBCli) ForEachQueryContext(ctx context.Context, tableName string, selectSQL string, ...) error
- func (d *DBCli) Get(dest any, query string, args ...any) error
- func (d *DBCli) GetContext(ctx context.Context, dest any, query string, args ...any) error
- func (d *DBCli) GetDB() *sqlx.DB
- func (d *DBCli) GetDDLSql(funcName dialect.DDLSqlFuncName, name ...string) (*dialect.SqlContent, error)
- func (d *DBCli) GetDatabases() ([]string, error)
- func (d *DBCli) GetIndexes(tableName string) ([]dialect.IndexInfo, error)
- func (d *DBCli) GetObjects(dbName string, schema *string, objectType dialect.DatabaseObjectType) ([]string, error)
- func (d *DBCli) GetPassword() string
- func (d *DBCli) GetPrimaryKeys(tableName string) ([]string, error)
- func (d *DBCli) GetSortedSql(funcName dialect.SortFuncName, database string, names []string) ([]*dialect.SqlContent, error)
- func (d *DBCli) GetSqlTransformer() (DatabaseTransformer, bool)
- func (d *DBCli) GetTableInfo(tableName string) (TableInfo, error)
- func (d *DBCli) GetTables(dbName string, schema *string, keyword *string) ([]string, error)
- func (d *DBCli) GetUniqueKeys(tableName string) ([]string, error)
- func (d *DBCli) Insert(tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)
- func (d *DBCli) InsertAndGetID(tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)
- func (d *DBCli) InsertAndGetIDContext(ctx context.Context, tableName string, data map[string]any, ...) (int64, error)
- func (d *DBCli) InsertContext(ctx context.Context, tableName string, data map[string]any, ...) (int64, error)
- func (d *DBCli) IsTableExist(tableName string) (bool, error)
- func (d *DBCli) Key() string
- func (d *DBCli) List(tableName string, data map[string]any, cc ...def.QueryOption) ([]map[string]any, error)
- func (d *DBCli) ListAsResult(tableName any, data map[string]any, cc ...QueryOption) QueryResult
- func (d *DBCli) ListAsResultContext(ctx context.Context, tableName any, data map[string]any, cc ...QueryOption) QueryResult
- func (d *DBCli) ListContext(ctx context.Context, tableName string, data map[string]any, ...) ([]map[string]any, error)
- func (d *DBCli) ListWithPage(tableName string, data map[string]any, pageIndex int, pageSize int, ...) ([]map[string]any, int64, error)
- func (d *DBCli) ListWithPageAsResult(tableName any, data map[string]any, pageIndex int, pageSize int, ...) QueryResult
- func (d *DBCli) ListWithPageAsResultContext(ctx context.Context, tableName any, data map[string]any, pageIndex int, ...) QueryResult
- func (d *DBCli) ListWithPageContext(ctx context.Context, tableName string, data map[string]any, pageIndex int, ...) ([]map[string]any, int64, error)
- func (d *DBCli) NQuery(sql string, data any) ([]map[string]any, error)deprecated
- func (d *DBCli) NQueryContext(ctx context.Context, sql string, data any) ([]map[string]any, error)deprecated
- func (d *DBCli) NQueryRow(sql string, data any) (map[string]any, error)
- func (d *DBCli) NQueryRowContext(ctx context.Context, sql string, data any) (map[string]any, error)
- func (d *DBCli) NamedExecute(sql string, data any) (int64, error)
- func (d *DBCli) NamedExecuteContext(ctx context.Context, sql string, data any) (int64, error)
- func (d *DBCli) NamedForEachQuery(tableName string, selectSQL string, data any, fn func(RowData) error) error
- func (d *DBCli) NamedForEachQueryContext(ctx context.Context, tableName string, selectSQL string, data any, ...) error
- func (d *DBCli) NamedQuery(sql string, data any) ([]map[string]any, error)
- func (d *DBCli) NamedQueryAsResult(sql string, data any) QueryResult
- func (d *DBCli) NamedQueryAsResultContext(ctx context.Context, sql string, data any) QueryResult
- func (d *DBCli) NamedQueryContext(ctx context.Context, sql string, data any) ([]map[string]any, error)
- func (d *DBCli) NamedQueryFastContext(ctx context.Context, sql string, data any) ([][]any, []string, error)
- func (d *DBCli) NamedQueryRow(sql string, data any) (map[string]any, error)
- func (d *DBCli) NamedQueryRowAsResultContext(ctx context.Context, sql string, data any) QueryResult
- func (d *DBCli) NamedQueryRowContext(ctx context.Context, sql string, data any) (map[string]any, error)
- func (d *DBCli) NamedQueryRowFast(sql string, data any) ([]any, []string, error)
- func (d *DBCli) NamedQueryRowFastContext(ctx context.Context, sql string, data any) ([]any, []string, error)
- func (d *DBCli) ObjectExists(objectName string, objectType dialect.DatabaseObjectType) (bool, error)
- func (d *DBCli) PW() string
- func (d *DBCli) PaginatedList(tableName string, data map[string]any, pageIndex int, pageSize int, ...) ([]map[string]any, int64, error)
- func (d *DBCli) PaginatedListAsResult(tableName any, data map[string]any, pageIndex int, pageSize int, ...) QueryResult
- func (d *DBCli) PaginatedListAsResultContext(ctx context.Context, tableName any, data map[string]any, pageIndex int, ...) QueryResult
- func (d *DBCli) PaginatedListContext(ctx context.Context, tableName string, data map[string]any, pageIndex int, ...) ([]map[string]any, int64, error)
- func (d *DBCli) Query(sql string, arguments ...any) ([]map[string]any, error)
- func (d *DBCli) QueryAsResult(sql string, arguments ...any) QueryResult
- func (d *DBCli) QueryAsResultContext(ctx context.Context, sql string, arguments ...any) QueryResult
- func (d *DBCli) QueryContext(ctx context.Context, sql string, arguments ...any) ([]map[string]any, error)
- func (d *DBCli) QueryFast(sql string, arguments ...any) ([][]any, []string, error)
- func (d *DBCli) QueryFastContext(ctx context.Context, sql string, arguments ...any) ([][]any, []string, error)
- func (d *DBCli) QueryRow(sql string, args ...any) (map[string]any, error)
- func (d *DBCli) QueryRowAsResult(sql string, args ...any) QueryResult
- func (d *DBCli) QueryRowAsResultContext(ctx context.Context, sql string, args ...any) QueryResult
- func (d *DBCli) QueryRowContext(ctx context.Context, sql string, args ...any) (map[string]any, error)
- func (d *DBCli) QueryRowFast(sql string, args ...any) ([]any, []string, error)
- func (d *DBCli) QueryRowFastContext(ctx context.Context, sql string, args ...any) ([]any, []string, error)
- func (d *DBCli) QueryWithLimitContext(ctx context.Context, sql string, limit, offset int) ([][]any, []string, error)
- func (d *DBCli) ReadSQLFile(r io.Reader, callback dialect.FuncSQLStmtCallback, ...) error
- func (d *DBCli) Replace(tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)
- func (d *DBCli) ReplaceContext(ctx context.Context, tableName string, data map[string]any, ...) (int64, error)
- func (d *DBCli) Rollback() error
- func (d *DBCli) Select(dest any, query string, args ...any) error
- func (d *DBCli) SelectContext(ctx context.Context, dest any, query string, args ...any) error
- func (d *DBCli) Update(tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)
- func (d *DBCli) UpdateContext(ctx context.Context, tableName string, data map[string]any, ...) (int64, error)
- func (d *DBCli) Upsert(tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)
- func (d *DBCli) UpsertContext(ctx context.Context, tableName string, data map[string]any, ...) (int64, error)
- func (d *DBCli) ValidateSQL(sql string) *def.ValidationError
- func (d *DBCli) WithTransaction(fn func(tx DatabaseClient) error) (err error)
- func (d *DBCli) WithTransactionContext(ctx context.Context, fn func(tx DatabaseClient) error) (err error)
- type DBConnection
- type DBMgr
- func (s *DBMgr) CloseAll()
- func (s *DBMgr) Exist(key string) bool
- func (s *DBMgr) GetCli(key string) *DBCli
- func (s *DBMgr) GetDatebase() []string
- func (s *DBMgr) GetOrCreateCli(config any, extendProps ...CLiExtendPropsFunc) (*DBCli, error)
- func (s *DBMgr) InitByConfig(conf *def.Config, extendProps ...CLiExtendPropsFunc) error
- func (s *DBMgr) SetCli(key string, cli *DBCli)
- func (s *DBMgr) SetCliIfNotExists(key string, cli *DBCli)
- func (s *DBMgr) TestConnect(con *def.DBConnection) error
- type DDLSqlFuncName
- type DatabaseClient
- type DatabaseError
- type DatabaseObjectType
- type DatabaseTransformer
- type Expression
- type FieldData
- type IDBOperWrapper
- type IRepo
- type ItemTransformFunc
- type MigrateFileFunc
- type MigrateInfo
- type OP
- type Object
- type OrderBy
- type P
- type PARAMS
- type PaginatedResult
- type QueryMetadata
- type QueryOption
- func WithBeforeBuild(callback func(def.SQLStmt) error) QueryOption
- func WithBetween(field string, start, end any) QueryOption
- func WithContains(field string, value string) QueryOption
- func WithCount(field string) QueryOption
- func WithDistinct(distinct bool) QueryOption
- func WithEQ(field string, value ...any) QueryOption
- func WithEQs(field ...string) QueryOption
- func WithEndsWith(field string, value string) QueryOption
- func WithFields(fields ...any) QueryOption
- func WithGT(field string, value ...any) QueryOption
- func WithGTE(field string, value ...any) QueryOption
- func WithGTEs(field ...string) QueryOption
- func WithGTs(field ...string) QueryOption
- func WithGroupBy(columns ...any) QueryOption
- func WithISNOTNULL(field string) QueryOption
- func WithISNULL(field string) QueryOption
- func WithIn(field string, values []any) QueryOption
- func WithInSub(field string, subquery def.SQLStmt) QueryOption
- func WithInnerJoin(table any, on ...Where) QueryOption
- func WithJoin(table any, on ...Where) QueryOption
- func WithLT(field string, value ...any) QueryOption
- func WithLTE(field string, value ...any) QueryOption
- func WithLTEs(field ...string) QueryOption
- func WithLTs(field ...string) QueryOption
- func WithLeftJoin(table any, on ...Where) QueryOption
- func WithLike(field string, value string) QueryOption
- func WithLimit(limit int) QueryOption
- func WithNEQ(field string, value ...any) QueryOption
- func WithNEQs(field ...string) QueryOption
- func WithNotIn(field string, values []any) QueryOption
- func WithNotInSub(field string, subquery def.SQLStmt) QueryOption
- func WithOffset(offset int) QueryOption
- func WithOrderBy(orders ...any) QueryOption
- func WithOrderByAsc(orders ...any) QueryOption
- func WithOrderByDesc(orders ...any) QueryOption
- func WithRightJoin(table any, on ...Where) QueryOption
- func WithSelect(selects ...any) QueryOption
- func WithStartsWith(field string, value string) QueryOption
- func WithSubQueryValues(builder *ss.SQLStmt) QueryOption
- func WithTable(table any) QueryOption
- func WithUnion(stmt *ss.SQLStmt) QueryOption
- func WithUnionAll(stmt *ss.SQLStmt) QueryOption
- func WithUpdate(table any) QueryOption
- func WithUpdateExpr(assignments ...ss.Assignment) QueryOption
- func WithValues(data ...[]Expression) QueryOption
- func WithValuesAppend(data ...[]Expression) QueryOption
- func WithWhere(where ...Where) QueryOption
- func WithWhereAnd(where ...Where) QueryOption
- func WithWhereOr(where ...Where) QueryOption
- type QueryResult
- type RawCondition
- type RowData
- type SQLBlock
- type SQLBuilder
- type SQLImpact
- type SQLStmt
- type SortDirection
- type SortFuncName
- type TableInfo
- type ValidationError
- type Where
- func AND(c ...Where) Where
- func AllEQ(fields []string, values ...any) Where
- func AllGT(fields []string, values ...any) Where
- func AllGTE(fields []string, values ...any) Where
- func AllLT(fields []string, values ...any) Where
- func AllLTE(fields []string, values ...any) Where
- func AllNEQ(fields []string, values ...any) Where
- func AnyEQ(fields []string, values ...any) Where
- func AnyGT(fields []string, values ...any) Where
- func AnyGTE(fields []string, values ...any) Where
- func AnyLT(fields []string, values ...any) Where
- func AnyLTE(fields []string, values ...any) Where
- func AnyNEQ(fields []string, values ...any) Where
- func BETWEEN(field string, start, end any) Where
- func EQ(field any, v ...any) Where
- func GT(field any, v ...any) Where
- func GTE(field any, v ...any) Where
- func IN(field string, values ...any) Where
- func ISNOTNULL(field string) Where
- func ISNULL(field string) Where
- func IS_NOT_NULL(field string) Where
- func IS_NULL(field string) Where
- func LIKE(field string, value string, pt def.LikePatternType) Where
- func LIKEC(field string, value string) Where
- func LIKEL(field string, value string) Where
- func LIKEN(field string, value string) Where
- func LIKER(field string, value string) Where
- func LT(field any, v ...any) Where
- func LTE(field any, v ...any) Where
- func NEQ(field any, v ...any) Where
- func NOT_IN(field string, values ...any) Where
- func NOT_LIKE(field string, value string, pt def.LikePatternType) Where
- func NOT_LIKEC(field string, value string) Where
- func NOT_LIKEL(field string, value string) Where
- func NOT_LIKEN(field string, value string) Where
- func NOT_LIKER(field string, value string) Where
- func ON(left any, right any, op ...string) Where
- func OR(c ...Where) Where
- func TupleEQ(cols []string, vals ...any) Where
- func TupleGT(cols []string, vals ...any) Where
- func TupleGTE(cols []string, vals ...any) Where
- func TupleIN(cols []string, valsList [][]any) Where
- func TupleLT(cols []string, vals ...any) Where
- func TupleLTE(cols []string, vals ...any) Where
- func TupleNE(cols []string, vals ...any) Where
- func TupleNOTIN(cols []string, valsList [][]any) Where
- func WHERE(field string, value any, ops ...OP) Where
- type WhereOptionFunc
Constants ¶
const ( ErrCodeConnection = "CONNECTION_FAILED" ErrCodeQuery = "QUERY_FAILED" ErrCodeTransaction = "TRANSACTION_FAILED" ErrCodeConstraint = "CONSTRAINT_VIOLATION" ErrCodeNotFound = "NOT_FOUND" ErrCodeDuplicate = "DUPLICATE_KEY" ErrCodeTimeout = "TIMEOUT" ErrCodeInvalidParam = "INVALID_PARAMETER" ErrCodeUnsupported = "UNSUPPORTED_OPERATION" )
Common database error codes
Variables ¶
var NewDBCliMgr = NewSqlMgr
Functions ¶
func AutoMigrate ¶ added in v1.0.0
func AutoMigrate(d def.DatabaseClient, model any, opts ...migrate.AutoMigrateOption) error
func ConvertToCountSQL ¶ added in v1.0.0
func DetectSQLType ¶ added in v1.0.0
func EnsureDBExists ¶ added in v1.0.0
func EnsureDBExists(v *def.DBConnection) error
func FlushTableInfoCache ¶ added in v1.0.0
func FlushTableInfoCache()
FlushTableInfoCache 清空表结构元数据缓存(跨实例对比等需要强制重新读取的场景使用)
func GetDBLogger ¶ added in v1.0.0
func InMapParam ¶
func NormalData ¶
func NormalData(d any, props *CLiExtendProps) any
func NormalData2 ¶
func NormalData2(d any, props *CLiExtendProps) any
func ParseCount ¶ added in v1.0.0
func Q ¶ added in v1.0.0
func Q(options ...QueryOption) def.SQLStmt
func SplitSQLStatements ¶ added in v1.0.0
SplitSQLStatements 将完整的多语句 SQL 脚本按语句边界切分为单条语句(Navicat 式批量执行)。
dbtype 指定语句解析所用方言:复用 dialect.GetSqlDialect(dbtype).ReadSQLFile 的完整 语句解析链路(各方言已注入 WordCallback,正确处理字符串字面量、三种注释的跨行状态, 以及存储过程/触发器等多语句块的边界),而非另写状态机。
无法识别的 dbtype 会回退到基础 dialect.ReadSQLFile(按分号切分)。 返回的每条语句已 Trim 空白,空语句被过滤。
func ToColumn ¶ added in v1.0.0
func ToColumn[T any](qr QueryResult, columnName string) ([]T, error)
func ToMigrationTableInfo ¶ added in v1.0.0
func ToResult ¶ added in v1.0.0
func ToResult[T any](qr QueryResult, opts ...cystructmap.Option) (T, error)
func ToResultEx ¶ added in v1.0.0
func ToResultEx[T any](qr QueryResult, transform def.ItemTransformFunc, opts ...cystructmap.Option) (T, error)
func ToValue ¶ added in v1.0.0
func ToValue[T any](qr QueryResult, columnName string, rowIndex ...int) (T, error)
func WithTransaction ¶
WithTransaction 在单个 repo 上执行带事务的操作。 若 fn 返回 error 或发生 panic,事务将回滚;否则提交。
func WithTransactions ¶ added in v1.0.0
WithTransactions 在多个 repo 上分别开启本地事务并执行操作。 注意:
- 这不是分布式事务!各事务独立提交。
- 若任一事务提交失败,其余已成功提交的事务不会回滚(仅未提交的会回滚)。
- 适用于同一数据库的多 schema / 多连接池,或可容忍最终一致性的场景。
Types ¶
type BooleanCondition ¶ added in v1.0.0
type BooleanCondition = def.BooleanCondition
type CLiExtendProps ¶ added in v1.0.0
type CLiExtendPropsFunc ¶ added in v1.0.0
type CLiExtendPropsFunc func(props *CLiExtendProps)
func WithNumbersAsString ¶ added in v1.0.0
func WithNumbersAsString(asString bool) CLiExtendPropsFunc
func WithTimeFormat ¶ added in v1.0.0
func WithTimeFormat(format string) CLiExtendPropsFunc
type CRUDSqlFuncName ¶
type CRUDSqlFuncName = dialect.CRUDSqlFuncName
const ( FuncNameGetInsertSql CRUDSqlFuncName = dialect.FuncNameGetInsertSql FuncNameGetSelectSql CRUDSqlFuncName = dialect.FuncNameGetSelectSql FuncNameGetUpdateSql CRUDSqlFuncName = dialect.FuncNameGetUpdateSql FuncNameGetDeleteSql CRUDSqlFuncName = dialect.FuncNameGetDeleteSql FuncNameGetReplaceSql CRUDSqlFuncName = dialect.FuncNameGetReplaceSql )
type ColumnExpr ¶ added in v1.0.0
type ColumnExpr = def.ColumnExpr
type ComparisonCondition ¶ added in v1.0.0
type ComparisonCondition = def.ComparisonCondition
type DBCli ¶
type DBCli struct {
CLiExtendProps
// contains filtered or unexported fields
}
func NewDBCli ¶
func NewDBCli(cli IDBOperWrapper, dbtype, key, database, un, pw, dbSubType string) *DBCli
NewDBCli creates a new DBCli instance. This is useful for testing purposes.
func TryConnect ¶
func TryConnect(v *def.DBConnection, extendProps ...CLiExtendPropsFunc) (*DBCli, error)
func (*DBCli) AnalyzeSQL ¶ added in v1.0.0
func (*DBCli) BatchInsert ¶
func (*DBCli) BatchInsertContext ¶ added in v1.0.0
func (*DBCli) BatchReplace ¶
func (*DBCli) BatchReplaceContext ¶ added in v1.0.0
func (*DBCli) BatchUpdate ¶
func (*DBCli) BatchUpdateContext ¶ added in v1.0.0
func (*DBCli) BeginTxContext ¶ added in v1.0.0
func (*DBCli) ColumnExists ¶ added in v1.0.0
func (*DBCli) CompatCollation ¶ added in v1.0.0
CompatCollation 返回 MySQL 8.0→5.7 collation 兼容开关。
func (*DBCli) CountContext ¶ added in v1.0.0
func (*DBCli) DeleteContext ¶ added in v1.0.0
func (*DBCli) DirectExecute ¶ added in v1.0.0
func (*DBCli) DirectExecuteContext ¶ added in v1.0.0
func (*DBCli) DirectForEachQuery ¶ added in v1.0.0
func (*DBCli) DirectNQueryRow ¶ added in v1.0.0
func (*DBCli) DirectNQueryRowContext ¶ added in v1.0.0
func (*DBCli) DirectNamedExecute ¶ added in v1.0.0
func (*DBCli) DirectNamedExecuteContext ¶ added in v1.0.0
func (*DBCli) DirectNamedForEachQuery ¶ added in v1.0.0
func (*DBCli) DirectNamedForEachQueryContext ¶ added in v1.0.0
func (*DBCli) DirectNamedInsert ¶ added in v1.0.0
func (*DBCli) DirectNamedInsertContext ¶ added in v1.0.0
func (*DBCli) DirectNamedQuery ¶ added in v1.0.0
func (*DBCli) DirectNamedQueryAsResult ¶ added in v1.0.0
func (d *DBCli) DirectNamedQueryAsResult(sql string, params any) def.QueryResult
DirectNamedQueryAsResult implements def.DBExecutor.
func (*DBCli) DirectNamedQueryAsResultContext ¶ added in v1.0.0
func (d *DBCli) DirectNamedQueryAsResultContext(ctx context.Context, sql string, params any) def.QueryResult
DirectNamedQueryAsResultContext implements def.DBExecutor.
func (*DBCli) DirectNamedQueryContext ¶ added in v1.0.0
func (*DBCli) DirectNamedQueryFast ¶ added in v1.0.0
DirectNamedQueryFast returns results in efficient [][]any format for named queries
func (*DBCli) DirectNamedQueryFastContext ¶ added in v1.0.0
func (d *DBCli) DirectNamedQueryFastContext(ctx context.Context, sql string, data any) ([][]any, []string, error)
DirectNamedQueryFastContext returns results in efficient [][]any format for named queries with context support
func (*DBCli) DirectNamedQueryRow ¶ added in v1.0.0
func (*DBCli) DirectNamedQueryRowContext ¶ added in v1.0.0
func (*DBCli) DirectNamedQueryRowFast ¶ added in v1.0.0
DirectNamedQueryRowFast returns single row in efficient []any format for named queries
func (*DBCli) DirectNamedQueryRowFastContext ¶ added in v1.0.0
func (d *DBCli) DirectNamedQueryRowFastContext(ctx context.Context, sql string, data any) ([]any, []string, error)
DirectNamedQueryRowFastContext returns single row in efficient []any format for named queries with context support
func (*DBCli) DirectNamedSelect ¶ added in v1.0.0
func (*DBCli) DirectQuery ¶ added in v1.0.0
func (*DBCli) DirectQueryContext ¶ added in v1.0.0
func (*DBCli) DirectQueryFast ¶ added in v1.0.0
DirectQueryFast returns results in efficient [][]any format
func (*DBCli) DirectQueryFastContext ¶ added in v1.0.0
func (d *DBCli) DirectQueryFastContext(ctx context.Context, sql string, arguments ...any) ([][]any, []string, error)
DirectQueryFastContext returns results in efficient [][]any format with context support
func (*DBCli) DirectQueryRow ¶ added in v1.0.0
func (*DBCli) DirectQueryRowContext ¶ added in v1.0.0
func (*DBCli) DirectQueryRowFast ¶ added in v1.0.0
DirectQueryRowFast returns single row in efficient []any format
func (*DBCli) DirectQueryRowFastContext ¶ added in v1.0.0
func (d *DBCli) DirectQueryRowFastContext(ctx context.Context, sql string, args ...any) ([]any, []string, error)
DirectQueryRowFastContext returns single row in efficient []any format with context support
func (*DBCli) EnsureDBExists ¶ added in v1.0.0
func (*DBCli) EnsureLimit ¶ added in v1.0.0
EnsureLimit 为查询语句补齐 LIMIT 护栏(可选查询限制)。 采用「解析 → 判断 → 构造 → 执行」的正规链路:
- ParseMySQL 解析 AST;无法解析则原样返回(安全降级,交由数据库报错);
- 若 AST 已有 LimitClause → 原样返回(含 LIMIT 的语句由用户控制行数);
- 若语句类型不支持 LIMIT(SHOW/DESC/SET 等)→ 原样返回;
- 否则在 AST 上 SetLimitClause,再按当前数据库方言 BuildSQL 重构, 使 LIMIT/OFFSET 由底层按方言正确渲染(MySQL/PG 用 LIMIT,Oracle 用 ROWNUM)。
func (*DBCli) ExecuteContext ¶ added in v1.0.0
func (*DBCli) ExistsContext ¶ added in v1.0.0
func (*DBCli) ExplainSQL ¶ added in v1.0.0
func (d *DBCli) ExplainSQL(sql string) def.QueryResult
ExplainSQL returns execution plan wrapped in QueryResult with dialect-specific behavior
func (*DBCli) FirstAsResult ¶ added in v1.0.0
func (d *DBCli) FirstAsResult(tableName any, data map[string]any, cc ...QueryOption) QueryResult
FirstAsResult executes a query expected to return at most one row and returns QueryResult
func (*DBCli) FirstAsResultContext ¶ added in v1.0.0
func (d *DBCli) FirstAsResultContext(ctx context.Context, tableName any, data map[string]any, cc ...QueryOption) QueryResult
FirstAsResultContext executes a query expected to return at most one row with context and returns QueryResult
func (*DBCli) FirstContext ¶ added in v1.0.0
func (*DBCli) ForEachData ¶ added in v1.0.0
func (*DBCli) ForEachQuery ¶ added in v1.0.0
func (*DBCli) ForEachQueryByWhere ¶ added in v1.0.0
func (*DBCli) ForEachQueryContext ¶ added in v1.0.0
func (*DBCli) GetContext ¶ added in v1.0.0
func (*DBCli) GetDDLSql ¶
func (d *DBCli) GetDDLSql(funcName dialect.DDLSqlFuncName, name ...string) (*dialect.SqlContent, error)
func (*DBCli) GetDatabases ¶ added in v1.0.0
GetDatabases 返回数据库列表(通过 dialect 实现,屏蔽方言差异)。
func (*DBCli) GetIndexes ¶ added in v1.0.0
GetIndexes 返回表索引列表(通过 dialect 实现,屏蔽方言差异)。
func (*DBCli) GetObjects ¶ added in v1.0.0
func (d *DBCli) GetObjects(dbName string, schema *string, objectType dialect.DatabaseObjectType) ([]string, error)
GetObjects 枚举库/schema 内指定类型的对象名称列表(与 GetTables 对称的元数据能力)
func (*DBCli) GetPassword ¶ added in v1.0.0
func (*DBCli) GetPrimaryKeys ¶ added in v1.0.0
func (*DBCli) GetSortedSql ¶
func (d *DBCli) GetSortedSql(funcName dialect.SortFuncName, database string, names []string) ([]*dialect.SqlContent, error)
func (*DBCli) GetSqlTransformer ¶ added in v1.0.0
func (d *DBCli) GetSqlTransformer() (DatabaseTransformer, bool)
func (*DBCli) GetTableInfo ¶ added in v1.0.0
func (*DBCli) GetUniqueKeys ¶ added in v1.0.0
func (*DBCli) InsertAndGetID ¶ added in v1.0.0
func (*DBCli) InsertAndGetIDContext ¶ added in v1.0.0
func (*DBCli) InsertContext ¶ added in v1.0.0
func (*DBCli) List ¶
func (d *DBCli) List(tableName string, data map[string]any, cc ...def.QueryOption) ([]map[string]any, error)
List queries all matching rows from a table.
Parameters:
- tableName: table name to query
- data: named parameters for WHERE clause (can be nil or empty)
- cc: query options (WithWhere, WithOrderBy, WithLimit, etc.)
Examples:
// Query all
users, err := cli.List("users")
// With WHERE condition only
users, err := cli.List("users",
cydb.WithWhere(cydb.EQ("status", "active")),
)
// With complex conditions and params
users, err := cli.List("users",
map[string]any{"status": "active", "age": 18},
cydb.WithWhere(cydb.And(
cydb.EQ("status", "active"),
cydb.GT("age", 18),
)),
cydb.WithOrderBy("created_at DESC"),
cydb.WithLimit(10),
)
func (*DBCli) ListAsResult ¶ added in v1.0.0
func (d *DBCli) ListAsResult(tableName any, data map[string]any, cc ...QueryOption) QueryResult
ListAsResult executes a SELECT built by SQLBuilder and returns an efficient QueryResult
func (*DBCli) ListAsResultContext ¶ added in v1.0.0
func (d *DBCli) ListAsResultContext(ctx context.Context, tableName any, data map[string]any, cc ...QueryOption) QueryResult
ListAsResultContext executes a SELECT built by SQLBuilder with context and returns an efficient QueryResult
func (*DBCli) ListContext ¶ added in v1.0.0
func (*DBCli) ListWithPage ¶
func (*DBCli) ListWithPageAsResult ¶ added in v1.0.0
func (d *DBCli) ListWithPageAsResult(tableName any, data map[string]any, pageIndex int, pageSize int, cc ...QueryOption) QueryResult
ListWithPageAsResult returns paginated results wrapped in QueryResult
func (*DBCli) ListWithPageAsResultContext ¶ added in v1.0.0
func (d *DBCli) ListWithPageAsResultContext(ctx context.Context, tableName any, data map[string]any, pageIndex int, pageSize int, cc ...QueryOption) QueryResult
ListWithPageAsResultContext returns paginated results with context wrapped in QueryResult
func (*DBCli) ListWithPageContext ¶ added in v1.0.0
func (*DBCli) NQueryRowContext ¶ added in v1.0.0
func (*DBCli) NamedExecute ¶ added in v1.0.0
func (*DBCli) NamedExecuteContext ¶ added in v1.0.0
func (*DBCli) NamedForEachQuery ¶ added in v1.0.0
func (*DBCli) NamedForEachQueryContext ¶ added in v1.0.0
func (*DBCli) NamedQuery ¶ added in v1.0.0
NamedQuery and DirectNamedQuery are aliases of NQuery/DirectNQuery. Prefer these names for clarity; NQuery variants are kept for compatibility.
func (*DBCli) NamedQueryAsResult ¶ added in v1.0.0
func (d *DBCli) NamedQueryAsResult(sql string, data any) QueryResult
NamedQueryAsResult executes a named parameter query and returns results wrapped in QueryResult
func (*DBCli) NamedQueryAsResultContext ¶ added in v1.0.0
NamedQueryAsResultContext executes a named parameter query with context and returns results wrapped in QueryResult
func (*DBCli) NamedQueryContext ¶ added in v1.0.0
func (*DBCli) NamedQueryFastContext ¶ added in v1.0.0
func (d *DBCli) NamedQueryFastContext(ctx context.Context, sql string, data any) ([][]any, []string, error)
NamedQueryFastContext returns results in efficient [][]any format with preprocessing and context support for named queries
func (*DBCli) NamedQueryRow ¶ added in v1.0.0
NamedQueryRow and DirectNamedQueryRow align with named-parameter single row queries
func (*DBCli) NamedQueryRowAsResultContext ¶ added in v1.0.0
NamedQueryRowAsResultContext executes a named parameter query with context expected to return at most one row
func (*DBCli) NamedQueryRowContext ¶ added in v1.0.0
func (*DBCli) NamedQueryRowFast ¶ added in v1.0.0
NamedQueryRowFast returns single row in efficient []any format with preprocessing for named queries
func (*DBCli) NamedQueryRowFastContext ¶ added in v1.0.0
func (d *DBCli) NamedQueryRowFastContext(ctx context.Context, sql string, data any) ([]any, []string, error)
NamedQueryRowFastContext returns single row in efficient []any format with preprocessing and context support for named queries
func (*DBCli) ObjectExists ¶ added in v1.0.0
func (d *DBCli) ObjectExists(objectName string, objectType dialect.DatabaseObjectType) (bool, error)
ObjectExists checks if a database object (table, view, procedure, function, trigger, sequence) exists
func (*DBCli) PaginatedList ¶ added in v1.0.0
func (*DBCli) PaginatedListAsResult ¶ added in v1.0.0
func (d *DBCli) PaginatedListAsResult(tableName any, data map[string]any, pageIndex int, pageSize int, cc ...QueryOption) QueryResult
func (*DBCli) PaginatedListAsResultContext ¶ added in v1.0.0
func (d *DBCli) PaginatedListAsResultContext(ctx context.Context, tableName any, data map[string]any, pageIndex int, pageSize int, cc ...QueryOption) QueryResult
func (*DBCli) PaginatedListContext ¶ added in v1.0.0
func (*DBCli) QueryAsResult ¶ added in v1.0.0
func (d *DBCli) QueryAsResult(sql string, arguments ...any) QueryResult
QueryAsResult executes a query and returns results wrapped in QueryResult
func (*DBCli) QueryAsResultContext ¶ added in v1.0.0
QueryAsResultContext executes a query with context and returns results wrapped in QueryResult
func (*DBCli) QueryContext ¶ added in v1.0.0
func (*DBCli) QueryFast ¶ added in v1.0.0
QueryFast returns results in efficient [][]any format with preprocessing
func (*DBCli) QueryFastContext ¶ added in v1.0.0
func (d *DBCli) QueryFastContext(ctx context.Context, sql string, arguments ...any) ([][]any, []string, error)
QueryFastContext returns results in efficient [][]any format with preprocessing and context support
func (*DBCli) QueryRowAsResult ¶ added in v1.0.0
func (d *DBCli) QueryRowAsResult(sql string, args ...any) QueryResult
QueryRowAsResult executes a query expected to return at most one row and returns QueryResult
func (*DBCli) QueryRowAsResultContext ¶ added in v1.0.0
QueryRowAsResultContext executes a query with context expected to return at most one row and returns QueryResult
func (*DBCli) QueryRowContext ¶ added in v1.0.0
func (*DBCli) QueryRowFast ¶ added in v1.0.0
QueryRowFast returns single row in efficient []any format with preprocessing
func (*DBCli) QueryRowFastContext ¶ added in v1.0.0
func (d *DBCli) QueryRowFastContext(ctx context.Context, sql string, args ...any) ([]any, []string, error)
QueryRowFastContext returns single row in efficient []any format with preprocessing and context support
func (*DBCli) QueryWithLimitContext ¶ added in v1.0.0
func (d *DBCli) QueryWithLimitContext(ctx context.Context, sql string, limit, offset int) ([][]any, []string, error)
QueryWithLimitContext 执行查询类 SQL,自动应用可选 LIMIT 护栏(EnsureLimit)。 已含 LIMIT 或无需 LIMIT 的语句原样执行;无 LIMIT 的 SELECT 按方言重构后追加上限。
func (*DBCli) ReadSQLFile ¶
func (d *DBCli) ReadSQLFile(r io.Reader, callback dialect.FuncSQLStmtCallback, options ...func(*dialect.ReadSQLFileOptions)) error
readSQLFile reads and returns the content of an SQL file.
func (*DBCli) ReplaceContext ¶ added in v1.0.0
func (*DBCli) SelectContext ¶ added in v1.0.0
func (*DBCli) UpdateContext ¶ added in v1.0.0
func (*DBCli) UpsertContext ¶ added in v1.0.0
func (*DBCli) ValidateSQL ¶ added in v1.0.0
func (d *DBCli) ValidateSQL(sql string) *def.ValidationError
func (*DBCli) WithTransaction ¶
func (d *DBCli) WithTransaction(fn func(tx DatabaseClient) error) (err error)
func (*DBCli) WithTransactionContext ¶ added in v1.0.0
type DBConnection ¶
type DBConnection = def.DBConnection
type DBMgr ¶
type DBMgr struct {
// contains filtered or unexported fields
}
func (*DBMgr) GetDatebase ¶ added in v1.0.0
func (*DBMgr) GetOrCreateCli ¶
func (s *DBMgr) GetOrCreateCli(config any, extendProps ...CLiExtendPropsFunc) (*DBCli, error)
func (*DBMgr) InitByConfig ¶
func (s *DBMgr) InitByConfig(conf *def.Config, extendProps ...CLiExtendPropsFunc) error
func (*DBMgr) SetCliIfNotExists ¶ added in v1.0.0
func (*DBMgr) TestConnect ¶ added in v1.0.0
func (s *DBMgr) TestConnect(con *def.DBConnection) error
type DDLSqlFuncName ¶
type DDLSqlFuncName = dialect.DDLSqlFuncName
Re-export dialect function name types/constants
const ( FuncNameGetCreateTableSql DDLSqlFuncName = dialect.FuncNameGetCreateTableSql FuncNameGetCreateViewSql DDLSqlFuncName = dialect.FuncNameGetCreateViewSql FuncNameGetCreateProcedureSql DDLSqlFuncName = dialect.FuncNameGetCreateProcedureSql FuncNameGetCreateFunctionSql DDLSqlFuncName = dialect.FuncNameGetCreateFunctionSql FuncNameGetTableEventSql DDLSqlFuncName = dialect.FuncNameGetTableEventSql FuncNameGetBeginSql DDLSqlFuncName = dialect.FuncNameGetBeginSql FuncNameGetEndSql DDLSqlFuncName = dialect.FuncNameGetEndSql )
type DatabaseClient ¶
type DatabaseClient = def.DatabaseClient
type DatabaseError ¶
type DatabaseError struct {
Code string `json:"code"`
Message string `json:"message"`
Details string `json:"details,omitempty"`
Cause error `json:"-"`
}
DatabaseError represents a database-specific error with error codes
func NewDatabaseError ¶
func NewDatabaseError(code, message string) *DatabaseError
NewDatabaseError creates a new DatabaseError
func (*DatabaseError) Error ¶
func (e *DatabaseError) Error() string
func (*DatabaseError) Unwrap ¶
func (e *DatabaseError) Unwrap() error
func (*DatabaseError) WithCause ¶
func (e *DatabaseError) WithCause(cause error) *DatabaseError
WithCause adds the underlying cause
func (*DatabaseError) WithDetails ¶
func (e *DatabaseError) WithDetails(details string) *DatabaseError
WithDetails adds details to the error
type DatabaseObjectType ¶ added in v1.0.0
type DatabaseObjectType = dialect.DatabaseObjectType
const ( ObjectTypeTable DatabaseObjectType = dialect.ObjectTypeTable ObjectTypeView DatabaseObjectType = dialect.ObjectTypeView ObjectTypeProcedure DatabaseObjectType = dialect.ObjectTypeProcedure ObjectTypeFunction DatabaseObjectType = dialect.ObjectTypeFunction ObjectTypeTrigger DatabaseObjectType = dialect.ObjectTypeTrigger ObjectTypeSequence DatabaseObjectType = dialect.ObjectTypeSequence )
type DatabaseTransformer ¶
type DatabaseTransformer = dialect.DatabaseTransformer
type Expression ¶
type Expression = def.Expression
func Named ¶ added in v1.0.0
func Named(name string) Expression
Named creates a named parameter expression (e.g., Named("id") -> :id).
type IDBOperWrapper ¶
type IDBOperWrapper interface {
BindNamed(query string, arg any) (string, []any, error)
Exec(query string, args ...any) (sql.Result, error)
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
Get(dest any, query string, args ...any) error
GetContext(ctx context.Context, dest any, query string, args ...any) error
MustExec(query string, args ...any) sql.Result
MustExecContext(ctx context.Context, query string, args ...any) sql.Result
NamedExec(query string, arg any) (sql.Result, error)
NamedExecContext(ctx context.Context, query string, arg any) (sql.Result, error)
NamedQuery(query string, arg any) (*sqlx.Rows, error)
Prepare(query string) (*sql.Stmt, error)
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
PrepareNamed(query string) (*sqlx.NamedStmt, error)
PrepareNamedContext(ctx context.Context, query string) (*sqlx.NamedStmt, error)
Preparex(query string) (*sqlx.Stmt, error)
PreparexContext(ctx context.Context, query string) (*sqlx.Stmt, error)
Query(query string, args ...any) (*sql.Rows, error)
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
QueryRow(query string, args ...any) *sql.Row
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
QueryRowx(query string, args ...any) *sqlx.Row
QueryRowxContext(ctx context.Context, query string, args ...any) *sqlx.Row
Queryx(query string, args ...any) (*sqlx.Rows, error)
QueryxContext(ctx context.Context, query string, args ...any) (*sqlx.Rows, error)
Select(dest any, query string, args ...any) error
SelectContext(ctx context.Context, dest any, query string, args ...any) error
}
IDBOperWrapper defines the operations DBCli delegates to (sqlx.DB or sqlx.Tx).
type IRepo ¶
IRepo 定义支持事务的仓库接口。 实现要求:
- GetDBCli() 返回底层数据库客户端(用于开启事务)
- NewTransactionCopy(tx) 必须返回与调用者相同的具体类型(如 *UserRepo), 以确保泛型类型断言 tempRepo.(T) 安全。
type ItemTransformFunc ¶ added in v1.0.0
type ItemTransformFunc = def.ItemTransformFunc
type MigrateFileFunc ¶
type MigrateFileFunc = migrate.MigrateFileFunc
func WithIgnoreError ¶
func WithIgnoreError(ignoreError bool) MigrateFileFunc
func WithMigrateFileFunc ¶
func WithMigrateFileFunc(f *embed.FS) MigrateFileFunc
func WithServiceOwner ¶
func WithServiceOwner(serviceOwner string) MigrateFileFunc
type MigrateInfo ¶
type OP ¶
type OP string
const ( // 比较运算符 OP_EQ OP = "=" OP_NEQ OP = "!=" OP_GT OP = ">" OP_GTE OP = ">=" OP_LT OP = "<" OP_LTE OP = "<=" OP_LIKE OP = "LIKE" OP_NOT_LIKE OP = "NOT LIKE" OP_IN OP = "IN" OP_NOT_IN OP = "NOT IN" OP_IS_NULL OP = "IS NULL" OP_IS_NOT_NULL OP = "IS NOT NULL" OP_BETWEEN OP = "BETWEEN" OP_EXISTS OP = "EXISTS" OP_NOT_EXISTS OP = "NOT EXISTS" // 算术运算符 OP_ADD OP = "+" OP_SUBTRACT OP = "-" OP_MULTIPLY OP = "*" OP_DIVIDE OP = "/" OP_MOD OP = "%" )
type OrderBy ¶
type OrderBy = def.OrderClause
type PaginatedResult ¶ added in v1.0.0
type PaginatedResult[T any] = schema.PaginatedResult[T]
func ToPagedResult ¶ added in v1.0.0
func ToPagedResult[T any](qr QueryResult, opts ...cystructmap.Option) (*PaginatedResult[T], error)
func ToPagedResultEx ¶ added in v1.0.0
func ToPagedResultEx[T any](qr QueryResult, transform ItemTransformFunc, opts ...cystructmap.Option) (*PaginatedResult[T], error)
type QueryMetadata ¶
type QueryMetadata = schema.QueryMetadata
QueryMetadata contains additional information about the query execution
type QueryOption ¶ added in v1.0.0
type QueryOption = def.QueryOption
func WithBeforeBuild ¶ added in v1.0.0
func WithBeforeBuild(callback func(def.SQLStmt) error) QueryOption
WithBeforeBuild registers a callback function that will be invoked before building SQL. This allows you to validate or modify the SQLStmt dynamically.
func WithBetween ¶
func WithBetween(field string, start, end any) QueryOption
func WithContains ¶ added in v1.0.0
func WithContains(field string, value string) QueryOption
func WithCount ¶
func WithCount(field string) QueryOption
func WithDistinct ¶
func WithDistinct(distinct bool) QueryOption
func WithEQ ¶
func WithEQ(field string, value ...any) QueryOption
func WithEQs ¶ added in v1.0.0
func WithEQs(field ...string) QueryOption
func WithEndsWith ¶ added in v1.0.0
func WithEndsWith(field string, value string) QueryOption
func WithFields ¶
func WithFields(fields ...any) QueryOption
func WithGT ¶
func WithGT(field string, value ...any) QueryOption
func WithGTE ¶
func WithGTE(field string, value ...any) QueryOption
func WithGTEs ¶ added in v1.0.0
func WithGTEs(field ...string) QueryOption
func WithGTs ¶ added in v1.0.0
func WithGTs(field ...string) QueryOption
func WithGroupBy ¶
func WithGroupBy(columns ...any) QueryOption
func WithISNOTNULL ¶ added in v1.0.0
func WithISNOTNULL(field string) QueryOption
func WithISNULL ¶ added in v1.0.0
func WithISNULL(field string) QueryOption
func WithIn ¶
func WithIn(field string, values []any) QueryOption
func WithInSub ¶ added in v1.0.0
func WithInSub(field string, subquery def.SQLStmt) QueryOption
WithInSub creates an IN condition with a subquery.
func WithInnerJoin ¶
func WithInnerJoin(table any, on ...Where) QueryOption
func WithJoin ¶
func WithJoin(table any, on ...Where) QueryOption
func WithLT ¶
func WithLT(field string, value ...any) QueryOption
func WithLTE ¶
func WithLTE(field string, value ...any) QueryOption
func WithLTEs ¶ added in v1.0.0
func WithLTEs(field ...string) QueryOption
func WithLTs ¶ added in v1.0.0
func WithLTs(field ...string) QueryOption
func WithLeftJoin ¶
func WithLeftJoin(table any, on ...Where) QueryOption
func WithLike ¶
func WithLike(field string, value string) QueryOption
func WithLimit ¶
func WithLimit(limit int) QueryOption
func WithNEQ ¶
func WithNEQ(field string, value ...any) QueryOption
func WithNEQs ¶ added in v1.0.0
func WithNEQs(field ...string) QueryOption
func WithNotIn ¶
func WithNotIn(field string, values []any) QueryOption
func WithNotInSub ¶ added in v1.0.0
func WithNotInSub(field string, subquery def.SQLStmt) QueryOption
WithNotInSub creates a NOT IN condition with a subquery.
func WithOffset ¶
func WithOffset(offset int) QueryOption
func WithOrderBy ¶
func WithOrderBy(orders ...any) QueryOption
func WithOrderByAsc ¶ added in v1.0.0
func WithOrderByAsc(orders ...any) QueryOption
func WithOrderByDesc ¶ added in v1.0.0
func WithOrderByDesc(orders ...any) QueryOption
func WithRightJoin ¶
func WithRightJoin(table any, on ...Where) QueryOption
func WithSelect ¶
func WithSelect(selects ...any) QueryOption
func WithStartsWith ¶ added in v1.0.0
func WithStartsWith(field string, value string) QueryOption
func WithSubQueryValues ¶
func WithSubQueryValues(builder *ss.SQLStmt) QueryOption
func WithTable ¶
func WithTable(table any) QueryOption
func WithUnion ¶ added in v1.0.0
func WithUnion(stmt *ss.SQLStmt) QueryOption
func WithUnionAll ¶ added in v1.0.0
func WithUnionAll(stmt *ss.SQLStmt) QueryOption
func WithUpdate ¶
func WithUpdate(table any) QueryOption
func WithUpdateExpr ¶
func WithUpdateExpr(assignments ...ss.Assignment) QueryOption
WithUpdateExpr maps to SET clause assignments. We change signature to accept ss.Assignment for type safety with ss package.
func WithValues ¶
func WithValues(data ...[]Expression) QueryOption
func WithValuesAppend ¶
func WithValuesAppend(data ...[]Expression) QueryOption
func WithWhere ¶
func WithWhere(where ...Where) QueryOption
func WithWhereAnd ¶
func WithWhereAnd(where ...Where) QueryOption
func WithWhereOr ¶
func WithWhereOr(where ...Where) QueryOption
type QueryResult ¶ added in v1.0.0
type QueryResult = def.QueryResult
type RawCondition ¶ added in v1.0.0
type RawCondition = def.RawCondition
type SQLBuilder ¶
func ParseMySQL ¶
func ParseMySQL(sql string) (SQLBuilder, error)
ParseMySQL parses a SQL statement and returns a SQLBuilder
type SortDirection ¶ added in v1.0.0
type SortDirection = ss.SortDirection
SortDirection represents the sort direction for ORDER BY.
const ( SortAsc SortDirection = ss.SortAsc SortDesc SortDirection = ss.SortDesc )
type SortFuncName ¶
type SortFuncName = dialect.SortFuncName
const ( FuncNameSortTables SortFuncName = dialect.FuncNameSortTables FuncNameSortFunctions SortFuncName = dialect.FuncNameSortFunctions FuncNameSortProcedures SortFuncName = dialect.FuncNameSortProcedures )
type ValidationError ¶ added in v1.0.0
type ValidationError = def.ValidationError
type Where ¶
func IS_NOT_NULL ¶
func NOT_LIKE ¶ added in v1.0.0
func NOT_LIKE(field string, value string, pt def.LikePatternType) Where
func TupleEQ ¶ added in v1.0.0
TupleEQ creates (cols...) = (vals...) for composite key comparison.
Example:
TupleEQ([]string{"order_id", "product_id"}, 1, 2) // (order_id, product_id) = (1, 2)
func TupleGT ¶ added in v1.0.0
TupleGT creates (cols...) > (vals...), useful for keyset pagination.
Example:
TupleGT([]string{"created_at", "id"}, lastCreatedAt, lastID)
func TupleIN ¶ added in v1.0.0
TupleIN creates (cols...) IN ((v1...), (v2...), ...) for multiple composite keys.
Example:
TupleIN([]string{"order_id", "product_id"}, [][]any{{1, 2}, {3, 4}})
func TupleNOTIN ¶ added in v1.0.0
TupleNOTIN creates (cols...) NOT IN ((...)).
type WhereOptionFunc ¶
type WhereOptionFunc = def.QueryOption
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cydb provides database operations and SQL parsing utilities.
|
Package cydb provides database operations and SQL parsing utilities. |
|
Package cydb provides automatic table creation based on Go struct definitions.
|
Package cydb provides automatic table creation based on Go struct definitions. |