mysql

package
v0.0.0-...-dfd9850 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsErrDupEntry

func IsErrDupEntry(err error) bool

IsErrDupEntry returns true if error code = 1062

func RunWithRetry

func RunWithRetry(ctx context.Context, retryCnt int, interval time.Duration, f func() error) error

RunWithRetry tries to run func in specified count

Types

type DBAccessor

type DBAccessor interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

DBAccessor can be txn snapshot or db it self

type DBConnect

type DBConnect struct {
	sync.Mutex
	// contains filtered or unexported fields
}

DBConnect wraps db

func OpenDB

func OpenDB(dsn string, maxIdleConns int) (*DBConnect, error)

OpenDB opens db

func (*DBConnect) Begin

func (conn *DBConnect) Begin() error

Begin a transaction

func (*DBConnect) CloseDB

func (conn *DBConnect) CloseDB() error

CloseDB turn off db connection

func (*DBConnect) Commit

func (conn *DBConnect) Commit() error

Commit a transaction

func (*DBConnect) Exec

func (conn *DBConnect) Exec(query string, args ...interface{}) (sql.Result, error)

Exec execute sql

func (*DBConnect) GetBeginTime

func (conn *DBConnect) GetBeginTime() time.Time

GetBeginTime get the begin time of a transaction if not in transaction, return 0

func (*DBConnect) GetDB

func (conn *DBConnect) GetDB() *sql.DB

GetDB get real db object

func (*DBConnect) GetDBAccessor

func (conn *DBConnect) GetDBAccessor() DBAccessor

GetDBAccessor get DBAccessor interface

func (*DBConnect) GetTiDBTS

func (conn *DBConnect) GetTiDBTS() (uint64, error)

GetTiDBTS get the txn begin timestamp from TiDB

func (*DBConnect) IfTxn

func (conn *DBConnect) IfTxn() bool

IfTxn show if in a transaction

func (*DBConnect) MustExec

func (conn *DBConnect) MustExec(query string, args ...interface{}) sql.Result

MustExec must execute sql or fatal

func (*DBConnect) Query

func (conn *DBConnect) Query(query string, args ...interface{}) (*sql.Rows, error)

Query execute select statement

func (*DBConnect) ReConnect

func (conn *DBConnect) ReConnect() error

ReConnect rebuild connection

func (*DBConnect) Rollback

func (conn *DBConnect) Rollback() error

Rollback a transaction

Jump to

Keyboard shortcuts

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