Documentation
¶
Index ¶
- func AddConnection(dbName string, driverName string, connectionString string) error
- func AddConnectionByFun(dbNames []string, getConnection connectionFun)
- func ExecuteByTran(connectionName string, executeFun ExecuteFun) error
- func WriteExecError(command string, err error)
- func WritePrepareError(command string, err error)
- func WriteQueryError(command string, err error)
- func WriteScanError(command string, err error)
- func WriteTransactionError(command string, err error)
- type DbConnection
- func (this *DbConnection) Dispose()
- func (this *DbConnection) Execute(sql string, args ...interface{}) (int64, error)
- func (this *DbConnection) ExecuteList(sqlContent string, paramList [][]interface{}) (int64, error)
- func (this *DbConnection) GetDb() *sql.DB
- func (this *DbConnection) Init(driver string, connectionString string) error
- func (this *DbConnection) Name() string
- func (this *DbConnection) Query(sql string, args ...interface{}) (*sql.Rows, error)
- func (this *DbConnection) QueryRow(sql string, args ...interface{}) *sql.Row
- type DbTransaction
- type ExecuteFun
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddConnection ¶
添加数据库连接 dbName:数据库名 driverName:驱动名 connectionString:连接字符串 返回值: error:错误数据
func AddConnectionByFun ¶
func AddConnectionByFun(dbNames []string, getConnection connectionFun)
初始化数据库连接
func ExecuteByTran ¶
func ExecuteByTran(connectionName string, executeFun ExecuteFun) error
以事务方式执行 connectionName:连接名 executeFun:执行函数 返回值: error:执行的错误信息
func WriteExecError ¶
记录Exec错误 command:执行的SQL语句 err:错误对象
func WritePrepareError ¶
记录Prepare错误 command:执行的SQL语句 err:错误对象
func WriteQueryError ¶
记录Query错误 command:执行的SQL语句 err:错误对象
func WriteScanError ¶
记录Scan错误 command:执行的SQL语句 err:错误对象
func WriteTransactionError ¶
记录Query错误 command:执行的SQL语句 err:错误对象
Types ¶
type DbConnection ¶
type DbConnection struct {
// contains filtered or unexported fields
}
数据库连接结构体
func GetConnection ¶
func GetConnection(connectionName string) *DbConnection
获取连接对象 connectionName:连接名 *DbConnection:数据库连接工具类
func (*DbConnection) Execute ¶
func (this *DbConnection) Execute(sql string, args ...interface{}) (int64, error)
执行一条sql语句 sql:待执行的sql语句 args:参数 返回值: int64:影响记录数 error:错误信息
func (*DbConnection) ExecuteList ¶
func (this *DbConnection) ExecuteList(sqlContent string, paramList [][]interface{}) (int64, error)
批量执行sql语句(内部会采用事务提交) sqlContent:待执行的sql语句 paramList:sql语句对应的所有参数列表 返回值: int64:总共影响的记录集合 error:错误信息
func (*DbConnection) Init ¶
func (this *DbConnection) Init(driver string, connectionString string) error
初始化数据库连接信息 driver:驱动名 connectionString:链接字符串 返回值: error:初始化的错误信息
type DbTransaction ¶
type DbTransaction struct {
// contains filtered or unexported fields
}
type ExecuteFun ¶
type ExecuteFun func(tran *DbTransaction) (isCommit bool, errMsg error)
事务执行函数定义 tran:事务对象 返回值: bool:是否提交事务 error:错误信息