Documentation
¶
Index ¶
- type DbEnhance
- func (db *DbEnhance) EnhancedQuery(query string, args ...any) (*EnhanceRows, error)
- func (db *DbEnhance) EnhancedQueryContext(ctx context.Context, query string, args ...any) (*EnhanceRows, error)
- func (db *DbEnhance) EnhancedQueryRow(query string, args ...any) *EnhanceRow
- func (db *DbEnhance) EnhancedQueryRowContext(ctx context.Context, query string, args ...any) *EnhanceRow
- type DbExer
- type EnhanceRow
- type EnhanceRows
- type EnhancedDbExer
- type GetScanTypeFunc
- type TxEnhance
- func (tx *TxEnhance) EnhancedQuery(query string, args ...any) (*EnhanceRows, error)
- func (tx *TxEnhance) EnhancedQueryContext(ctx context.Context, query string, args ...any) (*EnhanceRows, error)
- func (tx *TxEnhance) EnhancedQueryRow(query string, args ...any) *EnhanceRow
- func (tx *TxEnhance) EnhancedQueryRowContext(ctx context.Context, query string, args ...any) *EnhanceRow
- type UnifyDataTypeFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DbEnhance ¶
DbEnhance 是对原生 sql.DB 的包装,除了原本的方法外,另外实现了 EnhancedDbExer 接口定义的额外方法。
func NewDbEnhance ¶
func NewDbEnhance(db *sql.DB, getScanTypeFn GetScanTypeFunc, unifyDataTypeFn UnifyDataTypeFn) *DbEnhance
func (*DbEnhance) EnhancedQuery ¶
func (db *DbEnhance) EnhancedQuery(query string, args ...any) (*EnhanceRows, error)
EnhancedQuery executes a query that returns rows. 返回增强后的 EnhanceRows 对象,相比原生 sql.Rows 提供了更强的数据读取能力。
func (*DbEnhance) EnhancedQueryContext ¶
func (db *DbEnhance) EnhancedQueryContext(ctx context.Context, query string, args ...any) (*EnhanceRows, error)
EnhancedQueryContext executes a query that returns rows. 返回增强后的 EnhanceRows 对象,相比原生 sql.Rows 提供了更强的数据读取能力。
func (*DbEnhance) EnhancedQueryRow ¶
func (db *DbEnhance) EnhancedQueryRow(query string, args ...any) *EnhanceRow
EnhancedQueryRow executes a query that is expected to return at most one row. 返回增强后的 EnhanceRow 对象,相比原生 sql.Row 提供了更强的数据读取能力。
func (*DbEnhance) EnhancedQueryRowContext ¶
func (db *DbEnhance) EnhancedQueryRowContext(ctx context.Context, query string, args ...any) *EnhanceRow
EnhancedQueryRowContext executes a query that is expected to return at most one row. 返回增强后的 EnhanceRow 对象,相比原生 sql.Row 提供了更强的数据读取能力。
type DbExer ¶
type DbExer interface {
// QueryRow executes a query that is expected to return at most one row.
// QueryRow always returns a non-nil value. Errors are deferred until
// Row's Scan method is called.
// If the query selects no rows, the *Row's Scan will return ErrNoRows.
// Otherwise, the *Row's Scan scans the first selected row and discards
// the rest.
QueryRow(query string, args ...any) *sql.Row
// QueryRowContext executes a query that is expected to return at most one row.
// QueryRowContext always returns a non-nil value. Errors are deferred until
// Row's Scan method is called.
// If the query selects no rows, the *Row's Scan will return ErrNoRows.
// Otherwise, the *Row's Scan scans the first selected row and discards
// the rest.
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
// Query executes a query that returns rows, typically a SELECT.
// The args are for any placeholder parameters in the query.
Query(query string, args ...any) (*sql.Rows, error)
// QueryContext executes a query that returns rows, typically a SELECT.
// The args are for any placeholder parameters in the query.
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
// Exec executes a query that doesn't return rows.
// For example: an INSERT and UPDATE.
Exec(query string, args ...any) (sql.Result, error)
// ExecContext executes a query without returning any rows.
// The args are for any placeholder parameters in the query.
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}
DbExer 是从 sql.Tx 和 sql.Db 对象上提取的公共数据库操纵接口。
type EnhanceRow ¶
type EnhanceRow struct {
// contains filtered or unexported fields
}
EnhanceRow 用于在 Enhanced 方法中替换元生的 sql.Row。 注意这里原生的 sql.Row 方法没有开放内部 sql.Rows 结构出来,这里直接通过内嵌 *EnhanceRows 实现。
func (*EnhanceRow) Err ¶
func (r *EnhanceRow) Err() error
func (*EnhanceRow) MapScan ¶
func (r *EnhanceRow) MapScan() (map[string]any, error)
MapScan 用于把一行数据填充到 map 中。
func (*EnhanceRow) SliceScan ¶
func (r *EnhanceRow) SliceScan() ([]any, error)
SliceScan 用 Slice 返回一行数据。
type EnhanceRows ¶
EnhanceRows 用于在 Enhanced 方法中替换元生的 sql.Rows。
func (*EnhanceRows) Err ¶
func (r *EnhanceRows) Err() error
func (*EnhanceRows) MapScan ¶
func (rs *EnhanceRows) MapScan() (map[string]any, error)
MapScan 用于把一行数据填充到 map 中。
func (*EnhanceRows) SliceScan ¶
func (rs *EnhanceRows) SliceScan() ([]any, error)
SliceScan 用 Slice 的方式返回一行数据。
type EnhancedDbExer ¶
type EnhancedDbExer interface {
DbExer
// EnhancedQueryRow executes a query that is expected to return at most one row.
// 返回增强后的 EnhanceRow 对象,相比原生 sql.Row 提供了更强的数据读取能力。
EnhancedQueryRow(query string, args ...any) *EnhanceRow
// EnhancedQueryRowContext executes a query that is expected to return at most one row.
// 返回增强后的 EnhanceRow 对象,相比原生 sql.Row 提供了更强的数据读取能力。
EnhancedQueryRowContext(ctx context.Context, query string, args ...any) *EnhanceRow
// EnhancedQuery executes a query that returns rows.
// 返回增强后的 EnhanceRows 对象,相比原生 sql.Rows 提供了更强的数据读取能力。
EnhancedQuery(query string, args ...any) (*EnhanceRows, error)
// EnhancedQueryContext executes a query that returns rows.
// 返回增强后的 EnhanceRows 对象,相比原生 sql.Rows 提供了更强的数据读取能力。
EnhancedQueryContext(ctx context.Context, query string, args ...any) (*EnhanceRows, error)
}
type GetScanTypeFunc ¶ added in v1.3.11
type GetScanTypeFunc func(columnType *sql.ColumnType) reflect.Type
GetScanTypeFunc 用于根据列的类型信息获取一个能用于 Scan 的 Go 类型。
type TxEnhance ¶
TxEnhance 是对原生 sql.Tx 的包装,除了原本的方法外,另外实现了 EnhancedDbExer 接口定义的额外方法。
func (*TxEnhance) EnhancedQuery ¶
func (tx *TxEnhance) EnhancedQuery(query string, args ...any) (*EnhanceRows, error)
EnhancedQuery executes a query that returns rows. 返回增强后的 EnhanceRows 对象,相比原生 sql.Rows 提供了更强的数据读取能力。
func (*TxEnhance) EnhancedQueryContext ¶
func (tx *TxEnhance) EnhancedQueryContext(ctx context.Context, query string, args ...any) (*EnhanceRows, error)
EnhancedQueryContext executes a query that returns rows. 返回增强后的 EnhanceRows 对象,相比原生 sql.Rows 提供了更强的数据读取能力。
func (*TxEnhance) EnhancedQueryRow ¶
func (tx *TxEnhance) EnhancedQueryRow(query string, args ...any) *EnhanceRow
EnhancedQueryRow executes a query that is expected to return at most one row. 返回增强后的 EnhanceRow 对象,相比原生 sql.Row 提供了更强的数据读取能力。
func (*TxEnhance) EnhancedQueryRowContext ¶
func (tx *TxEnhance) EnhancedQueryRowContext(ctx context.Context, query string, args ...any) *EnhanceRow
EnhancedQueryRowContext executes a query that is expected to return at most one row. 返回增强后的EnhanceRow对象,相比原生sql.Row提供了更强的数据读取能力。
type UnifyDataTypeFn ¶ added in v1.3.1
type UnifyDataTypeFn func(columnType *sql.ColumnType, dest *any)
用于统一不同驱动在 Go 中的映射类型。