mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 15:22:26 +08:00
Chore: Replace xorm with sqlx (#52575)
* Change of sqlstore to use sqlx * Use sqlx in the playlist store * Refectory of the interface * update playlist service * go mod tidy * some refectory on interface * fix kyle
This commit is contained in:
@ -12,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-sql-driver/mysql"
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/lib/pq"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"xorm.io/xorm"
|
||||
@ -27,6 +28,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrations"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/session"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/sqlutil"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@ -44,6 +46,7 @@ type ContextSessionKey struct{}
|
||||
|
||||
type SQLStore struct {
|
||||
Cfg *setting.Cfg
|
||||
sqlxsession *session.SessionDB
|
||||
CacheService *localcache.CacheService
|
||||
|
||||
bus bus.Bus
|
||||
@ -183,6 +186,13 @@ func (ss *SQLStore) Bus() bus.Bus {
|
||||
return ss.bus
|
||||
}
|
||||
|
||||
func (ss *SQLStore) GetSqlxSession() *session.SessionDB {
|
||||
if ss.sqlxsession == nil {
|
||||
ss.sqlxsession = session.GetSession(sqlx.NewDb(ss.engine.DB().DB, ss.GetDialect().DriverName()))
|
||||
}
|
||||
return ss.sqlxsession
|
||||
}
|
||||
|
||||
func (ss *SQLStore) ensureMainOrgAndAdminUser() error {
|
||||
ctx := context.Background()
|
||||
err := ss.WithTransactionalDbSession(ctx, func(sess *DBSession) error {
|
||||
@ -285,7 +295,7 @@ func (ss *SQLStore) buildConnectionString() (string, error) {
|
||||
cnnstr += fmt.Sprintf("&tx_isolation=%s", val)
|
||||
}
|
||||
|
||||
if ss.Cfg.IsFeatureToggleEnabled("mysqlAnsiQuotes") {
|
||||
if ss.Cfg.IsFeatureToggleEnabled("mysqlAnsiQuotes") || ss.Cfg.IsFeatureToggleEnabled("newDBLibrary") {
|
||||
cnnstr += "&sql_mode='ANSI_QUOTES'"
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user