Replace remaining GetMaster() queries (#19545)
There are still some remaining which access the raw DB struct. There will be a separate PR to clean those up. ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
256427f7f9
Коммит
678c7d3b8c
@@ -14,10 +14,32 @@ import (
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
||||
"github.com/mattermost/gorp"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
"github.com/mattermost/mattermost-server/v6/store/storetest"
|
||||
)
|
||||
|
||||
type StoreTestWrapper struct {
|
||||
orig *SqlStore
|
||||
}
|
||||
|
||||
func NewStoreTestWrapper(orig *SqlStore) *StoreTestWrapper {
|
||||
return &StoreTestWrapper{orig}
|
||||
}
|
||||
|
||||
func (w *StoreTestWrapper) GetMaster() *gorp.DbMap {
|
||||
return w.orig.GetMaster()
|
||||
}
|
||||
|
||||
func (w *StoreTestWrapper) GetMasterX() storetest.SqlXExecutor {
|
||||
return w.orig.GetMasterX()
|
||||
}
|
||||
|
||||
func (w *StoreTestWrapper) DriverName() string {
|
||||
return w.orig.DriverName()
|
||||
}
|
||||
|
||||
// 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 {
|
||||
@@ -106,6 +128,18 @@ func (w *sqlxDBWrapper) Exec(query string, args ...interface{}) (sql.Result, err
|
||||
return w.ExecRaw(query, args...)
|
||||
}
|
||||
|
||||
func (w *sqlxDBWrapper) ExecNoTimeout(query string, args ...interface{}) (sql.Result, error) {
|
||||
query = w.DB.Rebind(query)
|
||||
|
||||
if w.trace {
|
||||
defer func(then time.Time) {
|
||||
printArgs(query, time.Since(then), args)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.DB.ExecContext(context.Background(), 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) {
|
||||
|
||||
Ссылка в новой задаче
Block a user