baseconn

package
v1.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseConn

type BaseConn struct {
	DB *sql.DB

	// for reset
	DSN string

	RetryStrategy retry.Strategy
}

BaseConn wraps a connection to DB

func NewBaseConn

func NewBaseConn(dbDSN string, strategy retry.Strategy) (*BaseConn, error)

NewBaseConn builds BaseConn to connect real DB

func (*BaseConn) ApplyRetryStrategy

func (conn *BaseConn) ApplyRetryStrategy(tctx *tcontext.Context, params retry.Params,
	operateFn func(*tcontext.Context) (interface{}, error)) (interface{}, int, error)

ApplyRetryStrategy apply specify strategy for BaseConn

func (*BaseConn) Close

func (conn *BaseConn) Close() error

Close release DB resource

func (*BaseConn) ExecuteSQL

func (conn *BaseConn) ExecuteSQL(tctx *tcontext.Context, queries []string, args ...[]interface{}) (int, error)

ExecuteSQL executes sql on real DB, return 1. failed: (the index of sqls executed error, error) 2. succeed: (len(sqls), nil)

func (*BaseConn) ExecuteSQLWithIgnoreError

func (conn *BaseConn) ExecuteSQLWithIgnoreError(tctx *tcontext.Context, ignoreErr func(error) bool, queries []string, args ...[]interface{}) (int, error)

ExecuteSQLWithIgnoreError executes sql on real DB, and will ignore some error and continue execute the next query. return 1. failed: (the index of sqls executed error, error) 2. succeed: (len(sqls), nil)

func (*BaseConn) QuerySQL

func (conn *BaseConn) QuerySQL(tctx *tcontext.Context, query string, args ...interface{}) (*sql.Rows, error)

QuerySQL defines query statement, and connect to real DB

func (*BaseConn) ResetConn

func (conn *BaseConn) ResetConn(tctx *tcontext.Context) error

ResetConn generates new *DB with new connection pool to take place old one

func (*BaseConn) SetRetryStrategy

func (conn *BaseConn) SetRetryStrategy(strategy retry.Strategy) error

SetRetryStrategy set retry strategy for baseConn

Jump to

Keyboard shortcuts

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