|
@@ -64,9 +64,8 @@ func ReleaseConfig(dbx *DB) {
|
|
|
|
|
|
func connect() (dbx *sqlx.DB, err error) {
|
|
func connect() (dbx *sqlx.DB, err error) {
|
|
once.Do(func() {
|
|
once.Do(func() {
|
|
- db, err = sqlx.Connect(config.Driver, config.DNS)
|
|
|
|
|
|
+ db, err = sqlx.Open(config.Driver, config.DNS) // sqlx.Connect(config.Driver, config.DNS)
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println("Connect ERR", err)
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|
|
db.DB.SetMaxOpenConns(config.MaxOpenConns)
|
|
db.DB.SetMaxOpenConns(config.MaxOpenConns)
|
|
@@ -76,7 +75,6 @@ func connect() (dbx *sqlx.DB, err error) {
|
|
/*
|
|
/*
|
|
err = db.Ping()
|
|
err = db.Ping()
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println("Connect Ping", err)
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|
|
// */
|
|
// */
|
|
@@ -93,7 +91,6 @@ func connectContext(ctx context.Context) (dbx *sqlx.DB, err error) {
|
|
once.Do(func() {
|
|
once.Do(func() {
|
|
db, err = sqlx.ConnectContext(ctx, config.Driver, config.DNS)
|
|
db, err = sqlx.ConnectContext(ctx, config.Driver, config.DNS)
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println("Connect ERR", err)
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|
|
db.DB.SetMaxOpenConns(config.MaxOpenConns)
|
|
db.DB.SetMaxOpenConns(config.MaxOpenConns)
|
|
@@ -267,6 +264,30 @@ func (d *DB) TransRow(dest interface{}, query string, args interface{}) (err err
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Preparex a statement within a transaction.
|
|
|
|
+func (d *DB) Preparex(query string) (stmt *Stmt, err error) {
|
|
|
|
+ stmt, err = d.conn.Preparex(query)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// PreparexContext returns an sqlx.Stmt instead of a sql.Stmt.
|
|
|
|
+func (d *DB) PreparexContext(ctx context.Context, query string) (stmt *Stmt, err error) {
|
|
|
|
+ stmt, err = d.conn.PreparexContext(ctx, query)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// PrepareNamed returns an sqlx.NamedStmt
|
|
|
|
+func (d *DB) PrepareNamed(query string) (stmt *NamedStmt, err error) {
|
|
|
|
+ stmt, err = d.conn.PrepareNamed(query)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// PrepareNamedContext returns an sqlx.NamedStmt
|
|
|
|
+func (d *DB) PrepareNamedContext(ctx context.Context, query string) (stmt *NamedStmt, err error) {
|
|
|
|
+ stmt, err = d.conn.PrepareNamedContext(ctx, query)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
// Select select
|
|
// Select select
|
|
func (d *DB) Select(dest interface{}, query string, args ...interface{}) (err error) {
|
|
func (d *DB) Select(dest interface{}, query string, args ...interface{}) (err error) {
|
|
err = d.Connect()
|
|
err = d.Connect()
|
|
@@ -453,7 +474,7 @@ func (d *DB) RowContext(ctx context.Context, dest interface{}, query string, arg
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-/*
|
|
|
|
|
|
+// *
|
|
// In expands slice values in args, returning the modified query string and a new arg list that can be executed by a database. The `query` should use the `?` bindVar. The return value uses the `?` bindVar.
|
|
// In expands slice values in args, returning the modified query string and a new arg list that can be executed by a database. The `query` should use the `?` bindVar. The return value uses the `?` bindVar.
|
|
func (d *DB) In(query string, args ...interface{}) (q string, params []interface{}, err error) {
|
|
func (d *DB) In(query string, args ...interface{}) (q string, params []interface{}, err error) {
|
|
err = d.Connect()
|
|
err = d.Connect()
|
|
@@ -466,6 +487,7 @@ func (d *DB) In(query string, args ...interface{}) (q string, params []interface
|
|
q = d.conn.Rebind(s)
|
|
q = d.conn.Rebind(s)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+
|
|
//*/
|
|
//*/
|
|
|
|
|
|
// InsertReply insert and return DbReply
|
|
// InsertReply insert and return DbReply
|
|
@@ -699,6 +721,30 @@ func (t *Tx) ExecContext(ctx context.Context, query string, args ...interface{})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Preparex a statement within a transaction.
|
|
|
|
+func (t *Tx) Preparex(query string) (stmt *Stmt, err error) {
|
|
|
|
+ stmt, err = t.tx.Preparex(query)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// PreparexContext a statement within a transaction.
|
|
|
|
+func (t *Tx) PreparexContext(ctx context.Context, query string) (stmt *Stmt, err error) {
|
|
|
|
+ stmt, err = t.tx.PreparexContext(ctx, query)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// PrepareNamed returns an sqlx.NamedStmt
|
|
|
|
+func (t *Tx) PrepareNamed(query string) (stmt *NamedStmt, err error) {
|
|
|
|
+ stmt, err = t.tx.PrepareNamed(query)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// PrepareNamedContext returns an sqlx.NamedStmt
|
|
|
|
+func (t *Tx) PrepareNamedContext(ctx context.Context, query string) (stmt *NamedStmt, err error) {
|
|
|
|
+ stmt, err = t.tx.PrepareNamedContext(ctx, query)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
// Query executes a query that returns rows, typically a SELECT. with named args
|
|
// Query executes a query that returns rows, typically a SELECT. with named args
|
|
func (t *Tx) Query(dest interface{}, query string, args interface{}) (err error) {
|
|
func (t *Tx) Query(dest interface{}, query string, args interface{}) (err error) {
|
|
nstmt := &sqlx.NamedStmt{}
|
|
nstmt := &sqlx.NamedStmt{}
|