mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 16:15:42 -06:00
* chore: add alias for InitTestDB and Session Adds an alias for the sqlstore InitTestDB and Session, and updates tests using these to reduce dependencies on the sqlstore.Store. * next pass of removing sqlstore imports * last little bit * remove mockstore where possible
56 lines
1.4 KiB
Go
56 lines
1.4 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
|
|
}
|
|
|
|
type Session = sqlstore.DBSession
|
|
type SQLBuilder = sqlstore.SQLBuilder
|
|
type InitTestDBOpt = sqlstore.InitTestDBOpt
|
|
|
|
var InitTestDB = sqlstore.InitTestDB
|
|
var InitTestDBwithCfg = sqlstore.InitTestDBWithCfg
|
|
var ProvideService = sqlstore.ProvideService
|
|
var NewSqlBuilder = sqlstore.NewSqlBuilder
|
|
|
|
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
|
|
}
|