[MM-39629] - Migrate from gorp to sqlx in store/sqlstore/thread_store.go (#19094)

Automatic Merge
Этот коммит содержится в:
Penthaa Patel
2022-02-10 09:34:18 +05:30
коммит произвёл GitHub
родитель c4dcf116c4
Коммит 7c9708ef49
3 изменённых файлов: 345 добавлений и 62 удалений

Просмотреть файл

@@ -18,6 +18,19 @@ import (
"github.com/mattermost/mattermost-server/v6/shared/mlog"
)
// 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
NamedExec(query string, arg interface{}) (sql.Result, error)
Exec(query string, args ...interface{}) (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
}
// namedParamRegex is used to capture all named parameters and convert them
// to lowercase. This is necessary to be able to use a single query for both
// Postgres and MySQL.
@@ -90,6 +103,12 @@ func (w *sqlxDBWrapper) NamedExec(query string, arg interface{}) (sql.Result, er
func (w *sqlxDBWrapper) Exec(query string, args ...interface{}) (sql.Result, error) {
query = w.DB.Rebind(query)
return w.ExecRaw(query, args...)
}
// 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) {
ctx, cancel := context.WithTimeout(context.Background(), w.queryTimeout)
defer cancel()
@@ -191,6 +210,12 @@ func (w *sqlxTxWrapper) Get(dest interface{}, query string, args ...interface{})
func (w *sqlxTxWrapper) Exec(query string, args ...interface{}) (sql.Result, error) {
query = w.Tx.Rebind(query)
return w.ExecRaw(query, args...)
}
// 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) {
ctx, cancel := context.WithTimeout(context.Background(), w.queryTimeout)
defer cancel()