dbs

package
v1.1.43 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: GPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const MaxConcatLen = "18446744073709551615"
View Source
const MaxIdleConns = 80
View Source
const MaxIdleTime = 30 * time.Minute
View Source
const MaxLifeTime = 30 * time.Minute
View Source
const MaxOpenConns = 256

Variables

This section is empty.

Functions

func NewMysqlConn

func NewMysqlConn(c *v1config.DBConfig, fs ...func(config *mysql.Config)) (*sql.DB, error)

Types

type DBMysql

type DBMysql struct {
	//db,正常操作db
	Edb *sql.DB

	//tx,初始为nil,开始事务后为对应事务上下文
	Etx *sql.Tx
}

func NewDBMysql

func NewDBMysql(c v1config.DBConfig, fs ...func(config *mysql.Config)) (*DBMysql, error)

func (*DBMysql) BeginTrans

func (d *DBMysql) BeginTrans() (IDBMysql, error)

func (*DBMysql) CommitTrans

func (d *DBMysql) CommitTrans() error

func (*DBMysql) DB

func (d *DBMysql) DB() *sql.DB

func (*DBMysql) ExecuteCreate

func (d *DBMysql) ExecuteCreate(tableName string, fields map[string]interface{}) (int64, error)

func (*DBMysql) ExecuteQuery

func (d *DBMysql) ExecuteQuery(tableName string, fields map[string]interface{}, whereArr []string, whereArgs []interface{}, orderBy []string) (bool, error)

func (*DBMysql) ExecuteSearch

func (d *DBMysql) ExecuteSearch(tableName string, fields []string, whereArr []string, whereArgs []interface{}, orderBy []string, pageNum, pageSize int64, rowsHandler SearchRowsHandler) (int64, int64, error)

func (*DBMysql) ExecuteUpdate

func (d *DBMysql) ExecuteUpdate(tableName string, fields map[string]interface{}, whereArr []string, whereArgs []interface{}) (int64, error)

func (*DBMysql) RollbackTrans

func (d *DBMysql) RollbackTrans() error

func (*DBMysql) TX

func (d *DBMysql) TX() *sql.Tx

func (*DBMysql) WithDB

func (d *DBMysql) WithDB(db *sql.DB) *DBMysql

type GormMysql

type GormMysql struct {
	//db,正常操作db,开始事务后为begin后的gorm
	Edb *gorm.DB

	//tx,初始为nil,开始事务后为对应事务上下文
	//可判断是否为nil来判断是否开始了事务
	Etx gorm.ConnPool
}

func NewGormMysql

func NewGormMysql(c *v1config.DBConfig, fs ...func(config *mysql.Config)) (*GormMysql, error)

NewGormMysql gorm的mysql操作db

func (*GormMysql) BeginTrans

func (d *GormMysql) BeginTrans() (IGormMysql, error)

func (*GormMysql) CommitTrans

func (d *GormMysql) CommitTrans() error

func (*GormMysql) DB

func (d *GormMysql) DB() *sql.DB

func (*GormMysql) ExecuteCreate

func (d *GormMysql) ExecuteCreate(tableName string, fields map[string]interface{}) (int64, error)

func (*GormMysql) ExecuteQuery

func (d *GormMysql) ExecuteQuery(tableName string, fields map[string]interface{}, whereArr []string, whereArgs []interface{}, orderBy []string) (bool, error)

func (*GormMysql) ExecuteSearch

func (d *GormMysql) ExecuteSearch(tableName string, fields []string, whereArr []string, whereArgs []interface{}, orderBy []string, pageNum, pageSize int64, rowsHandler SearchRowsHandler) (int64, int64, error)

func (*GormMysql) ExecuteUpdate

func (d *GormMysql) ExecuteUpdate(tableName string, fields map[string]interface{}, whereArr []string, whereArgs []interface{}) (int64, error)

func (*GormMysql) GormDB

func (d *GormMysql) GormDB() *gorm.DB

func (*GormMysql) GormTX

func (d *GormMysql) GormTX() gorm.ConnPool

func (*GormMysql) RollbackTrans

func (d *GormMysql) RollbackTrans() error

func (*GormMysql) WithDB

func (d *GormMysql) WithDB(db *gorm.DB) *GormMysql

type IDBMysql

type IDBMysql interface {
	DB() *sql.DB
	TX() *sql.Tx

	ExecuteSearch(tableName string, fields []string, whereArr []string, whereArgs []interface{}, orderBy []string, pageNum, pageSize int64, rowsHandler SearchRowsHandler) (int64, int64, error)
	ExecuteQuery(tableName string, fields map[string]interface{}, whereArr []string, whereArgs []interface{}, orderBy []string) (bool, error)
	ExecuteCreate(tableName string, fields map[string]interface{}) (int64, error)
	ExecuteUpdate(tableName string, fields map[string]interface{}, whereArr []string, whereArgs []interface{}) (int64, error)

	BeginTrans() (IDBMysql, error)
	CommitTrans() error
	RollbackTrans() error
}

type IGormMysql

type IGormMysql interface {
	DB() *sql.DB
	GormDB() *gorm.DB
	GormTX() gorm.ConnPool

	ExecuteSearch(tableName string, fields []string, whereArr []string, whereArgs []interface{}, orderBy []string, pageNum, pageSize int64, rowsHandler SearchRowsHandler) (int64, int64, error)
	ExecuteQuery(tableName string, fields map[string]interface{}, whereArr []string, whereArgs []interface{}, orderBy []string) (bool, error)
	ExecuteCreate(tableName string, fields map[string]interface{}) (int64, error)
	ExecuteUpdate(tableName string, fields map[string]interface{}, whereArr []string, whereArgs []interface{}) (int64, error)

	BeginTrans() (IGormMysql, error)
	CommitTrans() error
	RollbackTrans() error
}

type SearchRowsHandler

type SearchRowsHandler func(*sql.Rows) error

Jump to

Keyboard shortcuts

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