cydb

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var NewDBCliMgr = NewSqlMgr

Functions

func ASC

func ASC(field any) any

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 ConvertToCountSQL(sqlStr string) string

func DESC

func DESC(field any) any

func DetectSQLType added in v1.0.0

func DetectSQLType(sql string) string

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 GetDBLogger() *cylog.Logger

func InMapParam

func InMapParam(ids map[string]struct{}) string

func InParam

func InParam(ids []string) string

func InParam2

func InParam2(ids [][]string) string

func LeafDirs

func LeafDirs(efs *embed.FS) ([]string, error)

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 ParseCount(row map[string]any) int64

func Q added in v1.0.0

func Q(options ...QueryOption) def.SQLStmt

func SplitSQLStatements added in v1.0.0

func SplitSQLStatements(dbtype, sql string) []string

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 ToMigrationTableInfo(t def.TableInfo, opts ...migrate.ToMigrationTableInfoOption) def.TableInfo

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

func WithTransaction[T IRepo](repo T, fn func(T) error) (err error)

WithTransaction 在单个 repo 上执行带事务的操作。 若 fn 返回 error 或发生 panic,事务将回滚;否则提交。

func WithTransactions added in v1.0.0

func WithTransactions[T IRepo](repos []T, fn func([]T) error) (err error)

WithTransactions 在多个 repo 上分别开启本地事务并执行操作。 注意:

  • 这不是分布式事务!各事务独立提交。
  • 若任一事务提交失败,其余已成功提交的事务不会回滚(仅未提交的会回滚)。
  • 适用于同一数据库的多 schema / 多连接池,或可容忍最终一致性的场景。

Types

type BooleanCondition added in v1.0.0

type BooleanCondition = def.BooleanCondition

type CLiExtendProps added in v1.0.0

type CLiExtendProps struct {
	FormatTime      string
	NumbersAsString bool
}

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 Config

type Config = def.Config

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 (d *DBCli) AnalyzeSQL(sql string) (*def.SQLImpact, error)

func (*DBCli) BatchInsert

func (d *DBCli) BatchInsert(tableName string, data []map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) BatchInsertContext added in v1.0.0

func (d *DBCli) BatchInsertContext(ctx context.Context, tableName string, data []map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) BatchReplace

func (d *DBCli) BatchReplace(tableName string, data []map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) BatchReplaceContext added in v1.0.0

func (d *DBCli) BatchReplaceContext(ctx context.Context, tableName string, data []map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) BatchUpdate

func (d *DBCli) BatchUpdate(tableName string, data []map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) BatchUpdateContext added in v1.0.0

func (d *DBCli) BatchUpdateContext(ctx context.Context, tableName string, data []map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) BeginTx added in v1.0.0

func (d *DBCli) BeginTx() (r *DBCli, err error)

func (*DBCli) BeginTxContext added in v1.0.0

func (d *DBCli) BeginTxContext(ctx context.Context) (r *DBCli, err error)

func (*DBCli) Close

func (d *DBCli) Close() error

func (*DBCli) ColumnExists added in v1.0.0

func (d *DBCli) ColumnExists(tableName string, columnName string) (bool, error)

func (*DBCli) Commit

func (d *DBCli) Commit() error

func (*DBCli) CompatCollation added in v1.0.0

func (d *DBCli) CompatCollation() bool

CompatCollation 返回 MySQL 8.0→5.7 collation 兼容开关。

func (*DBCli) Count

func (d *DBCli) Count(tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) CountContext added in v1.0.0

func (d *DBCli) CountContext(ctx context.Context, tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) DBSubType added in v1.0.0

func (d *DBCli) DBSubType() string

func (*DBCli) DBType

func (d *DBCli) DBType() string

func (*DBCli) Database

func (d *DBCli) Database() string

func (*DBCli) Delete

func (d *DBCli) Delete(tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) DeleteContext added in v1.0.0

func (d *DBCli) DeleteContext(ctx context.Context, tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) DirectExcute deprecated added in v1.0.0

func (d *DBCli) DirectExcute(sql string, arguments ...any) (int64, error)

Deprecated: use DirectExecute instead.

func (*DBCli) DirectExecute added in v1.0.0

func (d *DBCli) DirectExecute(sql string, arguments ...any) (int64, error)

func (*DBCli) DirectExecuteContext added in v1.0.0

func (d *DBCli) DirectExecuteContext(ctx context.Context, sql string, arguments ...any) (int64, error)

func (*DBCli) DirectForEachQuery added in v1.0.0

func (d *DBCli) DirectForEachQuery(tableName string, selectSQL string, fn func(RowData) error) error

func (*DBCli) DirectNQuery deprecated added in v1.0.0

func (d *DBCli) DirectNQuery(sql string, data any) ([]map[string]any, error)

Deprecated: use DirectNamedQuery instead.

func (*DBCli) DirectNQueryContext deprecated added in v1.0.0

func (d *DBCli) DirectNQueryContext(ctx context.Context, sql string, data any) ([]map[string]any, error)

Deprecated: use DirectNamedQueryContext instead.

func (*DBCli) DirectNQueryRow added in v1.0.0

func (d *DBCli) DirectNQueryRow(sql string, data any) (map[string]any, error)

func (*DBCli) DirectNQueryRowContext added in v1.0.0

func (d *DBCli) DirectNQueryRowContext(ctx context.Context, sql string, data any) (map[string]any, error)

func (*DBCli) DirectNamedExecute added in v1.0.0

func (d *DBCli) DirectNamedExecute(sql string, data any) (int64, error)

func (*DBCli) DirectNamedExecuteContext added in v1.0.0

func (d *DBCli) DirectNamedExecuteContext(ctx context.Context, sql string, data any) (int64, error)

func (*DBCli) DirectNamedForEachQuery added in v1.0.0

func (d *DBCli) DirectNamedForEachQuery(tableName string, selectSQL string, data any, fn func(RowData) error) error

func (*DBCli) DirectNamedForEachQueryContext added in v1.0.0

func (d *DBCli) DirectNamedForEachQueryContext(ctx context.Context, tableName string, selectSQL string, data any, fn func(RowData) error) error

func (*DBCli) DirectNamedInsert added in v1.0.0

func (d *DBCli) DirectNamedInsert(sql string, data any) (int64, error)

func (*DBCli) DirectNamedInsertContext added in v1.0.0

func (d *DBCli) DirectNamedInsertContext(ctx context.Context, sql string, data any) (int64, error)

func (*DBCli) DirectNamedQuery added in v1.0.0

func (d *DBCli) DirectNamedQuery(sql string, data any) ([]map[string]any, error)

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 (d *DBCli) DirectNamedQueryContext(ctx context.Context, sql string, data any) ([]map[string]any, error)

func (*DBCli) DirectNamedQueryFast added in v1.0.0

func (d *DBCli) DirectNamedQueryFast(sql string, data any) ([][]any, []string, error)

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 (d *DBCli) DirectNamedQueryRow(sql string, data any) (map[string]any, error)

func (*DBCli) DirectNamedQueryRowContext added in v1.0.0

func (d *DBCli) DirectNamedQueryRowContext(ctx context.Context, sql string, data any) (map[string]any, error)

func (*DBCli) DirectNamedQueryRowFast added in v1.0.0

func (d *DBCli) DirectNamedQueryRowFast(sql string, data any) ([]any, []string, error)

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 (d *DBCli) DirectNamedSelect(dest any, query string, arg any) error

func (*DBCli) DirectQuery added in v1.0.0

func (d *DBCli) DirectQuery(sql string, arguments ...any) ([]map[string]any, error)

func (*DBCli) DirectQueryContext added in v1.0.0

func (d *DBCli) DirectQueryContext(ctx context.Context, sql string, arguments ...any) ([]map[string]any, error)

func (*DBCli) DirectQueryFast added in v1.0.0

func (d *DBCli) DirectQueryFast(sql string, arguments ...any) ([][]any, []string, error)

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 (d *DBCli) DirectQueryRow(sql string, args ...any) (map[string]any, error)

func (*DBCli) DirectQueryRowContext added in v1.0.0

func (d *DBCli) DirectQueryRowContext(ctx context.Context, sql string, args ...any) (map[string]any, error)

func (*DBCli) DirectQueryRowFast added in v1.0.0

func (d *DBCli) DirectQueryRowFast(sql string, args ...any) ([]any, []string, error)

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 (d *DBCli) EnsureDBExists(dbName string) error

func (*DBCli) EnsureLimit added in v1.0.0

func (d *DBCli) EnsureLimit(sql string, limit, offset int) (string, error)

EnsureLimit 为查询语句补齐 LIMIT 护栏(可选查询限制)。 采用「解析 → 判断 → 构造 → 执行」的正规链路:

  1. ParseMySQL 解析 AST;无法解析则原样返回(安全降级,交由数据库报错);
  2. 若 AST 已有 LimitClause → 原样返回(含 LIMIT 的语句由用户控制行数);
  3. 若语句类型不支持 LIMIT(SHOW/DESC/SET 等)→ 原样返回;
  4. 否则在 AST 上 SetLimitClause,再按当前数据库方言 BuildSQL 重构, 使 LIMIT/OFFSET 由底层按方言正确渲染(MySQL/PG 用 LIMIT,Oracle 用 ROWNUM)。

func (*DBCli) Excute deprecated

func (d *DBCli) Excute(sql string, arguments ...any) (int64, error)

Deprecated: use Execute instead.

func (*DBCli) Execute added in v1.0.0

func (d *DBCli) Execute(sql string, arguments ...any) (int64, error)

func (*DBCli) ExecuteContext added in v1.0.0

func (d *DBCli) ExecuteContext(ctx context.Context, sql string, arguments ...any) (int64, error)

func (*DBCli) Exists

func (d *DBCli) Exists(tableName string, data map[string]any, cc ...def.QueryOption) (bool, error)

func (*DBCli) ExistsContext added in v1.0.0

func (d *DBCli) ExistsContext(ctx context.Context, tableName string, data map[string]any, cc ...def.QueryOption) (bool, error)

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) First

func (d *DBCli) First(tableName string, data map[string]any, cc ...def.QueryOption) (map[string]any, error)

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 (d *DBCli) FirstContext(ctx context.Context, tableName string, data map[string]any, cc ...def.QueryOption) (map[string]any, error)

func (*DBCli) ForEachData added in v1.0.0

func (d *DBCli) ForEachData(tableName string, data []map[string]any, fn func(RowData) error) error

func (*DBCli) ForEachQuery added in v1.0.0

func (d *DBCli) ForEachQuery(tableName string, selectSQL string, fn func(RowData) error) error

func (*DBCli) ForEachQueryByWhere added in v1.0.0

func (d *DBCli) ForEachQueryByWhere(tableName string, where []def.QueryOption, p P, fn func(RowData) error) error

func (*DBCli) ForEachQueryContext added in v1.0.0

func (d *DBCli) ForEachQueryContext(ctx context.Context, tableName string, selectSQL string, fn func(RowData) error) error

func (*DBCli) Get

func (d *DBCli) Get(dest any, query string, args ...any) error

func (*DBCli) GetContext added in v1.0.0

func (d *DBCli) GetContext(ctx context.Context, dest any, query string, args ...any) error

func (*DBCli) GetDB

func (d *DBCli) GetDB() *sqlx.DB

func (*DBCli) GetDDLSql

func (d *DBCli) GetDDLSql(funcName dialect.DDLSqlFuncName, name ...string) (*dialect.SqlContent, error)

func (*DBCli) GetDatabases added in v1.0.0

func (d *DBCli) GetDatabases() ([]string, error)

GetDatabases 返回数据库列表(通过 dialect 实现,屏蔽方言差异)。

func (*DBCli) GetIndexes added in v1.0.0

func (d *DBCli) GetIndexes(tableName string) ([]dialect.IndexInfo, error)

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 (d *DBCli) GetPassword() string

func (*DBCli) GetPrimaryKeys added in v1.0.0

func (d *DBCli) GetPrimaryKeys(tableName string) ([]string, error)

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 (d *DBCli) GetTableInfo(tableName string) (TableInfo, error)

func (*DBCli) GetTables added in v1.0.0

func (d *DBCli) GetTables(dbName string, schema *string, keyword *string) ([]string, error)

func (*DBCli) GetUniqueKeys added in v1.0.0

func (d *DBCli) GetUniqueKeys(tableName string) ([]string, error)

func (*DBCli) Insert

func (d *DBCli) Insert(tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) InsertAndGetID added in v1.0.0

func (d *DBCli) InsertAndGetID(tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) InsertAndGetIDContext added in v1.0.0

func (d *DBCli) InsertAndGetIDContext(ctx context.Context, tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) InsertContext added in v1.0.0

func (d *DBCli) InsertContext(ctx context.Context, tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) IsTableExist

func (d *DBCli) IsTableExist(tableName string) (bool, error)

func (*DBCli) Key

func (d *DBCli) Key() string

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 (d *DBCli) ListContext(ctx context.Context, tableName string, data map[string]any, cc ...def.QueryOption) ([]map[string]any, error)

func (*DBCli) ListWithPage

func (d *DBCli) ListWithPage(tableName string, data map[string]any, pageIndex int, pageSize int, cc ...def.QueryOption) ([]map[string]any, int64, error)

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 (d *DBCli) ListWithPageContext(ctx context.Context, tableName string, data map[string]any, pageIndex int, pageSize int, cc ...def.QueryOption) ([]map[string]any, int64, error)

func (*DBCli) NQuery deprecated

func (d *DBCli) NQuery(sql string, data any) ([]map[string]any, error)

Deprecated: use NamedQuery instead.

func (*DBCli) NQueryContext deprecated added in v1.0.0

func (d *DBCli) NQueryContext(ctx context.Context, sql string, data any) ([]map[string]any, error)

Deprecated: use NamedQueryContext instead.

func (*DBCli) NQueryRow added in v1.0.0

func (d *DBCli) NQueryRow(sql string, data any) (map[string]any, error)

func (*DBCli) NQueryRowContext added in v1.0.0

func (d *DBCli) NQueryRowContext(ctx context.Context, sql string, data any) (map[string]any, error)

func (*DBCli) NamedExecute added in v1.0.0

func (d *DBCli) NamedExecute(sql string, data any) (int64, error)

func (*DBCli) NamedExecuteContext added in v1.0.0

func (d *DBCli) NamedExecuteContext(ctx context.Context, sql string, data any) (int64, error)

func (*DBCli) NamedForEachQuery added in v1.0.0

func (d *DBCli) NamedForEachQuery(tableName string, selectSQL string, data any, fn func(RowData) error) error

func (*DBCli) NamedForEachQueryContext added in v1.0.0

func (d *DBCli) NamedForEachQueryContext(ctx context.Context, tableName string, selectSQL string, data any, fn func(RowData) error) error

func (*DBCli) NamedQuery added in v1.0.0

func (d *DBCli) NamedQuery(sql string, data any) ([]map[string]any, error)

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

func (d *DBCli) NamedQueryAsResultContext(ctx context.Context, sql string, data any) QueryResult

NamedQueryAsResultContext executes a named parameter query with context and returns results wrapped in QueryResult

func (*DBCli) NamedQueryContext added in v1.0.0

func (d *DBCli) NamedQueryContext(ctx context.Context, sql string, data any) ([]map[string]any, error)

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

func (d *DBCli) NamedQueryRow(sql string, data any) (map[string]any, error)

NamedQueryRow and DirectNamedQueryRow align with named-parameter single row queries

func (*DBCli) NamedQueryRowAsResultContext added in v1.0.0

func (d *DBCli) NamedQueryRowAsResultContext(ctx context.Context, sql string, data any) QueryResult

NamedQueryRowAsResultContext executes a named parameter query with context expected to return at most one row

func (*DBCli) NamedQueryRowContext added in v1.0.0

func (d *DBCli) NamedQueryRowContext(ctx context.Context, sql string, data any) (map[string]any, error)

func (*DBCli) NamedQueryRowFast added in v1.0.0

func (d *DBCli) NamedQueryRowFast(sql string, data any) ([]any, []string, error)

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) PW

func (d *DBCli) PW() string

Legacy alias for interface compatibility

func (*DBCli) PaginatedList added in v1.0.0

func (d *DBCli) PaginatedList(tableName string, data map[string]any, pageIndex int, pageSize int, cc ...def.QueryOption) ([]map[string]any, int64, error)

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 (d *DBCli) PaginatedListContext(ctx context.Context, tableName string, data map[string]any, pageIndex int, pageSize int, cc ...def.QueryOption) ([]map[string]any, int64, error)

func (*DBCli) Query

func (d *DBCli) Query(sql string, arguments ...any) ([]map[string]any, error)

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

func (d *DBCli) QueryAsResultContext(ctx context.Context, sql string, arguments ...any) QueryResult

QueryAsResultContext executes a query with context and returns results wrapped in QueryResult

func (*DBCli) QueryContext added in v1.0.0

func (d *DBCli) QueryContext(ctx context.Context, sql string, arguments ...any) ([]map[string]any, error)

func (*DBCli) QueryFast added in v1.0.0

func (d *DBCli) QueryFast(sql string, arguments ...any) ([][]any, []string, error)

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) QueryRow added in v1.0.0

func (d *DBCli) QueryRow(sql string, args ...any) (map[string]any, error)

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

func (d *DBCli) QueryRowAsResultContext(ctx context.Context, sql string, args ...any) QueryResult

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 (d *DBCli) QueryRowContext(ctx context.Context, sql string, args ...any) (map[string]any, error)

func (*DBCli) QueryRowFast added in v1.0.0

func (d *DBCli) QueryRowFast(sql string, args ...any) ([]any, []string, error)

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) Replace

func (d *DBCli) Replace(tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) ReplaceContext added in v1.0.0

func (d *DBCli) ReplaceContext(ctx context.Context, tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) Rollback

func (d *DBCli) Rollback() error

func (*DBCli) Select

func (d *DBCli) Select(dest any, query string, args ...any) error

func (*DBCli) SelectContext added in v1.0.0

func (d *DBCli) SelectContext(ctx context.Context, dest any, query string, args ...any) error

func (*DBCli) Update

func (d *DBCli) Update(tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) UpdateContext added in v1.0.0

func (d *DBCli) UpdateContext(ctx context.Context, tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) Upsert

func (d *DBCli) Upsert(tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)

func (*DBCli) UpsertContext added in v1.0.0

func (d *DBCli) UpsertContext(ctx context.Context, tableName string, data map[string]any, cc ...def.QueryOption) (int64, error)

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

func (d *DBCli) WithTransactionContext(ctx context.Context, fn func(tx DatabaseClient) error) (err error)

type DBConnection

type DBConnection = def.DBConnection

type DBMgr

type DBMgr struct {
	// contains filtered or unexported fields
}

func NewSqlMgr

func NewSqlMgr(conf *def.Config, migrateFileFunc ...migrate.MigrateFileFunc) (*DBMgr, error)

func (*DBMgr) CloseAll

func (s *DBMgr) CloseAll()

func (*DBMgr) Exist added in v1.0.0

func (s *DBMgr) Exist(key string) bool

func (*DBMgr) GetCli

func (s *DBMgr) GetCli(key string) *DBCli

func (*DBMgr) GetDatebase added in v1.0.0

func (s *DBMgr) GetDatebase() []string

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) SetCli

func (s *DBMgr) SetCli(key string, cli *DBCli)

func (*DBMgr) SetCliIfNotExists added in v1.0.0

func (s *DBMgr) SetCliIfNotExists(key string, cli *DBCli)

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

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 FieldData

type FieldData = def.FieldData

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

type IRepo interface {
	GetDBCli() *DBCli
	NewTransactionCopy(tx *DBCli) (IRepo, error)
}

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 MigrateInfo struct {
	Key    string
	DBType string
}

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 Object added in v1.0.0

type Object = map[string]any

type OrderBy

type OrderBy = def.OrderClause

type P added in v1.0.0

type P = map[string]any

type PARAMS

type PARAMS = map[string]any

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 RowData

type RowData = def.RowData

type SQLBlock added in v1.0.0

type SQLBlock = dialect.SQLBlock

type SQLBuilder

type SQLBuilder = *ss.SQLStmt

func ParseMySQL

func ParseMySQL(sql string) (SQLBuilder, error)

ParseMySQL parses a SQL statement and returns a SQLBuilder

type SQLImpact added in v1.0.0

type SQLImpact = def.SQLImpact

type SQLStmt added in v1.0.0

type SQLStmt = def.SQLStmt

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 TableInfo added in v1.0.0

type TableInfo = def.TableInfo

type ValidationError added in v1.0.0

type ValidationError = def.ValidationError

type Where

type Where = ss.Condition

func AND

func AND(c ...Where) Where

func AllEQ added in v1.0.0

func AllEQ(fields []string, values ...any) Where

func AllGT added in v1.0.0

func AllGT(fields []string, values ...any) Where

func AllGTE added in v1.0.0

func AllGTE(fields []string, values ...any) Where

func AllLT added in v1.0.0

func AllLT(fields []string, values ...any) Where

func AllLTE added in v1.0.0

func AllLTE(fields []string, values ...any) Where

func AllNEQ added in v1.0.0

func AllNEQ(fields []string, values ...any) Where

func AnyEQ added in v1.0.0

func AnyEQ(fields []string, values ...any) Where

func AnyGT added in v1.0.0

func AnyGT(fields []string, values ...any) Where

func AnyGTE added in v1.0.0

func AnyGTE(fields []string, values ...any) Where

func AnyLT added in v1.0.0

func AnyLT(fields []string, values ...any) Where

func AnyLTE added in v1.0.0

func AnyLTE(fields []string, values ...any) Where

func AnyNEQ added in v1.0.0

func AnyNEQ(fields []string, values ...any) Where

func BETWEEN

func BETWEEN(field string, start, end any) Where

func EQ

func EQ(field any, v ...any) Where

func GT

func GT(field any, v ...any) Where

func GTE

func GTE(field any, v ...any) Where

func IN

func IN(field string, values ...any) Where

func ISNOTNULL added in v1.0.0

func ISNOTNULL(field string) Where

func ISNULL added in v1.0.0

func ISNULL(field string) Where

func IS_NOT_NULL

func IS_NOT_NULL(field string) Where

func IS_NULL

func IS_NULL(field string) Where

func LIKE

func LIKE(field string, value string, pt def.LikePatternType) Where

func LIKEC

func LIKEC(field string, value string) Where

func LIKEL

func LIKEL(field string, value string) Where

func LIKEN added in v1.0.0

func LIKEN(field string, value string) Where

func LIKER

func LIKER(field string, value string) Where

func LT

func LT(field any, v ...any) Where

func LTE

func LTE(field any, v ...any) Where

func NEQ

func NEQ(field any, v ...any) Where

func NOT_IN

func NOT_IN(field string, values ...any) Where

func NOT_LIKE added in v1.0.0

func NOT_LIKE(field string, value string, pt def.LikePatternType) Where

func NOT_LIKEC added in v1.0.0

func NOT_LIKEC(field string, value string) Where

func NOT_LIKEL added in v1.0.0

func NOT_LIKEL(field string, value string) Where

func NOT_LIKEN added in v1.0.0

func NOT_LIKEN(field string, value string) Where

func NOT_LIKER added in v1.0.0

func NOT_LIKER(field string, value string) Where

func ON

func ON(left any, right any, op ...string) Where

func OR

func OR(c ...Where) Where

func TupleEQ added in v1.0.0

func TupleEQ(cols []string, vals ...any) Where

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

func TupleGT(cols []string, vals ...any) Where

TupleGT creates (cols...) > (vals...), useful for keyset pagination.

Example:

TupleGT([]string{"created_at", "id"}, lastCreatedAt, lastID)

func TupleGTE added in v1.0.0

func TupleGTE(cols []string, vals ...any) Where

TupleGTE creates (cols...) >= (vals...).

func TupleIN added in v1.0.0

func TupleIN(cols []string, valsList [][]any) Where

TupleIN creates (cols...) IN ((v1...), (v2...), ...) for multiple composite keys.

Example:

TupleIN([]string{"order_id", "product_id"}, [][]any{{1, 2}, {3, 4}})

func TupleLT added in v1.0.0

func TupleLT(cols []string, vals ...any) Where

TupleLT creates (cols...) < (vals...).

func TupleLTE added in v1.0.0

func TupleLTE(cols []string, vals ...any) Where

TupleLTE creates (cols...) <= (vals...).

func TupleNE added in v1.0.0

func TupleNE(cols []string, vals ...any) Where

TupleNE creates (cols...) <> (vals...).

func TupleNOTIN added in v1.0.0

func TupleNOTIN(cols []string, valsList [][]any) Where

TupleNOTIN creates (cols...) NOT IN ((...)).

func WHERE

func WHERE(field string, value any, ops ...OP) Where

type WhereOptionFunc

type WhereOptionFunc = def.QueryOption

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL