коммит произвёл
GitHub
родитель
b45ff0be5d
Коммит
717a4d04a9
@@ -36,23 +36,23 @@ func (w *StoreTestWrapper) DriverName() string {
|
||||
}
|
||||
|
||||
type Builder interface {
|
||||
ToSql() (string, []interface{}, error)
|
||||
ToSql() (string, []any, error)
|
||||
}
|
||||
|
||||
// sqlxExecutor exposes sqlx operations. It is used to enable some internal store methods to
|
||||
// accept both transactions (*sqlxTxWrapper) and common db handlers (*sqlxDbWrapper).
|
||||
type sqlxExecutor interface {
|
||||
Get(dest interface{}, query string, args ...interface{}) error
|
||||
GetBuilder(dest interface{}, builder Builder) error
|
||||
NamedExec(query string, arg interface{}) (sql.Result, error)
|
||||
Exec(query string, args ...interface{}) (sql.Result, error)
|
||||
Get(dest any, query string, args ...any) error
|
||||
GetBuilder(dest any, builder Builder) error
|
||||
NamedExec(query string, arg any) (sql.Result, error)
|
||||
Exec(query string, args ...any) (sql.Result, error)
|
||||
ExecBuilder(builder Builder) (sql.Result, error)
|
||||
ExecRaw(query string, args ...interface{}) (sql.Result, error)
|
||||
NamedQuery(query string, arg interface{}) (*sqlx.Rows, error)
|
||||
QueryRowX(query string, args ...interface{}) *sqlx.Row
|
||||
QueryX(query string, args ...interface{}) (*sqlx.Rows, error)
|
||||
Select(dest interface{}, query string, args ...interface{}) error
|
||||
SelectBuilder(dest interface{}, builder Builder) error
|
||||
ExecRaw(query string, args ...any) (sql.Result, error)
|
||||
NamedQuery(query string, arg any) (*sqlx.Rows, error)
|
||||
QueryRowX(query string, args ...any) *sqlx.Row
|
||||
QueryX(query string, args ...any) (*sqlx.Rows, error)
|
||||
Select(dest any, query string, args ...any) error
|
||||
SelectBuilder(dest any, builder Builder) error
|
||||
}
|
||||
|
||||
// namedParamRegex is used to capture all named parameters and convert them
|
||||
@@ -98,7 +98,7 @@ func (w *sqlxDBWrapper) BeginXWithIsolation(opts *sql.TxOptions) (*sqlxTxWrapper
|
||||
return newSqlxTxWrapper(tx, w.queryTimeout, w.trace), nil
|
||||
}
|
||||
|
||||
func (w *sqlxDBWrapper) Get(dest interface{}, query string, args ...interface{}) error {
|
||||
func (w *sqlxDBWrapper) Get(dest any, query string, args ...any) error {
|
||||
query = w.DB.Rebind(query)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), w.queryTimeout)
|
||||
defer cancel()
|
||||
@@ -112,7 +112,7 @@ func (w *sqlxDBWrapper) Get(dest interface{}, query string, args ...interface{})
|
||||
return w.DB.GetContext(ctx, dest, query, args...)
|
||||
}
|
||||
|
||||
func (w *sqlxDBWrapper) GetBuilder(dest interface{}, builder Builder) error {
|
||||
func (w *sqlxDBWrapper) GetBuilder(dest any, builder Builder) error {
|
||||
query, args, err := builder.ToSql()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -121,7 +121,7 @@ func (w *sqlxDBWrapper) GetBuilder(dest interface{}, builder Builder) error {
|
||||
return w.Get(dest, query, args...)
|
||||
}
|
||||
|
||||
func (w *sqlxDBWrapper) NamedExec(query string, arg interface{}) (sql.Result, error) {
|
||||
func (w *sqlxDBWrapper) NamedExec(query string, arg any) (sql.Result, error) {
|
||||
if w.DB.DriverName() == model.DatabaseDriverPostgres {
|
||||
query = namedParamRegex.ReplaceAllStringFunc(query, strings.ToLower)
|
||||
}
|
||||
@@ -137,7 +137,7 @@ func (w *sqlxDBWrapper) NamedExec(query string, arg interface{}) (sql.Result, er
|
||||
return w.DB.NamedExecContext(ctx, query, arg)
|
||||
}
|
||||
|
||||
func (w *sqlxDBWrapper) Exec(query string, args ...interface{}) (sql.Result, error) {
|
||||
func (w *sqlxDBWrapper) Exec(query string, args ...any) (sql.Result, error) {
|
||||
query = w.DB.Rebind(query)
|
||||
|
||||
return w.ExecRaw(query, args...)
|
||||
@@ -152,7 +152,7 @@ func (w *sqlxDBWrapper) ExecBuilder(builder Builder) (sql.Result, error) {
|
||||
return w.Exec(query, args...)
|
||||
}
|
||||
|
||||
func (w *sqlxDBWrapper) ExecNoTimeout(query string, args ...interface{}) (sql.Result, error) {
|
||||
func (w *sqlxDBWrapper) ExecNoTimeout(query string, args ...any) (sql.Result, error) {
|
||||
query = w.DB.Rebind(query)
|
||||
|
||||
if w.trace {
|
||||
@@ -166,7 +166,7 @@ func (w *sqlxDBWrapper) ExecNoTimeout(query string, args ...interface{}) (sql.Re
|
||||
|
||||
// ExecRaw is like Exec but without any rebinding of params. You need to pass
|
||||
// the exact param types of your target database.
|
||||
func (w *sqlxDBWrapper) ExecRaw(query string, args ...interface{}) (sql.Result, error) {
|
||||
func (w *sqlxDBWrapper) ExecRaw(query string, args ...any) (sql.Result, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), w.queryTimeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -179,7 +179,7 @@ func (w *sqlxDBWrapper) ExecRaw(query string, args ...interface{}) (sql.Result,
|
||||
return w.DB.ExecContext(ctx, query, args...)
|
||||
}
|
||||
|
||||
func (w *sqlxDBWrapper) NamedQuery(query string, arg interface{}) (*sqlx.Rows, error) {
|
||||
func (w *sqlxDBWrapper) NamedQuery(query string, arg any) (*sqlx.Rows, error) {
|
||||
if w.DB.DriverName() == model.DatabaseDriverPostgres {
|
||||
query = namedParamRegex.ReplaceAllStringFunc(query, strings.ToLower)
|
||||
}
|
||||
@@ -195,7 +195,7 @@ func (w *sqlxDBWrapper) NamedQuery(query string, arg interface{}) (*sqlx.Rows, e
|
||||
return w.DB.NamedQueryContext(ctx, query, arg)
|
||||
}
|
||||
|
||||
func (w *sqlxDBWrapper) QueryRowX(query string, args ...interface{}) *sqlx.Row {
|
||||
func (w *sqlxDBWrapper) QueryRowX(query string, args ...any) *sqlx.Row {
|
||||
query = w.DB.Rebind(query)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), w.queryTimeout)
|
||||
defer cancel()
|
||||
@@ -209,7 +209,7 @@ func (w *sqlxDBWrapper) QueryRowX(query string, args ...interface{}) *sqlx.Row {
|
||||
return w.DB.QueryRowxContext(ctx, query, args...)
|
||||
}
|
||||
|
||||
func (w *sqlxDBWrapper) QueryX(query string, args ...interface{}) (*sqlx.Rows, error) {
|
||||
func (w *sqlxDBWrapper) QueryX(query string, args ...any) (*sqlx.Rows, error) {
|
||||
query = w.DB.Rebind(query)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), w.queryTimeout)
|
||||
defer cancel()
|
||||
@@ -223,7 +223,7 @@ func (w *sqlxDBWrapper) QueryX(query string, args ...interface{}) (*sqlx.Rows, e
|
||||
return w.DB.QueryxContext(ctx, query, args)
|
||||
}
|
||||
|
||||
func (w *sqlxDBWrapper) Select(dest interface{}, query string, args ...interface{}) error {
|
||||
func (w *sqlxDBWrapper) Select(dest any, query string, args ...any) error {
|
||||
query = w.DB.Rebind(query)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), w.queryTimeout)
|
||||
defer cancel()
|
||||
@@ -237,7 +237,7 @@ func (w *sqlxDBWrapper) Select(dest interface{}, query string, args ...interface
|
||||
return w.DB.SelectContext(ctx, dest, query, args...)
|
||||
}
|
||||
|
||||
func (w *sqlxDBWrapper) SelectBuilder(dest interface{}, builder Builder) error {
|
||||
func (w *sqlxDBWrapper) SelectBuilder(dest any, builder Builder) error {
|
||||
query, args, err := builder.ToSql()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -260,7 +260,7 @@ func newSqlxTxWrapper(tx *sqlx.Tx, timeout time.Duration, trace bool) *sqlxTxWra
|
||||
}
|
||||
}
|
||||
|
||||
func (w *sqlxTxWrapper) Get(dest interface{}, query string, args ...interface{}) error {
|
||||
func (w *sqlxTxWrapper) Get(dest any, query string, args ...any) error {
|
||||
query = w.Tx.Rebind(query)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), w.queryTimeout)
|
||||
defer cancel()
|
||||
@@ -274,7 +274,7 @@ func (w *sqlxTxWrapper) Get(dest interface{}, query string, args ...interface{})
|
||||
return w.Tx.GetContext(ctx, dest, query, args...)
|
||||
}
|
||||
|
||||
func (w *sqlxTxWrapper) GetBuilder(dest interface{}, builder Builder) error {
|
||||
func (w *sqlxTxWrapper) GetBuilder(dest any, builder Builder) error {
|
||||
query, args, err := builder.ToSql()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -283,13 +283,13 @@ func (w *sqlxTxWrapper) GetBuilder(dest interface{}, builder Builder) error {
|
||||
return w.Get(dest, query, args...)
|
||||
}
|
||||
|
||||
func (w *sqlxTxWrapper) Exec(query string, args ...interface{}) (sql.Result, error) {
|
||||
func (w *sqlxTxWrapper) Exec(query string, args ...any) (sql.Result, error) {
|
||||
query = w.Tx.Rebind(query)
|
||||
|
||||
return w.ExecRaw(query, args...)
|
||||
}
|
||||
|
||||
func (w *sqlxTxWrapper) ExecNoTimeout(query string, args ...interface{}) (sql.Result, error) {
|
||||
func (w *sqlxTxWrapper) ExecNoTimeout(query string, args ...any) (sql.Result, error) {
|
||||
query = w.Tx.Rebind(query)
|
||||
|
||||
if w.trace {
|
||||
@@ -312,7 +312,7 @@ func (w *sqlxTxWrapper) ExecBuilder(builder Builder) (sql.Result, error) {
|
||||
|
||||
// ExecRaw is like Exec but without any rebinding of params. You need to pass
|
||||
// the exact param types of your target database.
|
||||
func (w *sqlxTxWrapper) ExecRaw(query string, args ...interface{}) (sql.Result, error) {
|
||||
func (w *sqlxTxWrapper) ExecRaw(query string, args ...any) (sql.Result, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), w.queryTimeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -325,7 +325,7 @@ func (w *sqlxTxWrapper) ExecRaw(query string, args ...interface{}) (sql.Result,
|
||||
return w.Tx.ExecContext(ctx, query, args...)
|
||||
}
|
||||
|
||||
func (w *sqlxTxWrapper) NamedExec(query string, arg interface{}) (sql.Result, error) {
|
||||
func (w *sqlxTxWrapper) NamedExec(query string, arg any) (sql.Result, error) {
|
||||
if w.Tx.DriverName() == model.DatabaseDriverPostgres {
|
||||
query = namedParamRegex.ReplaceAllStringFunc(query, strings.ToLower)
|
||||
}
|
||||
@@ -341,7 +341,7 @@ func (w *sqlxTxWrapper) NamedExec(query string, arg interface{}) (sql.Result, er
|
||||
return w.Tx.NamedExecContext(ctx, query, arg)
|
||||
}
|
||||
|
||||
func (w *sqlxTxWrapper) NamedQuery(query string, arg interface{}) (*sqlx.Rows, error) {
|
||||
func (w *sqlxTxWrapper) NamedQuery(query string, arg any) (*sqlx.Rows, error) {
|
||||
if w.Tx.DriverName() == model.DatabaseDriverPostgres {
|
||||
query = namedParamRegex.ReplaceAllStringFunc(query, strings.ToLower)
|
||||
}
|
||||
@@ -385,7 +385,7 @@ func (w *sqlxTxWrapper) NamedQuery(query string, arg interface{}) (*sqlx.Rows, e
|
||||
return res.rows, res.err
|
||||
}
|
||||
|
||||
func (w *sqlxTxWrapper) QueryRowX(query string, args ...interface{}) *sqlx.Row {
|
||||
func (w *sqlxTxWrapper) QueryRowX(query string, args ...any) *sqlx.Row {
|
||||
query = w.Tx.Rebind(query)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), w.queryTimeout)
|
||||
defer cancel()
|
||||
@@ -399,7 +399,7 @@ func (w *sqlxTxWrapper) QueryRowX(query string, args ...interface{}) *sqlx.Row {
|
||||
return w.Tx.QueryRowxContext(ctx, query, args...)
|
||||
}
|
||||
|
||||
func (w *sqlxTxWrapper) QueryX(query string, args ...interface{}) (*sqlx.Rows, error) {
|
||||
func (w *sqlxTxWrapper) QueryX(query string, args ...any) (*sqlx.Rows, error) {
|
||||
query = w.Tx.Rebind(query)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), w.queryTimeout)
|
||||
defer cancel()
|
||||
@@ -413,7 +413,7 @@ func (w *sqlxTxWrapper) QueryX(query string, args ...interface{}) (*sqlx.Rows, e
|
||||
return w.Tx.QueryxContext(ctx, query, args)
|
||||
}
|
||||
|
||||
func (w *sqlxTxWrapper) Select(dest interface{}, query string, args ...interface{}) error {
|
||||
func (w *sqlxTxWrapper) Select(dest any, query string, args ...any) error {
|
||||
query = w.Tx.Rebind(query)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), w.queryTimeout)
|
||||
defer cancel()
|
||||
@@ -427,7 +427,7 @@ func (w *sqlxTxWrapper) Select(dest interface{}, query string, args ...interface
|
||||
return w.Tx.SelectContext(ctx, dest, query, args...)
|
||||
}
|
||||
|
||||
func (w *sqlxTxWrapper) SelectBuilder(dest interface{}, builder Builder) error {
|
||||
func (w *sqlxTxWrapper) SelectBuilder(dest any, builder Builder) error {
|
||||
query, args, err := builder.ToSql()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -446,7 +446,7 @@ func removeSpace(r rune) rune {
|
||||
return r
|
||||
}
|
||||
|
||||
func printArgs(query string, dur time.Duration, args ...interface{}) {
|
||||
func printArgs(query string, dur time.Duration, args ...any) {
|
||||
query = strings.Map(removeSpace, query)
|
||||
fields := make([]mlog.Field, 0, len(args)+1)
|
||||
fields = append(fields, mlog.Duration("duration", dur))
|
||||
|
||||
Ссылка в новой задаче
Block a user