Documentation
¶
Overview ¶
dbx 基于 sqlx 源码进行修改,是一个 Go 语言数据库工具库 在 `database/sql` 之上提供了 SQL 映射功能以及轻量的 ORM 功能 对比 sqlx, 提供了日志接入功能以及基于 vinovest/sqlx 的部分扩展功能进一步优化 接入了 sqltoken 包,用于解析 SQL 语句中的参数和函数调用 提供 `Row.Scan` 多行结果检测 LEFT JOIN 支持 LEFT JOIN 操作 重复列名按位置映射 列名映射函数 函数式选项 Queryable 接口统一 DB/TX 操作 多结果集支持 In 的 nil Valuer 处理以及 IN(...) 语义检测
Index ¶
- Constants
- Variables
- type Binder
- type ColScanner
- type Conn
- type DB
- type DefaultNamer
- type Execer
- type ExecerContext
- type Ext
- type ExtContext
- type Field
- type LogEntry
- type LogMode
- type Logger
- type NamedStmt
- type Namer
- type Preparer
- type PreparerContext
- type QStmt
- type Query
- type Queryable
- type Queryer
- type QueryerContext
- type Row
- type Rows
- type Rowsi
- type Schema
- type Session
- type Stmt
- type Tx
Constants ¶
View Source
const ( UNKNOWN = core.UNKNOWN // 未知绑定类型 QUESTION = core.QUESTION // 问号绑定类型 ? DOLLAR = core.DOLLAR // 美元符号绑定类型 $ NAMED = core.NAMED // 命名参数绑定类型 :name AT = core.AT // @ 符号绑定类型 @name )
View Source
const ( LogProd = core.LogProd // LogProd 生产模式:不调用日志方法 LogDebug = core.LogDebug // LogDebug 调试模式:调用日志方法打印 SQL )
Variables ¶
View Source
var ( BindType = core.BindType // BindType 根据驱动程序名称返回数据库绑定类型 BindDriver = core.BindDriver // BindDriver 将 driverName 的 BindType 设置为 bindType Rebind = core.Rebind // Rebind 将查询默认绑定类型(QUESTION)重新绑定到目标绑定类型 RebindBuff = core.RebindBuff // RebindBuff 是 Rebind 的实验性实现,使用 bytes.Buffer,代码更简单但速度较慢 In = core.In // In 展开 args 中的切片值,返回修改后的查询字符串和新的参数列表 )
View Source
var ( Select = core.Select // Select 使用提供的 Queryer 执行查询,并将每行通过 StructScan 扫描到 dest 中 Get = core.Get // Get 使用提供的 Queryer 执行 QueryRow,并将结果行扫描到 dest 中 MustExec = core.MustExec // MustExec 使用 e 执行查询,如果发生错误则 panic StructScan = core.StructScan // StructScan 将所有行扫描到 dest 切片中 SliceScan = core.SliceScan // SliceScan 扫描一行,返回类似 MapScan 的 []any 值 MapScan = core.MapScan // MapScan 将单行扫描到 dest map[string]any 中 ScanAll = core.ScanAll // ScanAll 将所有行扫描到目标切片中 )
View Source
var ( IsScannable = core.IsScannable // IsScannable 根据 reflect.Type 来判断目标是否可扫描 Mapper = core.Mapper // Mapper 返回使用已配置 NameMapper 函数的有效 Mapper FieldsByTraversal = core.FieldsByTraversal // FieldsByTraversal 根据 traversals 中的路径,用传递的 value 的字段填充 values 接口切片 )
View Source
var ( SetLogger = core.SetLogger // SetLogger 设置全局默认日志器,传入 nil 表示关闭日志 SetLogMode = core.SetLogMode // SetLogMode 设置全局默认日志模式 GetLogger = core.GetLogger // GetLogger 返回全局默认日志器(可能为 nil) GetLogMode = core.GetLogMode // GetLogMode 返回全局默认日志模式 )
View Source
var ( Connect = db.Connect // Connect 连接到数据库并通过 ping 验证连接 MustConnect = db.MustConnect // MustConnect 连接到数据库并在出错时 panic Open = db.Open // Open 与 sql.Open 相同,但返回 *dbx.DB MustOpen = db.MustOpen // MustOpen 与 sql.Open 相同,但返回 *dbx.DB 并在出错时 panic NewDb = db.NewDb // NewDb 为已存在的 *sql.DB 返回一个新的 dbx DB 封装 Preparex = db.Preparex // Preparex 预编译一条语句 LoadFile = db.LoadFile // LoadFile 执行文件中的每条语句 )
View Source
var ( WithUnsafe = db.WithUnsafe // WithUnsafe 返回使构建出的类型处于不安全模式的选项 WithSetUnsafe = db.WithSetUnsafe // WithSetUnsafe 返回设置不安全模式的选项 )
View Source
var ( Named = db.Named // Named 接受使用命名参数的查询和一个参数,返回一个带有参数列表的新查询 NamedQuery = db.NamedQuery // NamedQuery 绑定命名查询并运行 Query NamedExec = db.NamedExec // NamedExec 使用 BindStruct 获取可执行的查询并运行 Exec BindNamed = db.BindNamed // BindNamed 将结构体或 map 绑定到带有命名参数的查询 BindNamedMapper = db.BindNamedMapper // BindNamedMapper 使用指定的 Mapper 进行命名绑定 BindStruct = db.BindStruct // BindStruct 将命名参数查询与结构体参数的字段绑定 BindMap = db.BindMap // BindMap 将命名参数查询与参数 map 绑定 BindArray = db.BindArray // BindArray 将命名参数查询与结构体数组或切片参数的字段绑定 CompileNamedQuery = db.CompileNamedQuery // CompileNamedQuery 将命名查询编译为未绑定的查询和名称列表 FixBound = db.FixBound // FixBound 修复多行插入时的 VALUES 占位符 )
View Source
var ( IsUnsafe = db.IsUnsafe // IsUnsafe 判断扩展类型是否处于不安全模式 MapperFor = db.MapperFor // MapperFor 返回与给定接口关联的 Mapper )
View Source
var ( ConnectContext = db.ConnectContext // ConnectContext 连接到数据库并通过 ping 验证连接 SelectContext = db.SelectContext // SelectContext 使用提供的 Queryer 执行查询,并将每行扫描到 dest 中 GetContext = db.GetContext // GetContext 使用提供的 Queryer 执行 QueryRow,并将结果行扫描到 dest 中 MustExecContext = db.MustExecContext // MustExecContext 使用 e 执行查询,如果发生错误则 panic LoadFileContext = db.LoadFileContext // LoadFileContext 执行文件中的每条语句 PreparexContext = db.PreparexContext // PreparexContext 预编译一条语句 NamedQueryContext = db.NamedQueryContext // NamedQueryContext 绑定命名查询并运行 Query NamedExecContext = db.NamedExecContext // NamedExecContext 使用 BindStruct 获取可执行的查询并运行 Exec )
View Source
var ( NewQuery = orm.NewQuery // NewQuery 基于底层执行器创建 Session。执行器可以是 *db.DB 或 *db.Tx Create = orm.Create // Create 插入一条记录 Save = orm.Save // Save 主键为零值时插入,否则更新 Updates = orm.Updates // Updates 按主键更新指定列(cols 为空时更新所有非主键/非自增列) Delete = orm.Delete // Delete 删除记录(带 softdelete 字段时软删除,除非 Unscoped) Find = orm.Find // Find 查询多条记录 First = orm.First // First 查询首条记录 Take = orm.Take // Take 查询任意一条记录 Count = orm.Count // Count 统计记录数 Pluck = orm.Pluck // Pluck 查询单列 )
View Source
var ErrMultiRows = core.ErrMultiRows
ErrMultiRows 在预期只返回单行的函数(如 Get)实际返回多行时返回。
View Source
var ErrRecordNotFound = orm.ErrRecordNotFound
-- ORM 错误 --
View Source
var NameMapper = core.NameMapper
NameMapper 用于将列名映射到结构体字段名。默认使用 strings.ToLower 将字段名转为小写。
Functions ¶
This section is empty.
Types ¶
type ColScanner ¶
type ColScanner = core.ColScanner // ColScanner 是 MapScan 和 SliceScan 使用的接口
type DefaultNamer ¶
type DefaultNamer = orm.DefaultNamer
type ExecerContext ¶
type ExecerContext = db.ExecerContext // ExecerContext 是带 Context 的执行接口
type ExtContext ¶
type ExtContext = db.ExtContext // ExtContext 是带 Context 的联合接口,可以绑定、查询和执行
type PreparerContext ¶
type PreparerContext = db.PreparerContext // PreparerContext 是带 Context 的预编译接口
type QueryerContext ¶
type QueryerContext = db.QueryerContext // QueryerContext 是带 Context 的查询接口
Directories
¶
| Path | Synopsis |
|---|---|
|
Package core 定义了 dbx 的领域层接口与核心类型。
|
Package core 定义了 dbx 的领域层接口与核心类型。 |
|
Package db 提供了 dbx 的基础设施层实现。
|
Package db 提供了 dbx 的基础设施层实现。 |
|
Package reflectx 实现了对标准 reflect 库的扩展,适用于实现序列化和 反序列化包。
|
Package reflectx 实现了对标准 reflect 库的扩展,适用于实现序列化和 反序列化包。 |
|
Package types 提供了一些实现了`sql.Scanner`和`sql.Valuer`接口的实例类型 适合作为 databases/sql 的扫描和赋值目标。
|
Package types 提供了一些实现了`sql.Scanner`和`sql.Valuer`接口的实例类型 适合作为 databases/sql 的扫描和赋值目标。 |
Click to show internal directories.
Click to hide internal directories.