|
|
@ -64,7 +64,7 @@ type (
|
|
|
|
// query arguments into one string and do underlying query without arguments
|
|
|
|
// query arguments into one string and do underlying query without arguments
|
|
|
|
commonSqlConn struct {
|
|
|
|
commonSqlConn struct {
|
|
|
|
connProv connProvider
|
|
|
|
connProv connProvider
|
|
|
|
onError func(error)
|
|
|
|
onError func(context.Context, error)
|
|
|
|
beginTx beginnable
|
|
|
|
beginTx beginnable
|
|
|
|
brk breaker.Breaker
|
|
|
|
brk breaker.Breaker
|
|
|
|
accept func(error) bool
|
|
|
|
accept func(error) bool
|
|
|
@ -98,8 +98,8 @@ func NewSqlConn(driverName, datasource string, opts ...SqlOption) SqlConn {
|
|
|
|
connProv: func() (*sql.DB, error) {
|
|
|
|
connProv: func() (*sql.DB, error) {
|
|
|
|
return getSqlConn(driverName, datasource)
|
|
|
|
return getSqlConn(driverName, datasource)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onError: func(err error) {
|
|
|
|
onError: func(ctx context.Context, err error) {
|
|
|
|
logInstanceError(datasource, err)
|
|
|
|
logInstanceError(ctx, datasource, err)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
beginTx: begin,
|
|
|
|
beginTx: begin,
|
|
|
|
brk: breaker.NewBreaker(),
|
|
|
|
brk: breaker.NewBreaker(),
|
|
|
@ -118,8 +118,8 @@ func NewSqlConnFromDB(db *sql.DB, opts ...SqlOption) SqlConn {
|
|
|
|
connProv: func() (*sql.DB, error) {
|
|
|
|
connProv: func() (*sql.DB, error) {
|
|
|
|
return db, nil
|
|
|
|
return db, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onError: func(err error) {
|
|
|
|
onError: func(ctx context.Context, err error) {
|
|
|
|
logx.Errorf("Error on getting sql instance: %v", err)
|
|
|
|
logx.WithContext(ctx).Errorf("Error on getting sql instance: %v", err)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
beginTx: begin,
|
|
|
|
beginTx: begin,
|
|
|
|
brk: breaker.NewBreaker(),
|
|
|
|
brk: breaker.NewBreaker(),
|
|
|
@ -146,7 +146,7 @@ func (db *commonSqlConn) ExecCtx(ctx context.Context, q string, args ...any) (
|
|
|
|
var conn *sql.DB
|
|
|
|
var conn *sql.DB
|
|
|
|
conn, err = db.connProv()
|
|
|
|
conn, err = db.connProv()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
db.onError(err)
|
|
|
|
db.onError(ctx, err)
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -174,7 +174,7 @@ func (db *commonSqlConn) PrepareCtx(ctx context.Context, query string) (stmt Stm
|
|
|
|
var conn *sql.DB
|
|
|
|
var conn *sql.DB
|
|
|
|
conn, err = db.connProv()
|
|
|
|
conn, err = db.connProv()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
db.onError(err)
|
|
|
|
db.onError(ctx, err)
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -301,7 +301,7 @@ func (db *commonSqlConn) queryRows(ctx context.Context, scanner func(*sql.Rows)
|
|
|
|
err = db.brk.DoWithAcceptable(func() error {
|
|
|
|
err = db.brk.DoWithAcceptable(func() error {
|
|
|
|
conn, err := db.connProv()
|
|
|
|
conn, err := db.connProv()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
db.onError(err)
|
|
|
|
db.onError(ctx, err)
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|