db

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package db 提供了 dbx 的基础设施层实现。 它包含 DB、Tx、Stmt、Conn 等具体数据库封装类型, 以及连接管理、预编译语句等基础设施功能。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindArray

func BindArray(bindType int, query string, arg any, m *reflectx.Mapper) (string, []any, error)

BindArray 将命名参数查询与结构体数组或切片参数的字段绑定。

func BindMap

func BindMap(bindType int, query string, args map[string]any) (string, []any, error)

BindMap 将命名参数查询与参数 map 绑定。

func BindNamed

func BindNamed(bindType int, query string, arg any) (string, []any, error)

BindNamed 将结构体或 map 绑定到带有命名参数的查询。 已废弃:请改用 Named,此函数可能在将来被移除。

func BindNamedMapper

func BindNamedMapper(bindType int, query string, arg any, m *reflectx.Mapper) (string, []any, error)

BindNamedMapper 使用指定的 Mapper 进行命名绑定。

func BindStruct

func BindStruct(bindType int, query string, arg any, m *reflectx.Mapper) (string, []any, error)

BindStruct 将命名参数查询与结构体参数的字段绑定。

func CompileNamedQuery

func CompileNamedQuery(qs []byte, bindType int) (query string, names []string, err error)

CompileNamedQuery 将命名查询编译为未绑定的查询和名称列表。

func FixBound

func FixBound(bound string, loop int) string

FixBound 修复多行插入时的 VALUES 占位符。 内部通过词法分析定位 VALUES 的括号区间,替代正则匹配。

func GetContext

func GetContext(ctx context.Context, q QueryerContext, dest any, query string, args ...any) error

GetContext 使用提供的 Queryer 执行 QueryRow,并将结果行扫描到 dest 中。

func IsUnsafe

func IsUnsafe(i any) bool

IsUnsafe 判断扩展类型是否处于不安全模式。

func LoadFile

func LoadFile(e core.Execer, path string) (*sql.Result, error)

LoadFile 执行文件中的每条语句。

func LoadFileContext

func LoadFileContext(ctx context.Context, e ExecerContext, path string) (*sql.Result, error)

LoadFileContext 执行文件中的每条语句。

func MapperFor

func MapperFor(i any) *reflectx.Mapper

MapperFor 返回与给定接口关联的 Mapper。

func MustExecContext

func MustExecContext(ctx context.Context, e ExecerContext, query string, args ...any) sql.Result

MustExecContext 使用 e 执行查询,如果发生错误则 panic。

func Named

func Named(query string, arg any) (string, []any, error)

Named 接受使用命名参数的查询和一个参数, 返回一个带有参数列表的新查询,可供数据库执行。

func NamedExec

func NamedExec(e core.Ext, query string, arg any) (sql.Result, error)

NamedExec 使用 BindStruct 获取可执行的查询并运行 Exec。

func NamedExecContext

func NamedExecContext(ctx context.Context, e ExtContext, query string, arg any) (sql.Result, error)

NamedExecContext 使用 BindStruct 获取可执行的查询并运行 Exec。

func NamedQuery

func NamedQuery(e core.Ext, query string, arg any) (*core.Rows, error)

NamedQuery 绑定命名查询并运行 Query。

func NamedQueryContext

func NamedQueryContext(ctx context.Context, e ExtContext, query string, arg any) (*core.Rows, error)

NamedQueryContext 绑定命名查询并运行 Query。

func SelectContext

func SelectContext(ctx context.Context, q QueryerContext, dest any, query string, args ...any) error

SelectContext 使用提供的 Queryer 执行查询,并将每行通过 StructScan 扫描到 dest 中。

func WithSetUnsafe

func WithSetUnsafe(u bool) func(*dbOptions)

WithSetUnsafe 返回一个选项,设置构建出的类型的不安全模式。

func WithUnsafe

func WithUnsafe() func(*dbOptions)

WithUnsafe 返回一个选项,使构建出的类型默认处于不安全模式。

Types

type Conn

type Conn struct {
	*sql.Conn

	Mapper *reflectx.Mapper
	// contains filtered or unexported fields
}

Conn 是 sql.Conn 的封装,提供额外的功能。

func (*Conn) BeginTxx

func (c *Conn) BeginTxx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

BeginTxx 开始一个事务并返回 *Tx 而不是 *sql.Tx。

func (*Conn) ExecContext

func (c *Conn) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

ExecContext 在 Conn 和 context 中执行查询并记录 SQL 日志(仅 debug 模式)。

func (*Conn) GetContext

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

GetContext 使用此 Conn 获取单条记录。

func (*Conn) PreparexContext

func (c *Conn) PreparexContext(ctx context.Context, query string) (*Stmt, error)

PreparexContext 返回 Stmt 而不是 sql.Stmt。

func (*Conn) QueryContext

func (c *Conn) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)

QueryContext 在 Conn 和 context 中执行查询并记录 SQL 日志(仅 debug 模式)。

func (*Conn) QueryRowContext

func (c *Conn) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row

QueryRowContext 在 Conn 和 context 中执行查询并记录 SQL 日志(仅 debug 模式)。

func (*Conn) QueryRowxContext

func (c *Conn) QueryRowxContext(ctx context.Context, query string, args ...any) *core.Row

QueryRowxContext 查询数据库并返回 *Row。

func (*Conn) QueryxContext

func (c *Conn) QueryxContext(ctx context.Context, query string, args ...any) (*core.Rows, error)

QueryxContext 查询数据库并返回 *Rows。

func (*Conn) Rebind

func (c *Conn) Rebind(query string) string

Rebind 在 Conn 的绑定变量类型下重绑定查询。

func (*Conn) SelectContext

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

SelectContext 使用此 Conn 进行查询。

type DB

type DB struct {
	*sql.DB

	Mapper *reflectx.Mapper
	// contains filtered or unexported fields
}

DB 是 sql.DB 的封装,在 Open 时记录 driverName, 主要用于使用正确的绑定变量自动绑定命名查询。

func Connect

func Connect(driverName, dataSourceName string, args ...func(*dbOptions)) (*DB, error)

Connect 连接到数据库并通过 ping 验证连接。

func ConnectContext

func ConnectContext(ctx context.Context, driverName, dataSourceName string, args ...func(*dbOptions)) (*DB, error)

ConnectContext 连接到数据库并通过 ping 验证连接。

func MustConnect

func MustConnect(driverName, dataSourceName string, args ...func(*dbOptions)) *DB

MustConnect 连接到数据库并在出错时 panic。

func MustOpen

func MustOpen(driverName, dataSourceName string, args ...func(*dbOptions)) *DB

MustOpen 与 sql.Open 相同,但返回 *dbx.DB 并在出错时 panic。

func NewDb

func NewDb(d *sql.DB, driverName string, args ...func(*dbOptions)) *DB

NewDb 为已存在的 *sql.DB 返回一个新的 dbx DB 封装。

func Open

func Open(driverName, dataSourceName string, args ...func(*dbOptions)) (*DB, error)

Open 与 sql.Open 相同,但返回 *dbx.DB。

func (*DB) BeginTxx

func (db *DB) BeginTxx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

BeginTxx 开始一个事务并返回 *Tx 而不是 *sql.Tx。

func (*DB) Beginx

func (db *DB) Beginx() (*Tx, error)

Beginx 开始一个事务并返回 *Tx 而不是 *sql.Tx。

func (*DB) BindNamed

func (db *DB) BindNamed(query string, arg any) (string, []any, error)

BindNamed 使用 DB 驱动程序的绑定变量类型绑定查询。

func (*DB) Connx

func (db *DB) Connx(ctx context.Context) (*Conn, error)

Connx 返回 *Conn 而不是 *sql.Conn。

func (*DB) DriverName

func (db *DB) DriverName() string

DriverName 返回传递给此 DB 的 Open 函数的 driverName。

func (*DB) Exec

func (db *DB) Exec(query string, args ...any) (sql.Result, error)

Exec 执行查询并记录 SQL 日志(仅 debug 模式)。

func (*DB) ExecContext

func (db *DB) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

ExecContext 在 context 下执行查询并记录 SQL 日志(仅 debug 模式)。

func (*DB) Get

func (db *DB) Get(dest any, query string, args ...any) error

Get 使用此 DB 获取单条记录。

func (*DB) GetContext

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

GetContext 使用此 DB 获取单条记录。

func (*DB) MapperFunc

func (db *DB) MapperFunc(mf func(string) string)

MapperFunc 为此 DB 设置一个新的 Mapper。

func (*DB) MustBegin

func (db *DB) MustBegin() *Tx

MustBegin 开始一个事务,出错时 panic。

func (*DB) MustBeginTx

func (db *DB) MustBeginTx(ctx context.Context, opts *sql.TxOptions) *Tx

MustBeginTx 开始一个事务,出错时 panic。

func (*DB) MustExec

func (db *DB) MustExec(query string, args ...any) sql.Result

MustExec 使用此数据库运行 MustExec,出错时 panic。

func (*DB) MustExecContext

func (db *DB) MustExecContext(ctx context.Context, query string, args ...any) sql.Result

MustExecContext 使用此数据库运行 MustExec,出错时 panic。

func (*DB) NamedExec

func (db *DB) NamedExec(query string, arg any) (sql.Result, error)

NamedExec 使用此 DB 执行命名查询。

func (*DB) NamedExecContext

func (db *DB) NamedExecContext(ctx context.Context, query string, arg any) (sql.Result, error)

NamedExecContext 使用此 DB 执行命名查询。

func (*DB) NamedQuery

func (db *DB) NamedQuery(query string, arg any) (*core.Rows, error)

NamedQuery 使用此 DB 进行命名查询。

func (*DB) NamedQueryContext

func (db *DB) NamedQueryContext(ctx context.Context, query string, arg any) (*core.Rows, error)

NamedQueryContext 使用此 DB 进行命名查询。

func (*DB) PrepareNamed

func (db *DB) PrepareNamed(query string) (*NamedStmt, error)

PrepareNamed 返回 NamedStmt。

func (*DB) PrepareNamedContext

func (db *DB) PrepareNamedContext(ctx context.Context, query string) (*NamedStmt, error)

PrepareNamedContext 返回 NamedStmt。

func (*DB) Preparex

func (db *DB) Preparex(query string) (*Stmt, error)

Preparex 返回 Stmt 而不是 sql.Stmt。

func (*DB) PreparexContext

func (db *DB) PreparexContext(ctx context.Context, query string) (*Stmt, error)

PreparexContext 返回 Stmt 而不是 sql.Stmt。

func (*DB) Query

func (db *DB) Query(query string, args ...any) (*sql.Rows, error)

Query 执行查询并记录 SQL 日志(仅 debug 模式)。

func (*DB) QueryContext

func (db *DB) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)

QueryContext 在 context 下执行查询并记录 SQL 日志(仅 debug 模式)。

func (*DB) QueryRow

func (db *DB) QueryRow(query string, args ...any) *sql.Row

QueryRow 执行查询并记录 SQL 日志(仅 debug 模式)。

func (*DB) QueryRowContext

func (db *DB) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row

QueryRowContext 在 context 下执行查询并记录 SQL 日志(仅 debug 模式)。

func (*DB) QueryRowx

func (db *DB) QueryRowx(query string, args ...any) *core.Row

QueryRowx 查询数据库并返回 *Row。

func (*DB) QueryRowxContext

func (db *DB) QueryRowxContext(ctx context.Context, query string, args ...any) *core.Row

QueryRowxContext 查询数据库并返回 *Row。

func (*DB) Queryx

func (db *DB) Queryx(query string, args ...any) (*core.Rows, error)

Queryx 查询数据库并返回 *Rows。

func (*DB) QueryxContext

func (db *DB) QueryxContext(ctx context.Context, query string, args ...any) (*core.Rows, error)

QueryxContext 查询数据库并返回 *Rows。

func (*DB) Rebind

func (db *DB) Rebind(query string) string

Rebind 将查询从 QUESTION 转换为 DB 驱动程序对应的绑定变量类型。

func (*DB) Select

func (db *DB) Select(dest any, query string, args ...any) error

Select 使用此 DB 进行查询。

func (*DB) SelectContext

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

SelectContext 使用此 DB 进行查询。

func (*DB) SetUnsafe

func (db *DB) SetUnsafe(u bool)

SetUnsafe 设置 DB 的不安全模式。供测试使用。

func (*DB) Unsafe

func (db *DB) Unsafe() *DB

Unsafe 返回一个 DB 的版本,当 SQL 结果中的列在目标结构体中 没有对应字段时,会静默地扫描成功。

type ExecerContext

type ExecerContext interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

ExecerContext 是带 Context 的执行接口。

type ExtContext

type ExtContext interface {
	core.Binder
	QueryerContext
	ExecerContext
}

ExtContext 是带 Context 的联合接口,可以绑定、查询和执行。

type NamedStmt

type NamedStmt struct {
	Params      []string
	QueryString string
	Stmt        *Stmt
}

NamedStmt 是一个执行命名查询的预编译语句。

func (*NamedStmt) Close

func (n *NamedStmt) Close() error

Close 关闭命名语句。

func (*NamedStmt) Exec

func (n *NamedStmt) Exec(arg any) (sql.Result, error)

Exec 使用传入的结构体执行命名语句。

func (*NamedStmt) ExecContext

func (n *NamedStmt) ExecContext(ctx context.Context, arg any) (sql.Result, error)

ExecContext 使用传入的结构体执行命名语句。

func (*NamedStmt) Get

func (n *NamedStmt) Get(dest any, arg any) error

Get 使用此 NamedStmt 获取单条记录。

func (*NamedStmt) GetContext

func (n *NamedStmt) GetContext(ctx context.Context, dest any, arg any) error

GetContext 使用此 NamedStmt 获取单条记录。

func (*NamedStmt) MustExec

func (n *NamedStmt) MustExec(arg any) sql.Result

MustExec 执行 NamedStmt,出错时 panic。

func (*NamedStmt) MustExecContext

func (n *NamedStmt) MustExecContext(ctx context.Context, arg any) sql.Result

MustExecContext 执行 NamedStmt,出错时 panic。

func (*NamedStmt) Query

func (n *NamedStmt) Query(arg any) (*sql.Rows, error)

Query 使用结构体参数执行命名语句,返回行。

func (*NamedStmt) QueryContext

func (n *NamedStmt) QueryContext(ctx context.Context, arg any) (*sql.Rows, error)

QueryContext 使用结构体参数执行命名语句,返回行。

func (*NamedStmt) QueryRow

func (n *NamedStmt) QueryRow(arg any) *core.Row

QueryRow 对数据库执行命名语句,返回 *Row。

func (*NamedStmt) QueryRowContext

func (n *NamedStmt) QueryRowContext(ctx context.Context, arg any) *core.Row

QueryRowContext 对数据库执行命名语句。

func (*NamedStmt) QueryRowx

func (n *NamedStmt) QueryRowx(arg any) *core.Row

QueryRowx 使用此 NamedStmt。

func (*NamedStmt) QueryRowxContext

func (n *NamedStmt) QueryRowxContext(ctx context.Context, arg any) *core.Row

QueryRowxContext 使用此 NamedStmt。

func (*NamedStmt) Queryx

func (n *NamedStmt) Queryx(arg any) (*core.Rows, error)

Queryx 使用此 NamedStmt 查询。

func (*NamedStmt) QueryxContext

func (n *NamedStmt) QueryxContext(ctx context.Context, arg any) (*core.Rows, error)

QueryxContext 使用此 NamedStmt 查询。

func (*NamedStmt) Select

func (n *NamedStmt) Select(dest any, arg any) error

Select 使用此 NamedStmt 查询。

func (*NamedStmt) SelectContext

func (n *NamedStmt) SelectContext(ctx context.Context, dest any, arg any) error

SelectContext 使用此 NamedStmt 查询。

func (*NamedStmt) Unsafe

func (n *NamedStmt) Unsafe() *NamedStmt

Unsafe 创建 NamedStmt 的不安全版本。

type PreparerContext

type PreparerContext interface {
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
}

PreparerContext 是带 Context 的预编译接口。

type QStmt

type QStmt struct{ *Stmt }

QStmt 是一个封装,通过实现 Queryer 和 Execer 接口使 Stmt 可复用。

func (*QStmt) Exec

func (q *QStmt) Exec(query string, args ...any) (sql.Result, error)

func (*QStmt) ExecContext

func (q *QStmt) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

func (*QStmt) Query

func (q *QStmt) Query(query string, args ...any) (*sql.Rows, error)

func (*QStmt) QueryContext

func (q *QStmt) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)

func (*QStmt) QueryRowx

func (q *QStmt) QueryRowx(query string, args ...any) *core.Row

func (*QStmt) QueryRowxContext

func (q *QStmt) QueryRowxContext(ctx context.Context, query string, args ...any) *core.Row

func (*QStmt) Queryx

func (q *QStmt) Queryx(query string, args ...any) (*core.Rows, error)

func (*QStmt) QueryxContext

func (q *QStmt) QueryxContext(ctx context.Context, query string, args ...any) (*core.Rows, error)

type Queryable

type Queryable interface {
	core.Ext
	ExecerContext
	PreparerContext
	QueryerContext
	core.Preparer

	GetContext(context.Context, any, string, ...any) error
	SelectContext(context.Context, any, string, ...any) error
	Get(any, string, ...any) error
	MustExecContext(context.Context, string, ...any) sql.Result
	PreparexContext(context.Context, string) (*Stmt, error)
	QueryRowContext(context.Context, string, ...any) *sql.Row
	Select(any, string, ...any) error
	QueryRow(string, ...any) *sql.Row
	PrepareNamedContext(context.Context, string) (*NamedStmt, error)
	PrepareNamed(string) (*NamedStmt, error)
	Preparex(string) (*Stmt, error)
	NamedExec(string, any) (sql.Result, error)
	NamedExecContext(context.Context, string, any) (sql.Result, error)
	MustExec(string, ...any) sql.Result
	NamedQuery(string, any) (*core.Rows, error)
	NamedQueryContext(context.Context, string, any) (*core.Rows, error)
}

Queryable 是统一 DB 与 Tx 的联合接口,二者均可作为查询执行器互换使用。

type QueryerContext

type QueryerContext interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryxContext(ctx context.Context, query string, args ...any) (*core.Rows, error)
	QueryRowxContext(ctx context.Context, query string, args ...any) *core.Row
}

QueryerContext 是带 Context 的查询接口。

type Stmt

type Stmt struct {
	*sql.Stmt

	Mapper *reflectx.Mapper
	// contains filtered or unexported fields
}

Stmt 是 sql.Stmt 的 dbx 封装,提供额外的功能。

func Preparex

func Preparex(p core.Preparer, query string) (*Stmt, error)

Preparex 预编译一条语句。

func PreparexContext

func PreparexContext(ctx context.Context, p PreparerContext, query string) (*Stmt, error)

PreparexContext 预编译一条语句。

func (*Stmt) Get

func (s *Stmt) Get(dest any, args ...any) error

Get 使用预编译语句获取单条记录。

func (*Stmt) GetContext

func (s *Stmt) GetContext(ctx context.Context, dest any, args ...any) error

GetContext 使用预编译语句获取单条记录。

func (*Stmt) MustExec

func (s *Stmt) MustExec(args ...any) sql.Result

MustExec 使用此语句执行,出错时 panic。

func (*Stmt) MustExecContext

func (s *Stmt) MustExecContext(ctx context.Context, args ...any) sql.Result

MustExecContext 使用此语句执行,出错时 panic。

func (*Stmt) QueryRowx

func (s *Stmt) QueryRowx(args ...any) *core.Row

QueryRowx 使用此语句查询单行。

func (*Stmt) QueryRowxContext

func (s *Stmt) QueryRowxContext(ctx context.Context, args ...any) *core.Row

QueryRowxContext 使用此语句查询单行。

func (*Stmt) Queryx

func (s *Stmt) Queryx(args ...any) (*core.Rows, error)

Queryx 使用此语句查询。

func (*Stmt) QueryxContext

func (s *Stmt) QueryxContext(ctx context.Context, args ...any) (*core.Rows, error)

QueryxContext 使用此语句查询。

func (*Stmt) Select

func (s *Stmt) Select(dest any, args ...any) error

Select 使用预编译语句进行查询。

func (*Stmt) SelectContext

func (s *Stmt) SelectContext(ctx context.Context, dest any, args ...any) error

SelectContext 使用预编译语句进行查询。

func (*Stmt) Unsafe

func (s *Stmt) Unsafe() *Stmt

Unsafe 返回一个 Stmt 的不安全版本。

type Tx

type Tx struct {
	*sql.Tx

	Mapper *reflectx.Mapper
	// contains filtered or unexported fields
}

Tx 是 sql.Tx 的 dbx 封装,提供额外的功能。

func (*Tx) BindNamed

func (tx *Tx) BindNamed(query string, arg any) (string, []any, error)

BindNamed 在事务的绑定变量类型下绑定查询。

func (*Tx) DriverName

func (tx *Tx) DriverName() string

DriverName 返回启动此事务的 DB 所使用的 driverName。

func (*Tx) Exec

func (tx *Tx) Exec(query string, args ...any) (sql.Result, error)

Exec 在事务中执行查询并记录 SQL 日志(仅 debug 模式)。

func (*Tx) ExecContext

func (tx *Tx) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

ExecContext 在事务和 context 中执行查询并记录 SQL 日志(仅 debug 模式)。

func (*Tx) Get

func (tx *Tx) Get(dest any, query string, args ...any) error

Get 在事务中获取单条记录。

func (*Tx) GetContext

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

GetContext 在事务和 context 中获取单条记录。

func (*Tx) MustExec

func (tx *Tx) MustExec(query string, args ...any) sql.Result

MustExec 在事务中运行 MustExec。

func (*Tx) MustExecContext

func (tx *Tx) MustExecContext(ctx context.Context, query string, args ...any) sql.Result

MustExecContext 在事务中运行 MustExecContext。

func (*Tx) NamedExec

func (tx *Tx) NamedExec(query string, arg any) (sql.Result, error)

NamedExec 在事务中执行命名查询。

func (*Tx) NamedExecContext

func (tx *Tx) NamedExecContext(ctx context.Context, query string, arg any) (sql.Result, error)

NamedExecContext 在事务和 context 中执行命名查询。

func (*Tx) NamedQuery

func (tx *Tx) NamedQuery(query string, arg any) (*core.Rows, error)

NamedQuery 在事务中执行命名查询。

func (*Tx) NamedQueryContext

func (tx *Tx) NamedQueryContext(ctx context.Context, query string, arg any) (*core.Rows, error)

NamedQueryContext 在事务和 context 中执行命名查询。

func (*Tx) NamedStmt

func (tx *Tx) NamedStmt(stmt *NamedStmt) *NamedStmt

NamedStmt 返回在事务中运行的命名预编译语句版本。

func (*Tx) NamedStmtContext

func (tx *Tx) NamedStmtContext(ctx context.Context, stmt *NamedStmt) *NamedStmt

NamedStmtContext 返回在事务中运行的命名预编译语句版本。

func (*Tx) PrepareNamed

func (tx *Tx) PrepareNamed(query string) (*NamedStmt, error)

PrepareNamed 返回 NamedStmt。

func (*Tx) PrepareNamedContext

func (tx *Tx) PrepareNamedContext(ctx context.Context, query string) (*NamedStmt, error)

PrepareNamedContext 返回 NamedStmt。

func (*Tx) Preparex

func (tx *Tx) Preparex(query string) (*Stmt, error)

Preparex 在事务中准备语句。

func (*Tx) PreparexContext

func (tx *Tx) PreparexContext(ctx context.Context, query string) (*Stmt, error)

PreparexContext 返回 Stmt 而不是 sql.Stmt。

func (*Tx) Query

func (tx *Tx) Query(query string, args ...any) (*sql.Rows, error)

Query 在事务中执行查询并记录 SQL 日志(仅 debug 模式)。

func (*Tx) QueryContext

func (tx *Tx) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)

QueryContext 在事务和 context 中执行查询并记录 SQL 日志(仅 debug 模式)。

func (*Tx) QueryRow

func (tx *Tx) QueryRow(query string, args ...any) *sql.Row

QueryRow 在事务中执行查询并记录 SQL 日志(仅 debug 模式)。

func (*Tx) QueryRowContext

func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row

QueryRowContext 在事务和 context 中执行查询并记录 SQL 日志(仅 debug 模式)。

func (*Tx) QueryRowx

func (tx *Tx) QueryRowx(query string, args ...any) *core.Row

QueryRowx 在事务中查询单行。

func (*Tx) QueryRowxContext

func (tx *Tx) QueryRowxContext(ctx context.Context, query string, args ...any) *core.Row

QueryRowxContext 在事务和 context 中查询单行。

func (*Tx) Queryx

func (tx *Tx) Queryx(query string, args ...any) (*core.Rows, error)

Queryx 在事务中查询。

func (*Tx) QueryxContext

func (tx *Tx) QueryxContext(ctx context.Context, query string, args ...any) (*core.Rows, error)

QueryxContext 在事务和 context 中查询。

func (*Tx) Rebind

func (tx *Tx) Rebind(query string) string

Rebind 在事务的绑定变量类型下重绑定查询。

func (*Tx) Select

func (tx *Tx) Select(dest any, query string, args ...any) error

Select 在事务中执行查询。

func (*Tx) SelectContext

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

SelectContext 在事务和 context 中查询。

func (*Tx) Stmtx

func (tx *Tx) Stmtx(stmt any) *Stmt

Stmtx 返回在事务中运行的预编译语句版本。

func (*Tx) StmtxContext

func (tx *Tx) StmtxContext(ctx context.Context, stmt any) *Stmt

StmtxContext 返回在事务中运行的预编译语句版本。

func (*Tx) Unsafe

func (tx *Tx) Unsafe() *Tx

Unsafe 返回一个 Tx 的不安全版本。

Jump to

Keyboard shortcuts

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