Documentation
¶
Overview ¶
DO NOT ADD METHODS TO THIS FILES. SQLSTORE IS DEPRECATED AND WILL BE REMOVED.
Index ¶
- Constants
- Variables
- func CleanupTestDB()
- func InBatches(items any, opts BulkOpSettings, fn func(batch any) error) error
- func SetupTestDB()
- func WrapDatabaseDriverWithHooks(dbType string, tracer tracing.Tracer) string
- type BulkOpSettings
- type ContextSessionKey
- type DBSession
- func (sess *DBSession) BulkInsert(table any, recordsSlice any, opts BulkOpSettings) (int64, error)
- func (sess *DBSession) InsertId(bean any, dialect migrator.Dialect) error
- func (sess *DBSession) PublishAfterCommit(msg any)
- func (sess *DBSession) WithReturningID(driverName string, query string, args []any) (int64, error)
- type DBTransactionFunc
- type DatabaseConfig
- type InitTestDBOpt
- type SQLStore
- func InitTestDB(t sqlutil.ITestDB, opts ...InitTestDBOpt) (*SQLStore, *setting.Cfg)
- func InitTestDBWithMigration(t sqlutil.ITestDB, migration registry.DatabaseMigrator, opts ...InitTestDBOpt) *SQLStore
- func NewSQLStoreWithoutSideEffects(cfg *setting.Cfg, features featuremgmt.FeatureToggles, bus bus.Bus, ...) (*SQLStore, error)
- func NewTestStore(tb TestingTB, opts ...TestOption) *SQLStore
- func ProvideService(cfg *setting.Cfg, features featuremgmt.FeatureToggles, ...) (*SQLStore, error)
- func ProvideServiceForTests(t sqlutil.ITestDB, cfg *setting.Cfg, features featuremgmt.FeatureToggles, ...) (*SQLStore, error)
- func (ss *SQLStore) Bus() bus.Bus
- func (ss *SQLStore) GetDBType() core.DbType
- func (ss *SQLStore) GetDialect() migrator.Dialect
- func (ss *SQLStore) GetEngine() *xorm.Engine
- func (ss *SQLStore) GetMigrationLockAttemptTimeout() int
- func (ss *SQLStore) GetSqlxSession() *session.SessionDB
- func (ss *SQLStore) InTransaction(ctx context.Context, fn func(ctx context.Context) error) error
- func (ss *SQLStore) Migrate(isDatabaseLockingEnabled bool) error
- func (ss *SQLStore) Quote(value string) string
- func (ss *SQLStore) RecursiveQueriesAreSupported() (bool, error)
- func (ss *SQLStore) Reset() error
- func (ss *SQLStore) WithDbSession(ctx context.Context, callback DBTransactionFunc) error
- func (ss *SQLStore) WithTransactionalDbSession(ctx context.Context, callback DBTransactionFunc) error
- type TestOption
- func WithCfg(cfg *setting.Cfg) TestOption
- func WithFeatureFlag(flag string, val bool) TestOption
- func WithFeatureFlags(flags ...string) TestOption
- func WithMigrator(migrator registry.DatabaseMigrator) TestOption
- func WithOSSMigrations() TestOption
- func WithTracer(tracer tracing.Tracer, bus bus.Bus) TestOption
- func WithTruncation() TestOption
- func WithoutDefaultOrgAndUser() TestOption
- func WithoutFeatureFlags(flags ...string) TestOption
- func WithoutMigrator() TestOption
- type TestingTB
- type XormLogger
- func (s *XormLogger) Debug(v ...any)
- func (s *XormLogger) Debugf(format string, v ...any)
- func (s *XormLogger) Error(v ...any)
- func (s *XormLogger) Errorf(format string, v ...any)
- func (s *XormLogger) Info(v ...any)
- func (s *XormLogger) Infof(format string, v ...any)
- func (s *XormLogger) IsShowSQL() bool
- func (s *XormLogger) Level() core.LogLevel
- func (s *XormLogger) SetLevel(l core.LogLevel)
- func (s *XormLogger) ShowSQL(show ...bool)
- func (s *XormLogger) Warn(v ...any)
- func (s *XormLogger) Warnf(format string, v ...any)
Constants ¶
const DefaultBatchSize = 1000
Variables ¶
var ErrMaximumRetriesReached = errutil.Internal("sqlstore.max-retries-reached")
Functions ¶
func CleanupTestDB ¶
func CleanupTestDB()
func SetupTestDB ¶
func SetupTestDB()
Types ¶
type BulkOpSettings ¶
type BulkOpSettings struct {
BatchSize int
}
func NativeSettingsForDialect ¶
func NativeSettingsForDialect(d migrator.Dialect) BulkOpSettings
type ContextSessionKey ¶
type ContextSessionKey struct{}
ContextSessionKey is used as key to save values in `context.Context`
type DBSession ¶
func (*DBSession) BulkInsert ¶
func (*DBSession) PublishAfterCommit ¶
type DBTransactionFunc ¶
type DatabaseConfig ¶
type DatabaseConfig struct {
Type string
Host string
Name string
User string
Pwd string
Path string
SslMode string
SSLSNI string
CaCertPath string
ClientKeyPath string
ClientCertPath string
ServerCertName string
ConnectionString string
IsolationLevel string
MaxOpenConn int
MaxIdleConn int
ConnMaxLifetime int
CacheMode string
WALEnabled bool
UrlQueryParams map[string][]string
SkipMigrations bool
EnsureDefaultOrgAndUser bool
MigrationLock bool
MigrationLockAttemptTimeout int
LogQueries bool
DeleteAutoGenIDs bool
// SQLite only
QueryRetries int
// SQLite only
TransactionRetries int
}
func NewDatabaseConfig ¶
func NewDatabaseConfig(cfg *setting.Cfg, features featuremgmt.FeatureToggles) (*DatabaseConfig, error)
type InitTestDBOpt ¶
InitTestDBOpt contains options for InitTestDB.
type SQLStore ¶
type SQLStore struct {
// contains filtered or unexported fields
}
func InitTestDB ¶
InitTestDB initializes the test DB.
func InitTestDBWithMigration ¶
func InitTestDBWithMigration(t sqlutil.ITestDB, migration registry.DatabaseMigrator, opts ...InitTestDBOpt) *SQLStore
InitTestDBWithMigration initializes the test DB given custom migrations.
func NewSQLStoreWithoutSideEffects ¶
func NewSQLStoreWithoutSideEffects(cfg *setting.Cfg, features featuremgmt.FeatureToggles, bus bus.Bus, tracer tracing.Tracer) (*SQLStore, error)
NewSQLStoreWithoutSideEffects creates a new *SQLStore without side-effects such as running database migrations and/or ensuring main org and admin user exists.
func NewTestStore ¶
func NewTestStore(tb TestingTB, opts ...TestOption) *SQLStore
NewTestStore creates a new SQLStore with a test database. It is useful in parallel tests. All cleanup is scheduled via the passed TestingTB; the caller does not need to do anything about it. Temporary, clean databases are created for each test, and are destroyed when the test finishes. When using subtests, create a new store for each subtest instead of sharing one across the entire test. By default, OSS migrations are run. Enterprise migrations need to be opted into manually. Migrations can also be opted out of entirely.
The opts are called in order. That means that a destructive option should be added last if you want it to be truly destructive.
func ProvideService ¶
func ProvideService(cfg *setting.Cfg, features featuremgmt.FeatureToggles, migrations registry.DatabaseMigrator, bus bus.Bus, tracer tracing.Tracer) (*SQLStore, error)
func ProvideServiceForTests ¶
func ProvideServiceForTests(t sqlutil.ITestDB, cfg *setting.Cfg, features featuremgmt.FeatureToggles, bus bus.Bus, migrations registry.DatabaseMigrator) (*SQLStore, error)
func (*SQLStore) GetDialect ¶
GetDialect return the dialect
func (*SQLStore) GetMigrationLockAttemptTimeout ¶
func (*SQLStore) GetSqlxSession ¶
func (*SQLStore) InTransaction ¶
InTransaction starts a transaction and calls the fn It stores the session in the context
func (*SQLStore) Migrate ¶
Migrate performs database migrations. Has to be done in a second phase (after initialization), since other services can register migrations during the initialization phase.
func (*SQLStore) RecursiveQueriesAreSupported ¶
func (*SQLStore) Reset ¶
Reset resets database state. If default org and user creation is enabled, it will be ensured they exist in the database.
func (*SQLStore) WithDbSession ¶
func (ss *SQLStore) WithDbSession(ctx context.Context, callback DBTransactionFunc) error
WithDbSession calls the callback with the session in the context (if exists). Otherwise it creates a new one that is closed upon completion. A session is stored in the context if sqlstore.InTransaction() has been previously called with the same context (and it's not committed/rolledback yet). In case of retryable errors, callback will be retried at most five times before giving up.
func (*SQLStore) WithTransactionalDbSession ¶
func (ss *SQLStore) WithTransactionalDbSession(ctx context.Context, callback DBTransactionFunc) error
WithTransactionalDbSession calls the callback with a session within a transaction.
type TestOption ¶
type TestOption func(*testOptions)
func WithCfg ¶
func WithCfg(cfg *setting.Cfg) TestOption
WithCfg configures a *setting.Cfg to base the configuration upon. Note that if this is set, we will modify the configuration object's [database] section.
func WithFeatureFlag ¶
func WithFeatureFlag(flag string, val bool) TestOption
WithFeatureFlag sets the flag to the specified value.
func WithFeatureFlags ¶
func WithFeatureFlags(flags ...string) TestOption
WithFeatureFlags adds the feature flags to the other flags already set with a value of true.
func WithMigrator ¶
func WithMigrator(migrator registry.DatabaseMigrator) TestOption
func WithOSSMigrations ¶
func WithOSSMigrations() TestOption
WithOSSMigrations sets the migrator to the OSS migrations. This effectively works _after_ all other options are passed, including WithMigrator.
func WithTracer ¶
func WithTracer(tracer tracing.Tracer, bus bus.Bus) TestOption
func WithTruncation ¶
func WithTruncation() TestOption
WithTruncation enables truncating the entire database's tables after setup. This is similar to the old infrastructure's behaviour.
Most tests should just run with the data the migrations create, as they should assume a position very close to a customer's database, and customers are not going to truncate their database before updating.
func WithoutDefaultOrgAndUser ¶
func WithoutDefaultOrgAndUser() TestOption
func WithoutFeatureFlags ¶
func WithoutFeatureFlags(flags ...string) TestOption
WithoutFeatureFlags adds the feature flags to the other flags already set with a value of true.
func WithoutMigrator ¶
func WithoutMigrator() TestOption
WithoutMigrator explicitly opts out of migrations.
type TestingTB ¶
type TestingTB interface {
// Helper marks the calling function as a test helper function. See also (*testing.T).Helper.
Helper()
// Cleanup registers a new function the testing suite will run after the test completes. See also (*testing.T).Cleanup.
Cleanup(func())
// Fatalf logs a message and marks the test as failed. The syntax is similar to that of fmt.Printf. See also (*testing.T).Fatalf.
Fatalf(format string, args ...any)
// Logf formats and logs its arguments. See also (*testing.T).Logf.
Logf(format string, args ...any)
// Context returns a context that is canceled just before Cleanup-registered functions are called. See also (*testing.T).Context.
Context() context.Context
}
TestingTB is an interface that is implemented by *testing.T and *testing.B. Similar to testing.TB.
type XormLogger ¶
type XormLogger struct {
// contains filtered or unexported fields
}
func NewXormLogger ¶
func NewXormLogger(level glog.Lvl, grafanaLog glog.Logger) *XormLogger
func (*XormLogger) Debugf ¶
func (s *XormLogger) Debugf(format string, v ...any)
Debugf implement core.ILogger
func (*XormLogger) Errorf ¶
func (s *XormLogger) Errorf(format string, v ...any)
Errorf implement core.ILogger
func (*XormLogger) Infof ¶
func (s *XormLogger) Infof(format string, v ...any)
Infof implement core.ILogger
func (*XormLogger) IsShowSQL ¶
func (s *XormLogger) IsShowSQL() bool
IsShowSQL implement core.ILogger
func (*XormLogger) SetLevel ¶
func (s *XormLogger) SetLevel(l core.LogLevel)
SetLevel implement core.ILogger
func (*XormLogger) ShowSQL ¶
func (s *XormLogger) ShowSQL(show ...bool)
ShowSQL implement core.ILogger
func (*XormLogger) Warnf ¶
func (s *XormLogger) Warnf(format string, v ...any)
Warnf implement core.ILogger
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package searchstore converts search queries to SQL.
|
Package searchstore converts search queries to SQL. |