|
@@ -9,9 +9,9 @@ import (
|
|
// PostgreSQL
|
|
// PostgreSQL
|
|
_ "github.com/lib/pq"
|
|
_ "github.com/lib/pq"
|
|
// MySQL
|
|
// MySQL
|
|
- _ "github.com/go-sql-driver/mysql"
|
|
|
|
|
|
+ //_ "github.com/go-sql-driver/mysql"
|
|
"github.com/jmoiron/sqlx"
|
|
"github.com/jmoiron/sqlx"
|
|
- _ "github.com/mattn/go-sqlite3"
|
|
|
|
|
|
+ //_ "github.com/mattn/go-sqlite3"
|
|
)
|
|
)
|
|
|
|
|
|
// DB define
|
|
// DB define
|
|
@@ -215,7 +215,7 @@ func (d *DB) Rollback() (err error) {
|
|
}
|
|
}
|
|
|
|
|
|
// TransExec trans execute with named args
|
|
// TransExec trans execute with named args
|
|
-func (d *DB) TransExec(query string, args interface{}) (lastInsertId, rowsAffected int64, err error) {
|
|
|
|
|
|
+func (d *DB) TransExec(query string, args any) (lastInsertId, rowsAffected int64, err error) {
|
|
var rs sql.Result
|
|
var rs sql.Result
|
|
if rs, err = d.tx.NamedExec(query, args); err == nil {
|
|
if rs, err = d.tx.NamedExec(query, args); err == nil {
|
|
rowsAffected, _ = rs.RowsAffected()
|
|
rowsAffected, _ = rs.RowsAffected()
|
|
@@ -225,7 +225,7 @@ func (d *DB) TransExec(query string, args interface{}) (lastInsertId, rowsAffect
|
|
}
|
|
}
|
|
|
|
|
|
// TransExec trans execute with named args
|
|
// TransExec trans execute with named args
|
|
-func (d *DB) TransExecContext(ctx context.Context, query string, args interface{}) (lastInsertId, rowsAffected int64, err error) {
|
|
|
|
|
|
+func (d *DB) TransExecContext(ctx context.Context, query string, args any) (lastInsertId, rowsAffected int64, err error) {
|
|
var rs sql.Result
|
|
var rs sql.Result
|
|
if rs, err = d.tx.NamedExecContext(ctx, query, args); err == nil {
|
|
if rs, err = d.tx.NamedExecContext(ctx, query, args); err == nil {
|
|
rowsAffected, _ = rs.RowsAffected()
|
|
rowsAffected, _ = rs.RowsAffected()
|
|
@@ -235,7 +235,7 @@ func (d *DB) TransExecContext(ctx context.Context, query string, args interface{
|
|
}
|
|
}
|
|
|
|
|
|
// TransUpdate trans update
|
|
// TransUpdate trans update
|
|
-func (d *DB) TransUpdate(query string, args interface{}) (reply Reply) {
|
|
|
|
|
|
+func (d *DB) TransUpdate(query string, args any) (reply Reply) {
|
|
var (
|
|
var (
|
|
err error
|
|
err error
|
|
rs sql.Result
|
|
rs sql.Result
|
|
@@ -251,7 +251,7 @@ func (d *DB) TransUpdate(query string, args interface{}) (reply Reply) {
|
|
}
|
|
}
|
|
|
|
|
|
// TransRow trans get row
|
|
// TransRow trans get row
|
|
-func (d *DB) TransRow(dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+func (d *DB) TransRow(dest any, query string, args any) (err error) {
|
|
nstmt := &sqlx.NamedStmt{}
|
|
nstmt := &sqlx.NamedStmt{}
|
|
nstmt, err = d.tx.PrepareNamed(query)
|
|
nstmt, err = d.tx.PrepareNamed(query)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -289,7 +289,7 @@ func (d *DB) PrepareNamedContext(ctx context.Context, query string) (stmt *Named
|
|
}
|
|
}
|
|
|
|
|
|
// Select select
|
|
// Select select
|
|
-func (d *DB) Select(dest interface{}, query string, args ...interface{}) (err error) {
|
|
|
|
|
|
+func (d *DB) Select(dest any, query string, args ...any) (err error) {
|
|
err = d.Connect()
|
|
err = d.Connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -301,7 +301,7 @@ func (d *DB) Select(dest interface{}, query string, args ...interface{}) (err er
|
|
}
|
|
}
|
|
|
|
|
|
// SelectContext select
|
|
// SelectContext select
|
|
-func (d *DB) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error) {
|
|
|
|
|
|
+func (d *DB) SelectContext(ctx context.Context, dest any, query string, args ...any) (err error) {
|
|
err = d.ConnectContext(ctx)
|
|
err = d.ConnectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -312,8 +312,8 @@ func (d *DB) SelectContext(ctx context.Context, dest interface{}, query string,
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-// Query get rows with named args, Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
|
|
|
|
-func (d *DB) Query(dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+// QueryNamed get rows with named args, Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
|
|
|
|
+func (d *DB) QueryNamed(dest any, query string, args any) (err error) {
|
|
err = d.Connect()
|
|
err = d.Connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -331,8 +331,8 @@ func (d *DB) Query(dest interface{}, query string, args interface{}) (err error)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-// QueryContext get rows with named args, QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
|
|
|
|
-func (d *DB) QueryContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+// QueryNamedContext get rows with named args, QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
|
|
|
|
+func (d *DB) QueryNamedContext(ctx context.Context, dest any, query string, args any) (err error) {
|
|
err = d.ConnectContext(ctx)
|
|
err = d.ConnectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -351,7 +351,7 @@ func (d *DB) QueryContext(ctx context.Context, dest interface{}, query string, a
|
|
}
|
|
}
|
|
|
|
|
|
// Rows get rows with named args
|
|
// Rows get rows with named args
|
|
-func (d *DB) Rows(dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+func (d *DB) Rows(dest any, query string, args any) (err error) {
|
|
err = d.Connect()
|
|
err = d.Connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -370,7 +370,7 @@ func (d *DB) Rows(dest interface{}, query string, args interface{}) (err error)
|
|
}
|
|
}
|
|
|
|
|
|
// RowsContext get rows with named args
|
|
// RowsContext get rows with named args
|
|
-func (d *DB) RowsContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+func (d *DB) RowsContext(ctx context.Context, dest any, query string, args any) (err error) {
|
|
err = d.ConnectContext(ctx)
|
|
err = d.ConnectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -389,7 +389,7 @@ func (d *DB) RowsContext(ctx context.Context, dest interface{}, query string, ar
|
|
}
|
|
}
|
|
|
|
|
|
// QueryRow get row, QueryRow executes a query that is expected to return at most one row.
|
|
// QueryRow get row, QueryRow executes a query that is expected to return at most one row.
|
|
-func (d *DB) QueryRow(dest interface{}, query string, args ...interface{}) (err error) {
|
|
|
|
|
|
+func (d *DB) QueryRow(dest any, query string, args ...any) (err error) {
|
|
err = d.Connect()
|
|
err = d.Connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -401,7 +401,7 @@ func (d *DB) QueryRow(dest interface{}, query string, args ...interface{}) (err
|
|
}
|
|
}
|
|
|
|
|
|
// QueryRowContext get row, QueryRowContext executes a query that is expected to return at most one row.
|
|
// QueryRowContext get row, QueryRowContext executes a query that is expected to return at most one row.
|
|
-func (d *DB) QueryRowContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error) {
|
|
|
|
|
|
+func (d *DB) QueryRowContext(ctx context.Context, dest any, query string, args ...any) (err error) {
|
|
err = d.ConnectContext(ctx)
|
|
err = d.ConnectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -413,7 +413,7 @@ func (d *DB) QueryRowContext(ctx context.Context, dest interface{}, query string
|
|
}
|
|
}
|
|
|
|
|
|
// Get get row, QueryRow executes a query that is expected to return at most one row.
|
|
// Get get row, QueryRow executes a query that is expected to return at most one row.
|
|
-func (d *DB) Get(dest interface{}, query string, args ...interface{}) (err error) {
|
|
|
|
|
|
+func (d *DB) Get(dest any, query string, args ...any) (err error) {
|
|
err = d.Connect()
|
|
err = d.Connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -425,7 +425,7 @@ func (d *DB) Get(dest interface{}, query string, args ...interface{}) (err error
|
|
}
|
|
}
|
|
|
|
|
|
// GetContext get
|
|
// GetContext get
|
|
-func (d *DB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error) {
|
|
|
|
|
|
+func (d *DB) GetContext(ctx context.Context, dest any, query string, args ...any) (err error) {
|
|
err = d.ConnectContext(ctx)
|
|
err = d.ConnectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -437,7 +437,7 @@ func (d *DB) GetContext(ctx context.Context, dest interface{}, query string, arg
|
|
}
|
|
}
|
|
|
|
|
|
// Row get row with named args
|
|
// Row get row with named args
|
|
-func (d *DB) Row(dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+func (d *DB) Row(dest any, query string, args any) (err error) {
|
|
err = d.Connect()
|
|
err = d.Connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -456,7 +456,7 @@ func (d *DB) Row(dest interface{}, query string, args interface{}) (err error) {
|
|
}
|
|
}
|
|
|
|
|
|
// RowContext get row with named args
|
|
// RowContext get row with named args
|
|
-func (d *DB) RowContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+func (d *DB) RowContext(ctx context.Context, dest any, query string, args any) (err error) {
|
|
err = d.ConnectContext(ctx)
|
|
err = d.ConnectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -476,7 +476,7 @@ func (d *DB) RowContext(ctx context.Context, dest interface{}, query string, arg
|
|
|
|
|
|
// *
|
|
// *
|
|
// 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 ...any) (q string, params []any, err error) {
|
|
err = d.Connect()
|
|
err = d.Connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -491,7 +491,7 @@ func (d *DB) In(query string, args ...interface{}) (q string, params []interface
|
|
//*/
|
|
//*/
|
|
|
|
|
|
// InsertReply insert and return DbReply
|
|
// InsertReply insert and return DbReply
|
|
-func (d *DB) InsertReply(query string, args interface{}) (reply Reply) {
|
|
|
|
|
|
+func (d *DB) InsertReply(query string, args any) (reply Reply) {
|
|
var (
|
|
var (
|
|
err error
|
|
err error
|
|
rs sql.Result
|
|
rs sql.Result
|
|
@@ -514,7 +514,7 @@ func (d *DB) InsertReply(query string, args interface{}) (reply Reply) {
|
|
}
|
|
}
|
|
|
|
|
|
// UpdateReply update/delete and return DbReply
|
|
// UpdateReply update/delete and return DbReply
|
|
-func (d *DB) UpdateReply(query string, args interface{}) (reply Reply) {
|
|
|
|
|
|
+func (d *DB) UpdateReply(query string, args any) (reply Reply) {
|
|
var (
|
|
var (
|
|
err error
|
|
err error
|
|
rs sql.Result
|
|
rs sql.Result
|
|
@@ -536,7 +536,7 @@ func (d *DB) UpdateReply(query string, args interface{}) (reply Reply) {
|
|
}
|
|
}
|
|
|
|
|
|
// Insert insert into with named args
|
|
// Insert insert into with named args
|
|
-func (d *DB) Insert(query string, args interface{}) (lastInsertId, rowsAffected int64, err error) {
|
|
|
|
|
|
+func (d *DB) Insert(query string, args any) (lastInsertId, rowsAffected int64, err error) {
|
|
err = d.Connect()
|
|
err = d.Connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -552,7 +552,7 @@ func (d *DB) Insert(query string, args interface{}) (lastInsertId, rowsAffected
|
|
}
|
|
}
|
|
|
|
|
|
// InsertContext insert into with named args
|
|
// InsertContext insert into with named args
|
|
-func (d *DB) InsertContext(ctx context.Context, query string, args interface{}) (lastInsertId, rowsAffected int64, err error) {
|
|
|
|
|
|
+func (d *DB) InsertContext(ctx context.Context, query string, args any) (lastInsertId, rowsAffected int64, err error) {
|
|
err = d.ConnectContext(ctx)
|
|
err = d.ConnectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -568,7 +568,7 @@ func (d *DB) InsertContext(ctx context.Context, query string, args interface{})
|
|
}
|
|
}
|
|
|
|
|
|
// Update update/delete with named args
|
|
// Update update/delete with named args
|
|
-func (d *DB) Update(query string, args interface{}) (rowsAffected int64, err error) {
|
|
|
|
|
|
+func (d *DB) Update(query string, args any) (rowsAffected int64, err error) {
|
|
err = d.Connect()
|
|
err = d.Connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -583,7 +583,7 @@ func (d *DB) Update(query string, args interface{}) (rowsAffected int64, err err
|
|
}
|
|
}
|
|
|
|
|
|
// Update update/delete with named args
|
|
// Update update/delete with named args
|
|
-func (d *DB) UpdateContext(ctx context.Context, query string, args interface{}) (rowsAffected int64, err error) {
|
|
|
|
|
|
+func (d *DB) UpdateContext(ctx context.Context, query string, args any) (rowsAffected int64, err error) {
|
|
err = d.ConnectContext(ctx)
|
|
err = d.ConnectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -598,7 +598,7 @@ func (d *DB) UpdateContext(ctx context.Context, query string, args interface{})
|
|
}
|
|
}
|
|
|
|
|
|
// Exec exec
|
|
// Exec exec
|
|
-func (d *DB) Exec(query string, args ...interface{}) (lastInsertId, rowsAffected int64, err error) {
|
|
|
|
|
|
+func (d *DB) Exec(query string, args ...any) (lastInsertId, rowsAffected int64, err error) {
|
|
err = d.Connect()
|
|
err = d.Connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -614,7 +614,7 @@ func (d *DB) Exec(query string, args ...interface{}) (lastInsertId, rowsAffected
|
|
}
|
|
}
|
|
|
|
|
|
// ExecContext exec
|
|
// ExecContext exec
|
|
-func (d *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (lastInsertId, rowsAffected int64, err error) {
|
|
|
|
|
|
+func (d *DB) ExecContext(ctx context.Context, query string, args ...any) (lastInsertId, rowsAffected int64, err error) {
|
|
err = d.ConnectContext(ctx)
|
|
err = d.ConnectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -630,7 +630,7 @@ func (d *DB) ExecContext(ctx context.Context, query string, args ...interface{})
|
|
}
|
|
}
|
|
|
|
|
|
// Exec exec, with named args
|
|
// Exec exec, with named args
|
|
-func (d *DB) NamedExec(query string, args interface{}) (lastInsertId, rowsAffected int64, err error) {
|
|
|
|
|
|
+func (d *DB) NamedExec(query string, args any) (lastInsertId, rowsAffected int64, err error) {
|
|
err = d.Connect()
|
|
err = d.Connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -646,7 +646,7 @@ func (d *DB) NamedExec(query string, args interface{}) (lastInsertId, rowsAffect
|
|
}
|
|
}
|
|
|
|
|
|
// NamedExecContext exec, with named args
|
|
// NamedExecContext exec, with named args
|
|
-func (d *DB) NamedExecContext(ctx context.Context, query string, args interface{}) (lastInsertId, rowsAffected int64, err error) {
|
|
|
|
|
|
+func (d *DB) NamedExecContext(ctx context.Context, query string, args any) (lastInsertId, rowsAffected int64, err error) {
|
|
err = d.ConnectContext(ctx)
|
|
err = d.ConnectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -663,11 +663,13 @@ func (d *DB) NamedExecContext(ctx context.Context, query string, args interface{
|
|
|
|
|
|
// Limit MySQL limit
|
|
// Limit MySQL limit
|
|
func (d *DB) Limit(page, pagesize int) string {
|
|
func (d *DB) Limit(page, pagesize int) string {
|
|
- // MySQL limit 0, size
|
|
|
|
- if d.Driver == `mysql` {
|
|
|
|
- return fmt.Sprintf(" LIMIT %d, %d", (page-1)*pagesize, pagesize)
|
|
|
|
- }
|
|
|
|
- // // PostgreSQL limit size offset 0
|
|
|
|
|
|
+ /*
|
|
|
|
+ // MySQL limit 0, size
|
|
|
|
+ if d.Driver == `mysql` {
|
|
|
|
+ return fmt.Sprintf(" LIMIT %d, %d", (page-1)*pagesize, pagesize)
|
|
|
|
+ }
|
|
|
|
+ // // PostgreSQL limit size offset 0
|
|
|
|
+ // */
|
|
return fmt.Sprintf(" LIMIT %d OFFSET %d", pagesize, (page-1)*pagesize)
|
|
return fmt.Sprintf(" LIMIT %d OFFSET %d", pagesize, (page-1)*pagesize)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -682,7 +684,7 @@ func (t *Tx) Rollback() error {
|
|
}
|
|
}
|
|
|
|
|
|
// NamedExec executes a query that doesn't return rows. For example: an INSERT and UPDATE. with named args
|
|
// NamedExec executes a query that doesn't return rows. For example: an INSERT and UPDATE. with named args
|
|
-func (t *Tx) NamedExec(query string, args interface{}) (lastInsertId, rowsAffected int64, err error) {
|
|
|
|
|
|
+func (t *Tx) NamedExec(query string, args any) (lastInsertId, rowsAffected int64, err error) {
|
|
var rs sql.Result
|
|
var rs sql.Result
|
|
if rs, err = t.tx.NamedExec(query, args); err == nil {
|
|
if rs, err = t.tx.NamedExec(query, args); err == nil {
|
|
rowsAffected, _ = rs.RowsAffected()
|
|
rowsAffected, _ = rs.RowsAffected()
|
|
@@ -692,7 +694,7 @@ func (t *Tx) NamedExec(query string, args interface{}) (lastInsertId, rowsAffect
|
|
}
|
|
}
|
|
|
|
|
|
// NamedExecContext executes a query that doesn't return rows. For example: an INSERT and UPDATE. with named args
|
|
// NamedExecContext executes a query that doesn't return rows. For example: an INSERT and UPDATE. with named args
|
|
-func (t *Tx) NamedExecContext(ctx context.Context, query string, args interface{}) (lastInsertId, rowsAffected int64, err error) {
|
|
|
|
|
|
+func (t *Tx) NamedExecContext(ctx context.Context, query string, args any) (lastInsertId, rowsAffected int64, err error) {
|
|
var rs sql.Result
|
|
var rs sql.Result
|
|
if rs, err = t.tx.NamedExecContext(ctx, query, args); err == nil {
|
|
if rs, err = t.tx.NamedExecContext(ctx, query, args); err == nil {
|
|
rowsAffected, _ = rs.RowsAffected()
|
|
rowsAffected, _ = rs.RowsAffected()
|
|
@@ -702,7 +704,7 @@ func (t *Tx) NamedExecContext(ctx context.Context, query string, args interface{
|
|
}
|
|
}
|
|
|
|
|
|
// Exec executes a query that doesn't return rows. For example: an INSERT and UPDATE.
|
|
// Exec executes a query that doesn't return rows. For example: an INSERT and UPDATE.
|
|
-func (t *Tx) Exec(query string, args ...interface{}) (lastInsertId, rowsAffected int64, err error) {
|
|
|
|
|
|
+func (t *Tx) Exec(query string, args ...any) (lastInsertId, rowsAffected int64, err error) {
|
|
var rs sql.Result
|
|
var rs sql.Result
|
|
if rs, err = t.tx.Exec(query, args...); err == nil {
|
|
if rs, err = t.tx.Exec(query, args...); err == nil {
|
|
rowsAffected, _ = rs.RowsAffected()
|
|
rowsAffected, _ = rs.RowsAffected()
|
|
@@ -712,7 +714,7 @@ func (t *Tx) Exec(query string, args ...interface{}) (lastInsertId, rowsAffected
|
|
}
|
|
}
|
|
|
|
|
|
// ExecContext executes a query that doesn't return rows. For example: an INSERT and UPDATE.
|
|
// ExecContext executes a query that doesn't return rows. For example: an INSERT and UPDATE.
|
|
-func (t *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (lastInsertId, rowsAffected int64, err error) {
|
|
|
|
|
|
+func (t *Tx) ExecContext(ctx context.Context, query string, args ...any) (lastInsertId, rowsAffected int64, err error) {
|
|
var rs sql.Result
|
|
var rs sql.Result
|
|
if rs, err = t.tx.ExecContext(ctx, query, args...); err == nil {
|
|
if rs, err = t.tx.ExecContext(ctx, query, args...); err == nil {
|
|
rowsAffected, _ = rs.RowsAffected()
|
|
rowsAffected, _ = rs.RowsAffected()
|
|
@@ -746,7 +748,7 @@ func (t *Tx) PrepareNamedContext(ctx context.Context, query string) (stmt *Named
|
|
}
|
|
}
|
|
|
|
|
|
// 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 any, query string, args any) (err error) {
|
|
nstmt := &sqlx.NamedStmt{}
|
|
nstmt := &sqlx.NamedStmt{}
|
|
nstmt, err = t.tx.PrepareNamed(query)
|
|
nstmt, err = t.tx.PrepareNamed(query)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -759,7 +761,7 @@ func (t *Tx) Query(dest interface{}, query string, args interface{}) (err error)
|
|
}
|
|
}
|
|
|
|
|
|
// QueryContext executes a query that returns rows, typically a SELECT. with named args
|
|
// QueryContext executes a query that returns rows, typically a SELECT. with named args
|
|
-func (t *Tx) QueryContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+func (t *Tx) QueryContext(ctx context.Context, dest any, query string, args any) (err error) {
|
|
nstmt := &sqlx.NamedStmt{}
|
|
nstmt := &sqlx.NamedStmt{}
|
|
nstmt, err = t.tx.PrepareNamedContext(ctx, query)
|
|
nstmt, err = t.tx.PrepareNamedContext(ctx, query)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -772,7 +774,7 @@ func (t *Tx) QueryContext(ctx context.Context, dest interface{}, query string, a
|
|
}
|
|
}
|
|
|
|
|
|
// QueryRow executes a query that returns rows, typically a SELECT. with named args
|
|
// QueryRow executes a query that returns rows, typically a SELECT. with named args
|
|
-func (t *Tx) QueryRow(dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+func (t *Tx) QueryRow(dest any, query string, args any) (err error) {
|
|
nstmt := &sqlx.NamedStmt{}
|
|
nstmt := &sqlx.NamedStmt{}
|
|
nstmt, err = t.tx.PrepareNamed(query)
|
|
nstmt, err = t.tx.PrepareNamed(query)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -785,7 +787,7 @@ func (t *Tx) QueryRow(dest interface{}, query string, args interface{}) (err err
|
|
}
|
|
}
|
|
|
|
|
|
// QueryRowContext get row with named args
|
|
// QueryRowContext get row with named args
|
|
-func (t *Tx) QueryRowContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+func (t *Tx) QueryRowContext(ctx context.Context, dest any, query string, args any) (err error) {
|
|
nstmt := &sqlx.NamedStmt{}
|
|
nstmt := &sqlx.NamedStmt{}
|
|
nstmt, err = t.tx.PrepareNamedContext(ctx, query)
|
|
nstmt, err = t.tx.PrepareNamedContext(ctx, query)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -831,7 +833,7 @@ func PingContext(ctx context.Context) (err error) {
|
|
}
|
|
}
|
|
|
|
|
|
// Select select
|
|
// Select select
|
|
-func Select(dest interface{}, query string, args ...interface{}) (err error) {
|
|
|
|
|
|
+func Select(dest any, query string, args ...any) (err error) {
|
|
defaultDB.conn, err = connect()
|
|
defaultDB.conn, err = connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -842,7 +844,7 @@ func Select(dest interface{}, query string, args ...interface{}) (err error) {
|
|
}
|
|
}
|
|
|
|
|
|
// Query get rows with named args
|
|
// Query get rows with named args
|
|
-func Query(dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+func Query(dest any, query string, args any) (err error) {
|
|
defaultDB.conn, err = connect()
|
|
defaultDB.conn, err = connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -860,7 +862,7 @@ func Query(dest interface{}, query string, args interface{}) (err error) {
|
|
}
|
|
}
|
|
|
|
|
|
// QueryContext get rows with named args
|
|
// QueryContext get rows with named args
|
|
-func QueryContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+func QueryContext(ctx context.Context, dest any, query string, args any) (err error) {
|
|
defaultDB.conn, err = connectContext(ctx)
|
|
defaultDB.conn, err = connectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -878,7 +880,7 @@ func QueryContext(ctx context.Context, dest interface{}, query string, args inte
|
|
}
|
|
}
|
|
|
|
|
|
// Rows get rows with named args
|
|
// Rows get rows with named args
|
|
-func Rows(dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+func Rows(dest any, query string, args any) (err error) {
|
|
defaultDB.conn, err = connect()
|
|
defaultDB.conn, err = connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -896,7 +898,7 @@ func Rows(dest interface{}, query string, args interface{}) (err error) {
|
|
}
|
|
}
|
|
|
|
|
|
// RowsContext get rows with named args
|
|
// RowsContext get rows with named args
|
|
-func RowsContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+func RowsContext(ctx context.Context, dest any, query string, args any) (err error) {
|
|
defaultDB.conn, err = connectContext(ctx)
|
|
defaultDB.conn, err = connectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -914,7 +916,7 @@ func RowsContext(ctx context.Context, dest interface{}, query string, args inter
|
|
}
|
|
}
|
|
|
|
|
|
// Get get
|
|
// Get get
|
|
-func Get(dest interface{}, query string, args ...interface{}) (err error) {
|
|
|
|
|
|
+func Get(dest any, query string, args ...any) (err error) {
|
|
defaultDB.conn, err = connect()
|
|
defaultDB.conn, err = connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -925,7 +927,7 @@ func Get(dest interface{}, query string, args ...interface{}) (err error) {
|
|
}
|
|
}
|
|
|
|
|
|
// QueryRow get row with named args
|
|
// QueryRow get row with named args
|
|
-func QueryRow(dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+func QueryRow(dest any, query string, args any) (err error) {
|
|
defaultDB.conn, err = connect()
|
|
defaultDB.conn, err = connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -943,7 +945,7 @@ func QueryRow(dest interface{}, query string, args interface{}) (err error) {
|
|
}
|
|
}
|
|
|
|
|
|
// QueryRowContext get row with named args
|
|
// QueryRowContext get row with named args
|
|
-func QueryRowContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+func QueryRowContext(ctx context.Context, dest any, query string, args any) (err error) {
|
|
defaultDB.conn, err = connectContext(ctx)
|
|
defaultDB.conn, err = connectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -961,7 +963,7 @@ func QueryRowContext(ctx context.Context, dest interface{}, query string, args i
|
|
}
|
|
}
|
|
|
|
|
|
// Row get row with named args
|
|
// Row get row with named args
|
|
-func Row(dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+func Row(dest any, query string, args any) (err error) {
|
|
defaultDB.conn, err = connect()
|
|
defaultDB.conn, err = connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -979,7 +981,7 @@ func Row(dest interface{}, query string, args interface{}) (err error) {
|
|
}
|
|
}
|
|
|
|
|
|
// RowContext get row with named args
|
|
// RowContext get row with named args
|
|
-func RowContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
|
|
+func RowContext(ctx context.Context, dest any, query string, args any) (err error) {
|
|
defaultDB.conn, err = connectContext(ctx)
|
|
defaultDB.conn, err = connectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -998,7 +1000,7 @@ func RowContext(ctx context.Context, dest interface{}, query string, args interf
|
|
|
|
|
|
/*
|
|
/*
|
|
// 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 In(query string, args ...interface{}) (q string, params []interface{}, err error) {
|
|
|
|
|
|
+func In(query string, args ...any) (q string, params []any, err error) {
|
|
defaultDB.conn, err = connect()
|
|
defaultDB.conn, err = connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -1010,7 +1012,7 @@ func In(query string, args ...interface{}) (q string, params []interface{}, err
|
|
// */
|
|
// */
|
|
|
|
|
|
// Exec exec
|
|
// Exec exec
|
|
-func Exec(query string, args ...interface{}) (lastInsertId, rowsAffected int64, err error) {
|
|
|
|
|
|
+func Exec(query string, args ...any) (lastInsertId, rowsAffected int64, err error) {
|
|
defaultDB.conn, err = connect()
|
|
defaultDB.conn, err = connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -1021,7 +1023,7 @@ func Exec(query string, args ...interface{}) (lastInsertId, rowsAffected int64,
|
|
}
|
|
}
|
|
|
|
|
|
// Exec exec
|
|
// Exec exec
|
|
-func ExecContext(ctx context.Context, query string, args ...interface{}) (lastInsertId, rowsAffected int64, err error) {
|
|
|
|
|
|
+func ExecContext(ctx context.Context, query string, args ...any) (lastInsertId, rowsAffected int64, err error) {
|
|
defaultDB.conn, err = connectContext(ctx)
|
|
defaultDB.conn, err = connectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -1032,7 +1034,7 @@ func ExecContext(ctx context.Context, query string, args ...interface{}) (lastIn
|
|
}
|
|
}
|
|
|
|
|
|
// NamedExec exec with named args
|
|
// NamedExec exec with named args
|
|
-func NamedExec(query string, args interface{}) (lastInsertId, rowsAffected int64, err error) {
|
|
|
|
|
|
+func NamedExec(query string, args any) (lastInsertId, rowsAffected int64, err error) {
|
|
defaultDB.conn, err = connect()
|
|
defaultDB.conn, err = connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -1043,7 +1045,7 @@ func NamedExec(query string, args interface{}) (lastInsertId, rowsAffected int64
|
|
}
|
|
}
|
|
|
|
|
|
// NamedExecContext exec with named args
|
|
// NamedExecContext exec with named args
|
|
-func NamedExecContext(ctx context.Context, query string, args interface{}) (lastInsertId, rowsAffected int64, err error) {
|
|
|
|
|
|
+func NamedExecContext(ctx context.Context, query string, args any) (lastInsertId, rowsAffected int64, err error) {
|
|
defaultDB.conn, err = connectContext(ctx)
|
|
defaultDB.conn, err = connectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|