Documentation
¶
Index ¶
- Constants
- Variables
- type BindSqlArgsFunc
- type DbClient
- type DbClientConfig
- type DbClientOption
- type MsSqlDbClient
- func (client *MsSqlDbClient) ConnectionString() string
- func (client *MsSqlDbClient) CreateTransaction() (TransactionKeeper, error)
- func (client *MsSqlDbClient) Execute(sqlText string, args ...interface{}) (int64, error)
- func (client *MsSqlDbClient) ExecuteContext(ctx context.Context, sqlText string, args ...interface{}) (int64, error)
- func (client *MsSqlDbClient) Exists(sqlText string, args ...interface{}) (bool, error)
- func (client *MsSqlDbClient) ExistsContext(ctx context.Context, sqlText string, args ...interface{}) (bool, error)
- func (client *MsSqlDbClient) Get(sqlText string, args ...interface{}) (map[string]interface{}, error)
- func (client *MsSqlDbClient) GetContext(ctx context.Context, sqlText string, args ...interface{}) (map[string]interface{}, error)
- func (client *MsSqlDbClient) Rows(sqlText string, args ...interface{}) (*sqlen.EnhanceRows, error)
- func (client *MsSqlDbClient) RowsContext(ctx context.Context, sqlText string, args ...interface{}) (*sqlen.EnhanceRows, error)
- func (client *MsSqlDbClient) Scalar(sqlText string, args ...interface{}) (interface{}, error)
- func (client *MsSqlDbClient) ScalarContext(ctx context.Context, sqlText string, args ...interface{}) (interface{}, error)
- func (client *MsSqlDbClient) SizedExecute(expectedSize int64, sqlText string, args ...interface{}) error
- func (client *MsSqlDbClient) SizedExecuteContext(ctx context.Context, expectedSize int64, sqlText string, args ...interface{}) error
- func (client *MsSqlDbClient) SliceGet(sqlText string, args ...interface{}) ([]map[string]interface{}, error)
- func (client *MsSqlDbClient) SliceGetContext(ctx context.Context, sqlText string, args ...interface{}) ([]map[string]interface{}, error)
- type MySqlDbClient
- func (client *MySqlDbClient) ConnectionString() string
- func (client *MySqlDbClient) CreateTransaction() (TransactionKeeper, error)
- func (client *MySqlDbClient) Execute(sqlText string, args ...interface{}) (int64, error)
- func (client *MySqlDbClient) ExecuteContext(ctx context.Context, sqlText string, args ...interface{}) (int64, error)
- func (client *MySqlDbClient) Exists(sqlText string, args ...interface{}) (bool, error)
- func (client *MySqlDbClient) ExistsContext(ctx context.Context, sqlText string, args ...interface{}) (bool, error)
- func (client *MySqlDbClient) Get(sqlText string, args ...interface{}) (map[string]interface{}, error)
- func (client *MySqlDbClient) GetContext(ctx context.Context, sqlText string, args ...interface{}) (map[string]interface{}, error)
- func (client *MySqlDbClient) Rows(sqlText string, args ...interface{}) (*sqlen.EnhanceRows, error)
- func (client *MySqlDbClient) RowsContext(ctx context.Context, sqlText string, args ...interface{}) (*sqlen.EnhanceRows, error)
- func (client *MySqlDbClient) Scalar(sqlText string, args ...interface{}) (interface{}, error)
- func (client *MySqlDbClient) ScalarContext(ctx context.Context, sqlText string, args ...interface{}) (interface{}, error)
- func (client *MySqlDbClient) SizedExecute(expectedSize int64, sqlText string, args ...interface{}) error
- func (client *MySqlDbClient) SizedExecuteContext(ctx context.Context, expectedSize int64, sqlText string, args ...interface{}) error
- func (client *MySqlDbClient) SliceGet(sqlText string, args ...interface{}) ([]map[string]interface{}, error)
- func (client *MySqlDbClient) SliceGetContext(ctx context.Context, sqlText string, args ...interface{}) ([]map[string]interface{}, error)
- type TransactionKeeper
Constants ¶
const ( SqlServeDriver = "sqlserver" // SqlServer 驱动名称。 MySqlDriver = "mysql" // MsSql 驱动名称。 )
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 BindSqlArgsFunc ¶
BindSqlArgsFunc 定义用于预处理 sql 语句与参数的函数。
type DbClient ¶
type DbClient interface {
// CreateTransaction 用于开始一个事务。
CreateTransaction() (TransactionKeeper, error)
// ConnectionString 用于获取当前实例所使用的数据库连接字符串。
ConnectionString() string
// Scalar 用于获取查询的第一行第一列的值。
Scalar(sqlText string, args ...interface{}) (interface{}, error)
// ScalarContext 用于获取查询的第一行第一列的值。
ScalarContext(context context.Context, sqlText string, args ...interface{}) (interface{}, error)
// Execute 用于执行非查询SQL语句,并返回所影响的行数。
Execute(sqlText string, args ...interface{}) (int64, error)
// ExecuteContext 用于执行非查询SQL语句,并返回所影响的行数。
ExecuteContext(context context.Context, sqlText string, args ...interface{}) (int64, error)
// SizedExecute 用于执行非查询SQL语句,并断言所影响的行数。若影响的函数不正确,抛出异常。
SizedExecute(expectedSize int64, sqlText string, args ...interface{}) error
// SizedExecuteContext 用于执行非查询SQL语句,并断言所影响的行数。若影响的函数不正确,抛出异常。
SizedExecuteContext(context context.Context, expectedSize int64, sqlText string, args ...interface{}) error
// Exists 用于判断给定的查询的结果是否至少包含1行。
Exists(sqlText string, args ...interface{}) (bool, error)
// ExistsContext 用于判断给定的查询的结果是否至少包含1行。
ExistsContext(context context.Context, sqlText string, args ...interface{}) (bool, error)
// Get 用于获取查询结果的第一行记录。
Get(sqlText string, args ...interface{}) (map[string]interface{}, error)
// GetContext 用于获取查询结果的第一行记录。
GetContext(context context.Context, sqlText string, args ...interface{}) (map[string]interface{}, error)
// SliceGet 用于获取查询结果得行序列。
SliceGet(sqlText string, args ...interface{}) ([]map[string]interface{}, error)
// SliceGetContext 用于获取查询结果得行序列。
SliceGetContext(context context.Context, sqlText string, args ...interface{}) ([]map[string]interface{}, error)
// Rows 用于获取查询结果得行序列。
Rows(sqlText string, args ...interface{}) (*sqlen.EnhanceRows, error)
// RowsContext 用于获取查询结果得行序列。
RowsContext(context context.Context, sqlText string, args ...interface{}) (*sqlen.EnhanceRows, error)
}
DbClient 定义了数据库访问客户端。
type DbClientConfig ¶
type DbClientConfig struct {
// contains filtered or unexported fields
}
func NewDbClientConfig ¶
func NewDbClientConfig(driver string, connectionString string, options ...DbClientOption) *DbClientConfig
NewDbClientConfig 创建一个数据库连接配置。
type DbClientOption ¶
type DbClientOption func(config *DbClientConfig)
DbClientOption 是 DbClientConfig 的可选配置。
func WithBindArgsFunc ¶
func WithBindArgsFunc(argsFunc BindSqlArgsFunc) DbClientOption
WithBindArgsFunc 用于为 DbClientConfig 设置处理参数的函数。
func WithConnTimeout ¶
func WithConnTimeout(timeout time.Duration) DbClientOption
WithConnTimeout 用于为 DbClientConfig 设置获取数据库连接的超时时间。
func WithExecTimeout ¶
func WithExecTimeout(timeout time.Duration) DbClientOption
WithExecTimeout 用于为 DbClientConfig 设置默认的执行超时时间。
type MsSqlDbClient ¶
type MsSqlDbClient struct {
// contains filtered or unexported fields
}
MsSqlDbClient 是针对 SqlServer 的 DbClient 实现。
func NewMsSqlDbClient ¶
func NewMsSqlDbClient(connectionString string, options ...DbClientOption) (*MsSqlDbClient, error)
NewMsSqlDbClient 用于创建一个 MsSqlDbClient。
func (*MsSqlDbClient) ConnectionString ¶
func (client *MsSqlDbClient) ConnectionString() string
ConnectionString 用于获取当前实例所使用的数据库连接字符串。
func (*MsSqlDbClient) CreateTransaction ¶
func (client *MsSqlDbClient) CreateTransaction() (TransactionKeeper, error)
CreateTransaction 用于开始一个事务。
func (*MsSqlDbClient) ExecuteContext ¶
func (client *MsSqlDbClient) ExecuteContext(ctx context.Context, sqlText string, args ...interface{}) (int64, error)
ExecuteContext 用于执行非查询 sql 语句,并返回所影响的行数。
func (*MsSqlDbClient) ExistsContext ¶
func (client *MsSqlDbClient) ExistsContext(ctx context.Context, sqlText string, args ...interface{}) (bool, error)
ExistsContext 用于判断给定的查询的结果是否至少包含1行。
func (*MsSqlDbClient) Get ¶
func (client *MsSqlDbClient) Get(sqlText string, args ...interface{}) (map[string]interface{}, error)
Get 用于获取查询结果的第一行记录。
func (*MsSqlDbClient) GetContext ¶
func (client *MsSqlDbClient) GetContext(ctx context.Context, sqlText string, args ...interface{}) (map[string]interface{}, error)
GetContext 用于获取查询结果的第一行记录。
func (*MsSqlDbClient) Rows ¶
func (client *MsSqlDbClient) Rows(sqlText string, args ...interface{}) (*sqlen.EnhanceRows, error)
Rows 用于获取读取数据的游标 sql.Rows。
func (*MsSqlDbClient) RowsContext ¶
func (client *MsSqlDbClient) RowsContext(ctx context.Context, sqlText string, args ...interface{}) (*sqlen.EnhanceRows, error)
RowsContext 用于获取读取数据的游标 sql.Rows。
func (*MsSqlDbClient) ScalarContext ¶
func (client *MsSqlDbClient) ScalarContext(ctx context.Context, sqlText string, args ...interface{}) (interface{}, error)
ScalarContext 用于获取查询的第一行第一列的值。
func (*MsSqlDbClient) SizedExecute ¶
func (client *MsSqlDbClient) SizedExecute(expectedSize int64, sqlText string, args ...interface{}) error
SizedExecute 用于执行非查询 sql 语句,并断言所影响的行数。若影响的函数不正确,抛出异常。
func (*MsSqlDbClient) SizedExecuteContext ¶
func (client *MsSqlDbClient) SizedExecuteContext(ctx context.Context, expectedSize int64, sqlText string, args ...interface{}) error
SizedExecuteContext 用于执行非查询 sql 语句,并断言所影响的行数。若影响的函数不正确,抛出异常。
type MySqlDbClient ¶
type MySqlDbClient struct {
// contains filtered or unexported fields
}
MySqlDbClient 是针对 MySql 的 DbClient 实现。
func NewMySqlDbClient ¶
func NewMySqlDbClient(connectionString string, options ...DbClientOption) (*MySqlDbClient, error)
NewMySqlDbClient 用于创建一个 MySqlDbClient。
func (*MySqlDbClient) ConnectionString ¶
func (client *MySqlDbClient) ConnectionString() string
ConnectionString 用于获取当前实例所使用的数据库连接字符串。
func (*MySqlDbClient) CreateTransaction ¶
func (client *MySqlDbClient) CreateTransaction() (TransactionKeeper, error)
CreateTransaction 用于开始一个事务。
func (*MySqlDbClient) ExecuteContext ¶
func (client *MySqlDbClient) ExecuteContext(ctx context.Context, sqlText string, args ...interface{}) (int64, error)
ExecuteContext 用于执行非查询 sql 语句,并返回所影响的行数。
func (*MySqlDbClient) ExistsContext ¶
func (client *MySqlDbClient) ExistsContext(ctx context.Context, sqlText string, args ...interface{}) (bool, error)
ExistsContext 用于判断给定的查询的结果是否至少包含1行。
func (*MySqlDbClient) Get ¶
func (client *MySqlDbClient) Get(sqlText string, args ...interface{}) (map[string]interface{}, error)
Get 用于获取查询结果的第一行记录。
func (*MySqlDbClient) GetContext ¶
func (client *MySqlDbClient) GetContext(ctx context.Context, sqlText string, args ...interface{}) (map[string]interface{}, error)
GetContext 用于获取查询结果的第一行记录。
func (*MySqlDbClient) Rows ¶
func (client *MySqlDbClient) Rows(sqlText string, args ...interface{}) (*sqlen.EnhanceRows, error)
Rows 用于获取读取数据的游标 sql.Rows。
func (*MySqlDbClient) RowsContext ¶
func (client *MySqlDbClient) RowsContext(ctx context.Context, sqlText string, args ...interface{}) (*sqlen.EnhanceRows, error)
RowsContext 用于获取读取数据的游标 sql.Rows。
func (*MySqlDbClient) ScalarContext ¶
func (client *MySqlDbClient) ScalarContext(ctx context.Context, sqlText string, args ...interface{}) (interface{}, error)
ScalarContext 用于获取查询的第一行第一列的值。
func (*MySqlDbClient) SizedExecute ¶
func (client *MySqlDbClient) SizedExecute(expectedSize int64, sqlText string, args ...interface{}) error
SizedExecute 用于执行非查询 sql 语句,并断言所影响的行数。若影响的函数不正确,抛出异常。
func (*MySqlDbClient) SizedExecuteContext ¶
func (client *MySqlDbClient) SizedExecuteContext(ctx context.Context, expectedSize int64, sqlText string, args ...interface{}) error
SizedExecuteContext 用于执行非查询 sql 语句,并断言所影响的行数。若影响的函数不正确,抛出异常。