Documentation
¶
Index ¶
- Variables
- type AbstractDbClient
- func (client *AbstractDbClient) ConnectionString() string
- func (client *AbstractDbClient) CreateTransaction() (TransactionKeeper, error)
- func (client *AbstractDbClient) Execute(sqlText string, args ...interface{}) (int64, error)
- func (client *AbstractDbClient) ExecuteContext(ctx context.Context, sqlText string, args ...interface{}) (int64, error)
- func (client *AbstractDbClient) Exists(sqlText string, args ...interface{}) (bool, error)
- func (client *AbstractDbClient) ExistsContext(ctx context.Context, sqlText string, args ...interface{}) (bool, error)
- func (client *AbstractDbClient) Get(sqlText string, args ...interface{}) (map[string]interface{}, error)
- func (client *AbstractDbClient) GetContext(ctx context.Context, sqlText string, args ...interface{}) (map[string]interface{}, error)
- func (client *AbstractDbClient) MustCreateTransaction() TransactionKeeper
- func (client *AbstractDbClient) MustExecute(sqlText string, args ...interface{}) int64
- func (client *AbstractDbClient) MustExecuteContext(ctx context.Context, sqlText string, args ...interface{}) int64
- func (client *AbstractDbClient) MustExists(sqlText string, args ...interface{}) bool
- func (client *AbstractDbClient) MustExistsContext(ctx context.Context, sqlText string, args ...interface{}) bool
- func (client *AbstractDbClient) MustGet(sqlText string, args ...interface{}) map[string]interface{}
- func (client *AbstractDbClient) MustGetContext(ctx context.Context, sqlText string, args ...interface{}) map[string]interface{}
- func (client *AbstractDbClient) MustRow(sqlText string, args ...interface{}) *sqlen.EnhanceRow
- func (client *AbstractDbClient) MustRowContext(ctx context.Context, sqlText string, args ...interface{}) *sqlen.EnhanceRow
- func (client *AbstractDbClient) MustRows(sqlText string, args ...interface{}) *sqlen.EnhanceRows
- func (client *AbstractDbClient) MustRowsContext(ctx context.Context, sqlText string, args ...interface{}) *sqlen.EnhanceRows
- func (client *AbstractDbClient) MustScalar(sqlText string, args ...interface{}) (interface{}, bool)
- func (client *AbstractDbClient) MustScalarContext(ctx context.Context, sqlText string, args ...interface{}) (interface{}, bool)
- func (client *AbstractDbClient) MustSizedExecute(expectedSize int64, sqlText string, args ...interface{})
- func (client *AbstractDbClient) MustSizedExecuteContext(ctx context.Context, expectedSize int64, sqlText string, args ...interface{})
- func (client *AbstractDbClient) MustSliceGet(sqlText string, args ...interface{}) []map[string]interface{}
- func (client *AbstractDbClient) MustSliceGetContext(ctx context.Context, sqlText string, args ...interface{}) []map[string]interface{}
- func (client *AbstractDbClient) Row(sqlText string, args ...interface{}) (*sqlen.EnhanceRow, error)
- func (client *AbstractDbClient) RowContext(ctx context.Context, sqlText string, args ...interface{}) (*sqlen.EnhanceRow, error)
- func (client *AbstractDbClient) Rows(sqlText string, args ...interface{}) (*sqlen.EnhanceRows, error)
- func (client *AbstractDbClient) RowsContext(ctx context.Context, sqlText string, args ...interface{}) (*sqlen.EnhanceRows, error)
- func (client *AbstractDbClient) Scalar(sqlText string, args ...interface{}) (interface{}, bool, error)
- func (client *AbstractDbClient) ScalarContext(ctx context.Context, sqlText string, args ...interface{}) (interface{}, bool, error)
- func (client *AbstractDbClient) SizedExecute(expectedSize int64, sqlText string, args ...interface{}) error
- func (client *AbstractDbClient) SizedExecuteContext(ctx context.Context, expectedSize int64, sqlText string, args ...interface{}) error
- func (client *AbstractDbClient) SliceGet(sqlText string, args ...interface{}) ([]map[string]interface{}, error)
- func (client *AbstractDbClient) SliceGetContext(ctx context.Context, sqlText string, args ...interface{}) ([]map[string]interface{}, error)
- type BindSqlArgsFunc
- type DbClient
- type DbClientConfig
- type DbClientOption
- func WithBindArgsFunc(argsFunc BindSqlArgsFunc) DbClientOption
- func WithConnTimeout(timeout time.Duration) DbClientOption
- func WithConnectionString(driver string, connectionString string) DbClientOption
- func WithDb(db *sql.DB) DbClientOption
- func WithExecTimeout(timeout time.Duration) DbClientOption
- func WithPingCheck(withPingCheck bool) DbClientOption
- func WithUnifyDataTypeFunc(unifyDataType sqlen.UnifyDataTypeFn) DbClientOption
- type TransactionKeeper
Constants ¶
This section is empty.
Variables ¶
var ErrConnect = errors.New("sqlmer: connect")
ErrConnect 是数据库连接相关错误。
var ErrSql = errors.New("sqlmer: sql")
ErrSql 是SQL语句相关错误。
var ErrTran = errors.New("sqlmer: transaction")
ErrTran 是数据库事务相关错误。
Functions ¶
This section is empty.
Types ¶
type AbstractDbClient ¶ added in v1.2.0
type AbstractDbClient struct {
SqlDB *sql.DB // 内部依赖的连接池。
Exer sqlen.EnhancedDbExer // 获取方法实际使用的执行对象。
// contains filtered or unexported fields
}
AbstractDbClient 是一个 DbClient 的抽象实现。
func NewInternalDbClient ¶ added in v1.2.0
func NewInternalDbClient(config *DbClientConfig) (AbstractDbClient, error)
NewInternalDbClient 用于获取一个 internalDbClient 对象。
func (*AbstractDbClient) ConnectionString ¶ added in v1.2.0
func (client *AbstractDbClient) ConnectionString() string
ConnectionString 用于获取当前实例所使用的数据库连接字符串。
func (*AbstractDbClient) CreateTransaction ¶ added in v1.2.0
func (client *AbstractDbClient) CreateTransaction() (TransactionKeeper, error)
CreateTransaction 用于开始一个事务。
func (*AbstractDbClient) Execute ¶ added in v1.2.0
func (client *AbstractDbClient) Execute(sqlText string, args ...interface{}) (int64, error)
Execute 用于执行非查询SQL语句,并返回所影响的行数。
func (*AbstractDbClient) ExecuteContext ¶ added in v1.2.0
func (client *AbstractDbClient) ExecuteContext(ctx context.Context, sqlText string, args ...interface{}) (int64, error)
ExecuteContext 用于执行非查询 sql 语句,并返回所影响的行数。
func (*AbstractDbClient) Exists ¶ added in v1.2.0
func (client *AbstractDbClient) Exists(sqlText string, args ...interface{}) (bool, error)
Exists 用于判断给定的查询的结果是否至少包含 1 行。
func (*AbstractDbClient) ExistsContext ¶ added in v1.2.0
func (client *AbstractDbClient) ExistsContext(ctx context.Context, sqlText string, args ...interface{}) (bool, error)
ExistsContext 用于判断给定的查询的结果是否至少包含 1 行。
func (*AbstractDbClient) Get ¶ added in v1.2.0
func (client *AbstractDbClient) Get(sqlText string, args ...interface{}) (map[string]interface{}, error)
Get 用于获取查询结果的第一行记录。
func (*AbstractDbClient) GetContext ¶ added in v1.2.0
func (client *AbstractDbClient) GetContext(ctx context.Context, sqlText string, args ...interface{}) (map[string]interface{}, error)
GetContext 用于获取查询结果的第一行记录。
func (*AbstractDbClient) MustCreateTransaction ¶ added in v1.2.0
func (client *AbstractDbClient) MustCreateTransaction() TransactionKeeper
MustCreateTransaction 用于开始一个事务。
func (*AbstractDbClient) MustExecute ¶ added in v1.2.0
func (client *AbstractDbClient) MustExecute(sqlText string, args ...interface{}) int64
MustExecute 用于执行非查询 sql 语句,并返回所影响的行数。
func (*AbstractDbClient) MustExecuteContext ¶ added in v1.2.0
func (client *AbstractDbClient) MustExecuteContext(ctx context.Context, sqlText string, args ...interface{}) int64
MustExecuteContext 用于执行非查询 sql 语句,并返回所影响的行数。
func (*AbstractDbClient) MustExists ¶ added in v1.2.0
func (client *AbstractDbClient) MustExists(sqlText string, args ...interface{}) bool
MustExists 用于判断给定的查询的结果是否至少包含 1 行。 注意:当查询不到行时候,将返回 false,而不是 panic。
func (*AbstractDbClient) MustExistsContext ¶ added in v1.2.0
func (client *AbstractDbClient) MustExistsContext(ctx context.Context, sqlText string, args ...interface{}) bool
MustExistsContext 用于判断给定的查询的结果是否至少包含 1 行。 注意:当查询不到行时候,将返回 false,而不是 panic。
func (*AbstractDbClient) MustGet ¶ added in v1.2.0
func (client *AbstractDbClient) MustGet(sqlText string, args ...interface{}) map[string]interface{}
MustGet 用于获取查询结果的第一行记录。 注意:当查询不到行时候,将返回 nil,而不是 panic。
func (*AbstractDbClient) MustGetContext ¶ added in v1.2.0
func (client *AbstractDbClient) MustGetContext(ctx context.Context, sqlText string, args ...interface{}) map[string]interface{}
MustGetContext 用于获取查询结果的第一行记录。 注意:当查询不到行时候,将返回 nil,而不是 panic。
func (*AbstractDbClient) MustRow ¶ added in v1.2.0
func (client *AbstractDbClient) MustRow(sqlText string, args ...interface{}) *sqlen.EnhanceRow
MustRow 用于获取单个查询结果行。
func (*AbstractDbClient) MustRowContext ¶ added in v1.2.0
func (client *AbstractDbClient) MustRowContext(ctx context.Context, sqlText string, args ...interface{}) *sqlen.EnhanceRow
RowMustRowContextContext 用于获取单个查询结果行。
func (*AbstractDbClient) MustRows ¶ added in v1.2.0
func (client *AbstractDbClient) MustRows(sqlText string, args ...interface{}) *sqlen.EnhanceRows
MustRows 用于获取读取数据的游标 sql.Rows。
func (*AbstractDbClient) MustRowsContext ¶ added in v1.2.0
func (client *AbstractDbClient) MustRowsContext(ctx context.Context, sqlText string, args ...interface{}) *sqlen.EnhanceRows
MustRowsContext 用于获取读取数据的游标 sql.Rows。
func (*AbstractDbClient) MustScalar ¶ added in v1.2.0
func (client *AbstractDbClient) MustScalar(sqlText string, args ...interface{}) (interface{}, bool)
MustScalar 用于获取查询的第一行第一列的值。 注意,sql.ErrNoRows 不会引发 panic,而通过第二个返回值区分,当查询不到数据的时候第二个返回值将为 false,否则为 true。
func (*AbstractDbClient) MustScalarContext ¶ added in v1.2.0
func (client *AbstractDbClient) MustScalarContext(ctx context.Context, sqlText string, args ...interface{}) (interface{}, bool)
MustScalarContext 用于获取查询的第一行第一列的值。 注意,sql.ErrNoRows 不会引发 panic,而通过第二个返回值区分,当查询不到数据的时候第二个返回值将为 false,否则为 true。
func (*AbstractDbClient) MustSizedExecute ¶ added in v1.2.0
func (client *AbstractDbClient) MustSizedExecute(expectedSize int64, sqlText string, args ...interface{})
MustSizedExecute 用于执行非查询 sql 语句,并断言所影响的行数。
func (*AbstractDbClient) MustSizedExecuteContext ¶ added in v1.2.0
func (client *AbstractDbClient) MustSizedExecuteContext(ctx context.Context, expectedSize int64, sqlText string, args ...interface{})
MustSizedExecuteContext 用于执行非查询 sql 语句,并断言所影响的行数。
func (*AbstractDbClient) MustSliceGet ¶ added in v1.2.0
func (client *AbstractDbClient) MustSliceGet(sqlText string, args ...interface{}) []map[string]interface{}
MustSliceGet 用于获取查询结果得行序列。 注意:当查询不到行时候,将返回 nil,而不是 panic。
func (*AbstractDbClient) MustSliceGetContext ¶ added in v1.2.0
func (client *AbstractDbClient) MustSliceGetContext(ctx context.Context, sqlText string, args ...interface{}) []map[string]interface{}
MustSliceGetContext 用于获取查询结果得行序列。 注意:当查询不到行时候,将返回 nil,而不是 panic。
func (*AbstractDbClient) Row ¶ added in v1.2.0
func (client *AbstractDbClient) Row(sqlText string, args ...interface{}) (*sqlen.EnhanceRow, error)
Row 用于获取单个查询结果行。
func (*AbstractDbClient) RowContext ¶ added in v1.2.0
func (client *AbstractDbClient) RowContext(ctx context.Context, sqlText string, args ...interface{}) (*sqlen.EnhanceRow, error)
RowContext 用于获取单个查询结果行。
func (*AbstractDbClient) Rows ¶ added in v1.2.0
func (client *AbstractDbClient) Rows(sqlText string, args ...interface{}) (*sqlen.EnhanceRows, error)
Rows 用于获取读取数据的游标 sql.Rows。
func (*AbstractDbClient) RowsContext ¶ added in v1.2.0
func (client *AbstractDbClient) RowsContext(ctx context.Context, sqlText string, args ...interface{}) (*sqlen.EnhanceRows, error)
RowsContext 用于获取读取数据的游标 sql.Rows。
func (*AbstractDbClient) Scalar ¶ added in v1.2.0
func (client *AbstractDbClient) Scalar(sqlText string, args ...interface{}) (interface{}, bool, error)
Scalar 用于获取查询的第一行第一列的值。 注意,sql.ErrNoRows 不放 error 中返回,而通过第二个返回值区分,当查询不到数据的时候第二个返回值将为 false,否则为 true。
func (*AbstractDbClient) ScalarContext ¶ added in v1.2.0
func (client *AbstractDbClient) ScalarContext(ctx context.Context, sqlText string, args ...interface{}) (interface{}, bool, error)
ScalarContext 用于获取查询的第一行第一列的值。 注意,sql.ErrNoRows 不放 error 中返回,而通过第二个返回值区分,当查询不到数据的时候第二个返回值将为 false,否则为 true。
func (*AbstractDbClient) SizedExecute ¶ added in v1.2.0
func (client *AbstractDbClient) SizedExecute(expectedSize int64, sqlText string, args ...interface{}) error
SizedExecute 用于执行非查询 sql 语句,并断言所影响的行数。若影响的函数不正确,抛出异常。
func (*AbstractDbClient) SizedExecuteContext ¶ added in v1.2.0
func (client *AbstractDbClient) SizedExecuteContext(ctx context.Context, expectedSize int64, sqlText string, args ...interface{}) error
SizedExecuteContext 用于执行非查询 sql 语句,并断言所影响的行数。若影响的函数不正确,抛出异常。
func (*AbstractDbClient) SliceGet ¶ added in v1.2.0
func (client *AbstractDbClient) SliceGet(sqlText string, args ...interface{}) ([]map[string]interface{}, error)
SliceGet 用于获取查询结果得行序列。
func (*AbstractDbClient) SliceGetContext ¶ added in v1.2.0
func (client *AbstractDbClient) SliceGetContext(ctx context.Context, sqlText string, args ...interface{}) ([]map[string]interface{}, error)
SliceGetContext 用于获取查询结果得行序列。
type BindSqlArgsFunc ¶
BindSqlArgsFunc 定义用于预处理 sql 语句与参数的函数。
type DbClient ¶
type DbClient interface {
ConnectionString() string // ConnectionString 用于获取当前实例所使用的数据库连接字符串。
// contains filtered or unexported methods
}
DbClient 定义了数据库访问客户端。
type DbClientConfig ¶
type DbClientConfig struct {
// contains filtered or unexported fields
}
func NewDbClientConfig ¶
func NewDbClientConfig(options ...DbClientOption) (*DbClientConfig, error)
NewDbClientConfig 创建一个数据库连接配置。
type DbClientOption ¶
type DbClientOption func(config *DbClientConfig) error
DbClientOption 是 DbClientConfig 的可选配置。
func WithBindArgsFunc ¶
func WithBindArgsFunc(argsFunc BindSqlArgsFunc) DbClientOption
WithBindArgsFunc 用于为 DbClientConfig 设置处理参数的函数。
func WithConnTimeout ¶
func WithConnTimeout(timeout time.Duration) DbClientOption
WithConnTimeout 用于为 DbClientConfig 设置获取数据库连接的超时时间。
func WithConnectionString ¶ added in v1.2.0
func WithConnectionString(driver string, connectionString string) DbClientOption
WithConnectionString 用于用现有的 sql.DB 初始化 DbClientOption。
func WithDb ¶ added in v1.2.0
func WithDb(db *sql.DB) DbClientOption
WithDb 用于用现有的 sql.DB 初始化 DbClientOption。
func WithExecTimeout ¶
func WithExecTimeout(timeout time.Duration) DbClientOption
WithExecTimeout 用于为 DbClientConfig 设置默认的执行超时时间。
func WithPingCheck ¶ added in v1.2.0
func WithPingCheck(withPingCheck bool) DbClientOption
WithPingCheck 用于选择是否在初始化 DbClient 时候进行 ping 操作(默认为 false)。
func WithUnifyDataTypeFunc ¶ added in v1.3.1
func WithUnifyDataTypeFunc(unifyDataType sqlen.UnifyDataTypeFn) DbClientOption
WithUnifyDataTypeFunc 用于为 DbClient 注入驱动相关的类型转换逻辑。
type TransactionKeeper ¶
type TransactionKeeper interface {
DbClient // DbClient 实现了数据库访问客户端的功能。
// contains filtered or unexported methods
}
TransactionKeeper 是一个定义数据库事务容器。