db

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

func GetDB

func GetDB(name *string, logger *log.Logger) *DB

GetDB 获得数据库连接 GetDB name 连接配置名称,如果不提供名称则使用默认连接 GetDB return 数据库连接,对象内置连接池操作,完成后无需手动关闭连接

func (*DB) Begin

func (db *DB) Begin() *Tx

Begin 开始事务 Begin return 事务对象,事务中的操作都在事务对象上操作,请务必在返回的事务对象上执行commit或rollback

func (*DB) Delete

func (db *DB) Delete(table string, wheres string, args ...interface{}) (int64, error)

Delete 删除数据 Delete return 返回影响的行数

func (*DB) Exec

func (db *DB) Exec(requestSql string, args ...interface{}) (int64, error)

Exec 执行SQL * requestSql SQL语句 * args SQL语句中问号变量的值,按顺序放在请求参数中 Exec return 如果是INSERT到含有自增字段的表中返回插入的自增ID,否则返回影响的行数

func (*DB) Insert

func (db *DB) Insert(table string, data map[string]interface{}) (int64, error)

Insert 插入数据 * table 表名 * data 数据对象(Key-Value格式) Insert return 如果是INSERT到含有自增字段的表中返回插入的自增ID,否则返回影响的行数

func (*DB) Query

func (db *DB) Query(requestSql string, args ...interface{}) ([]map[string]interface{}, error)

Query 查询 Query return 返回查询到的数据,对象数组格式

func (*DB) Replace

func (db *DB) Replace(table string, data map[string]interface{}) (int64, error)

Replace 替换数据 Replace return 如果是REPLACE到含有自增字段的表中返回插入的自增ID,否则返回影响的行数

func (*DB) Update

func (db *DB) Update(table string, data map[string]interface{}, wheres string, args ...interface{}) (int64, error)

Update 更新数据 * wheres 条件(SQL中WHERE后面的部分) Update return 返回影响的行数

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

func (*Tx) CheckFinished

func (tx *Tx) CheckFinished() error

CheckFinished 检查事务是否已经提交或回滚,如果事务没有结束则执行回滚操作

func (*Tx) Commit

func (tx *Tx) Commit() error

Commit 提交事务

func (*Tx) Delete

func (tx *Tx) Delete(table string, wheres string, args ...interface{}) (int64, error)

func (*Tx) Exec

func (tx *Tx) Exec(requestSql string, args ...interface{}) (int64, error)

func (*Tx) Finish

func (tx *Tx) Finish(ok bool) error

Finish 根据传入的成功标识提交或回滚事务 Finish ok 事务是否执行成功

func (*Tx) Insert

func (tx *Tx) Insert(table string, data map[string]interface{}) (int64, error)

func (*Tx) Query

func (tx *Tx) Query(requestSql string, args ...interface{}) ([]map[string]interface{}, error)

func (*Tx) Replace

func (tx *Tx) Replace(table string, data map[string]interface{}) (int64, error)

func (*Tx) Rollback

func (tx *Tx) Rollback() error

Rollback 回滚事务

func (*Tx) Update

func (tx *Tx) Update(table string, data map[string]interface{}, wheres string, args ...interface{}) (int64, error)

Jump to

Keyboard shortcuts

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