This reverts commit 280bc7f97e.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
6a9c4ad56b
Коммит
ea3ff49b35
@@ -64,17 +64,15 @@ var namedParamRegex = regexp.MustCompile(`:\w+`)
|
||||
|
||||
type sqlxDBWrapper struct {
|
||||
*sqlx.DB
|
||||
queryTimeout time.Duration
|
||||
trace bool
|
||||
debugbarPublish func(string, float64, ...any)
|
||||
queryTimeout time.Duration
|
||||
trace bool
|
||||
}
|
||||
|
||||
func newSqlxDBWrapper(db *sqlx.DB, timeout time.Duration, trace bool, debugbarPublish func(string, float64, ...any)) *sqlxDBWrapper {
|
||||
func newSqlxDBWrapper(db *sqlx.DB, timeout time.Duration, trace bool) *sqlxDBWrapper {
|
||||
return &sqlxDBWrapper{
|
||||
DB: db,
|
||||
queryTimeout: timeout,
|
||||
trace: trace,
|
||||
debugbarPublish: debugbarPublish,
|
||||
DB: db,
|
||||
queryTimeout: timeout,
|
||||
trace: trace,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +86,7 @@ func (w *sqlxDBWrapper) Beginx() (*sqlxTxWrapper, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newSqlxTxWrapper(tx, w.queryTimeout, w.trace, w.debugbarPublish), nil
|
||||
return newSqlxTxWrapper(tx, w.queryTimeout, w.trace), nil
|
||||
}
|
||||
|
||||
func (w *sqlxDBWrapper) BeginXWithIsolation(opts *sql.TxOptions) (*sqlxTxWrapper, error) {
|
||||
@@ -97,7 +95,7 @@ func (w *sqlxDBWrapper) BeginXWithIsolation(opts *sql.TxOptions) (*sqlxTxWrapper
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newSqlxTxWrapper(tx, w.queryTimeout, w.trace, w.debugbarPublish), nil
|
||||
return newSqlxTxWrapper(tx, w.queryTimeout, w.trace), nil
|
||||
}
|
||||
|
||||
func (w *sqlxDBWrapper) Get(dest any, query string, args ...any) error {
|
||||
@@ -110,11 +108,6 @@ func (w *sqlxDBWrapper) Get(dest any, query string, args ...any) error {
|
||||
printArgs(query, time.Since(then), args)
|
||||
}(time.Now())
|
||||
}
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.DB.GetContext(ctx, dest, query, args...)
|
||||
}
|
||||
@@ -141,12 +134,6 @@ func (w *sqlxDBWrapper) NamedExec(query string, arg any) (sql.Result, error) {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), arg)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.DB.NamedExecContext(ctx, query, arg)
|
||||
}
|
||||
|
||||
@@ -174,12 +161,6 @@ func (w *sqlxDBWrapper) ExecNoTimeout(query string, args ...any) (sql.Result, er
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.DB.ExecContext(context.Background(), query, args...)
|
||||
}
|
||||
|
||||
@@ -195,12 +176,6 @@ func (w *sqlxDBWrapper) ExecRaw(query string, args ...any) (sql.Result, error) {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.DB.ExecContext(ctx, query, args...)
|
||||
}
|
||||
|
||||
@@ -217,12 +192,6 @@ func (w *sqlxDBWrapper) NamedQuery(query string, arg any) (*sqlx.Rows, error) {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), arg)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.DB.NamedQueryContext(ctx, query, arg)
|
||||
}
|
||||
|
||||
@@ -237,12 +206,6 @@ func (w *sqlxDBWrapper) QueryRowX(query string, args ...any) *sqlx.Row {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.DB.QueryRowxContext(ctx, query, args...)
|
||||
}
|
||||
|
||||
@@ -257,12 +220,6 @@ func (w *sqlxDBWrapper) QueryX(query string, args ...any) (*sqlx.Rows, error) {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.DB.QueryxContext(ctx, query, args)
|
||||
}
|
||||
|
||||
@@ -281,12 +238,6 @@ func (w *sqlxDBWrapper) SelectCtx(ctx context.Context, dest any, query string, a
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.DB.SelectContext(ctx, dest, query, args...)
|
||||
}
|
||||
|
||||
@@ -301,17 +252,15 @@ func (w *sqlxDBWrapper) SelectBuilder(dest any, builder Builder) error {
|
||||
|
||||
type sqlxTxWrapper struct {
|
||||
*sqlx.Tx
|
||||
queryTimeout time.Duration
|
||||
trace bool
|
||||
debugbarPublish func(string, float64, ...any)
|
||||
queryTimeout time.Duration
|
||||
trace bool
|
||||
}
|
||||
|
||||
func newSqlxTxWrapper(tx *sqlx.Tx, timeout time.Duration, trace bool, debugbarPublish func(string, float64, ...any)) *sqlxTxWrapper {
|
||||
func newSqlxTxWrapper(tx *sqlx.Tx, timeout time.Duration, trace bool) *sqlxTxWrapper {
|
||||
return &sqlxTxWrapper{
|
||||
Tx: tx,
|
||||
queryTimeout: timeout,
|
||||
trace: trace,
|
||||
debugbarPublish: debugbarPublish,
|
||||
Tx: tx,
|
||||
queryTimeout: timeout,
|
||||
trace: trace,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,12 +275,6 @@ func (w *sqlxTxWrapper) Get(dest any, query string, args ...any) error {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.Tx.GetContext(ctx, dest, query, args...)
|
||||
}
|
||||
|
||||
@@ -359,12 +302,6 @@ func (w *sqlxTxWrapper) ExecNoTimeout(query string, args ...any) (sql.Result, er
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.Tx.ExecContext(context.Background(), query, args...)
|
||||
}
|
||||
|
||||
@@ -389,12 +326,6 @@ func (w *sqlxTxWrapper) ExecRaw(query string, args ...any) (sql.Result, error) {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.Tx.ExecContext(ctx, query, args...)
|
||||
}
|
||||
|
||||
@@ -411,12 +342,6 @@ func (w *sqlxTxWrapper) NamedExec(query string, arg any) (sql.Result, error) {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), arg)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.Tx.NamedExecContext(ctx, query, arg)
|
||||
}
|
||||
|
||||
@@ -433,12 +358,6 @@ func (w *sqlxTxWrapper) NamedQuery(query string, arg any) (*sqlx.Rows, error) {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), arg)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
// There is no tx.NamedQueryContext support in the sqlx API. (https://github.com/jmoiron/sqlx/issues/447)
|
||||
// So we need to implement this ourselves.
|
||||
type result struct {
|
||||
@@ -481,12 +400,6 @@ func (w *sqlxTxWrapper) QueryRowX(query string, args ...any) *sqlx.Row {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.Tx.QueryRowxContext(ctx, query, args...)
|
||||
}
|
||||
|
||||
@@ -501,12 +414,6 @@ func (w *sqlxTxWrapper) QueryX(query string, args ...any) (*sqlx.Rows, error) {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.Tx.QueryxContext(ctx, query, args)
|
||||
}
|
||||
|
||||
@@ -521,12 +428,6 @@ func (w *sqlxTxWrapper) Select(dest any, query string, args ...any) error {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.Tx.SelectContext(ctx, dest, query, args...)
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user