mirror of
https://github.com/grafana/grafana.git
synced 2024-11-24 09:50:29 -06:00
cc007e9727
* chore: remove unused test helper from sqlstore TimeNow() is no longer used in any tests in this package. * chore: move sqlstore.SQLBuilder to the infra/db package This required some minor refactoring; we need to be a little more explicit about passing around the dialect and engine. On the other hand, that's a few fewer uses of the `dialect` global constant! * chore: move UserDeletions into the only package using it * cleanup around moving sqlbuilder * remove dialect and sqlog global vars * rename userDeletions to serviceAccountDeletions
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"xorm.io/core"
|
|
|
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/session"
|
|
)
|
|
|
|
type DB interface {
|
|
WithTransactionalDbSession(ctx context.Context, callback sqlstore.DBTransactionFunc) error
|
|
WithDbSession(ctx context.Context, callback sqlstore.DBTransactionFunc) error
|
|
WithNewDbSession(ctx context.Context, callback sqlstore.DBTransactionFunc) error
|
|
GetDialect() migrator.Dialect
|
|
GetDBType() core.DbType
|
|
GetSqlxSession() *session.SessionDB
|
|
InTransaction(ctx context.Context, fn func(ctx context.Context) error) error
|
|
Quote(value string) string
|
|
}
|
|
|
|
type Session = sqlstore.DBSession
|
|
type InitTestDBOpt = sqlstore.InitTestDBOpt
|
|
|
|
var InitTestDB = sqlstore.InitTestDB
|
|
var InitTestDBwithCfg = sqlstore.InitTestDBWithCfg
|
|
var ProvideService = sqlstore.ProvideService
|
|
|
|
func IsTestDbSQLite() bool {
|
|
if db, present := os.LookupEnv("GRAFANA_TEST_DB"); !present || db == "sqlite" {
|
|
return true
|
|
}
|
|
|
|
return !IsTestDbMySQL() && !IsTestDbPostgres()
|
|
}
|
|
|
|
func IsTestDbMySQL() bool {
|
|
if db, present := os.LookupEnv("GRAFANA_TEST_DB"); present {
|
|
return db == migrator.MySQL
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func IsTestDbPostgres() bool {
|
|
if db, present := os.LookupEnv("GRAFANA_TEST_DB"); present {
|
|
return db == migrator.Postgres
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func IsTestDBMSSQL() bool {
|
|
if db, present := os.LookupEnv("GRAFANA_TEST_DB"); present {
|
|
return db == migrator.MSSQL
|
|
}
|
|
|
|
return false
|
|
}
|