sqlstore

package
v0.0.0-...-fb7f86c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2023 License: AGPL-3.0 Imports: 46 Imported by: 0

Documentation

Overview

DO NOT ADD METHODS TO THIS FILES. SQLSTORE IS DEPRECATED AND WILL BE REMOVED.

Index

Constants

View Source
const DefaultBatchSize = 1000

Variables

View Source
var ErrMaximumRetriesReached = errutil.NewBase(errutil.StatusInternal, "sqlstore.max-retries-reached")

Functions

func InBatches

func InBatches(items interface{}, opts BulkOpSettings, fn func(batch interface{}) error) error

func IsTestDBMSSQL

func IsTestDBMSSQL() bool

func IsTestDbMySQL

func IsTestDbMySQL() bool

func IsTestDbPostgres

func IsTestDbPostgres() bool

func WrapDatabaseDriverWithHooks

func WrapDatabaseDriverWithHooks(dbType string, tracer tracing.Tracer) string

WrapDatabaseDriverWithHooks creates a fake database driver that executes pre and post functions which we use to gather metrics about database queries. It also registers the metrics.

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

type DBSession struct {
	*xorm.Session
	// contains filtered or unexported fields
}

func (*DBSession) BulkInsert

func (sess *DBSession) BulkInsert(table interface{}, recordsSlice interface{}, opts BulkOpSettings) (int64, error)

func (*DBSession) InsertId

func (sess *DBSession) InsertId(bean interface{}, dialect migrator.Dialect) error

func (*DBSession) PublishAfterCommit

func (sess *DBSession) PublishAfterCommit(msg interface{})

func (*DBSession) WithReturningID

func (sess *DBSession) WithReturningID(driverName string, query string, args []interface{}) (int64, error)

type DBTransactionFunc

type DBTransactionFunc func(sess *DBSession) error

type DatabaseConfig

type DatabaseConfig struct {
	Type                        string
	Host                        string
	Name                        string
	User                        string
	Pwd                         string
	Path                        string
	SslMode                     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
	MigrationLockAttemptTimeout int
	// SQLite only
	QueryRetries int
	// SQLite only
	TransactionRetries int
}

type ITestDB

type ITestDB interface {
	Helper()
	Fatalf(format string, args ...interface{})
	Logf(format string, args ...interface{})
	Log(args ...interface{})
}

ITestDB is an interface of arguments for testing db

type InitTestDBOpt

type InitTestDBOpt struct {
	// EnsureDefaultOrgAndUser flags whether to ensure that default org and user exist.
	EnsureDefaultOrgAndUser bool
	FeatureFlags            []string
}

InitTestDBOpt contains options for InitTestDB.

type SQLStore

type SQLStore struct {
	Cfg *setting.Cfg

	CacheService *localcache.CacheService

	Dialect migrator.Dialect
	// contains filtered or unexported fields
}

func InitTestDB

func InitTestDB(t ITestDB, opts ...InitTestDBOpt) *SQLStore

InitTestDB initializes the test DB.

func InitTestDBWithCfg

func InitTestDBWithCfg(t ITestDB, opts ...InitTestDBOpt) (*SQLStore, *setting.Cfg)

func InitTestDBWithMigration

func InitTestDBWithMigration(t ITestDB, migration registry.DatabaseMigrator, opts ...InitTestDBOpt) *SQLStore

InitTestDBWithMigration initializes the test DB given custom migrations.

func ProvideService

func ProvideService(cfg *setting.Cfg, cacheService *localcache.CacheService, migrations registry.DatabaseMigrator, bus bus.Bus, tracer tracing.Tracer) (*SQLStore, error)

func ProvideServiceForTests

func ProvideServiceForTests(cfg *setting.Cfg, migrations registry.DatabaseMigrator) (*SQLStore, error)

func (*SQLStore) Bus

func (ss *SQLStore) Bus() bus.Bus

func (*SQLStore) GetDBType

func (ss *SQLStore) GetDBType() core.DbType

func (*SQLStore) GetDialect

func (ss *SQLStore) GetDialect() migrator.Dialect

GetDialect return the dialect

func (*SQLStore) GetEngine

func (ss *SQLStore) GetEngine() *xorm.Engine

func (*SQLStore) GetMigrationLockAttemptTimeout

func (ss *SQLStore) GetMigrationLockAttemptTimeout() int

func (*SQLStore) GetSqlxSession

func (ss *SQLStore) GetSqlxSession() *session.SessionDB

func (*SQLStore) InTransaction

func (ss *SQLStore) InTransaction(ctx context.Context, fn func(ctx context.Context) error) error

InTransaction starts a transaction and calls the fn It stores the session in the context

func (*SQLStore) Migrate

func (ss *SQLStore) Migrate(isDatabaseLockingEnabled bool) error

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) Quote

func (ss *SQLStore) Quote(value string) string

Quote quotes the value in the used SQL dialect

func (*SQLStore) RecursiveQueriesAreSupported

func (ss *SQLStore) RecursiveQueriesAreSupported() (bool, error)

func (*SQLStore) Reset

func (ss *SQLStore) Reset() error

Reset resets database state. If default org and user creation is enabled, it will be ensured they exist in the database.

func (*SQLStore) Sync

func (ss *SQLStore) Sync() error

Sync syncs changes to the database.

func (*SQLStore) TestReset

func (ss *SQLStore) TestReset() error

TestReset resets database state. If default org and user creation is enabled, it will be ensured they exist in the database. TestReset() is more permissive than Reset in that it will create the user and org whether or not there are already users 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 sqlite3.ErrLocked or sqlite3.ErrBusy failure it will be retried at most five times before giving up.

func (*SQLStore) WithNewDbSession

func (ss *SQLStore) WithNewDbSession(ctx context.Context, callback DBTransactionFunc) error

WithNewDbSession calls the callback with a new session that is closed upon completion. In case of sqlite3.ErrLocked or sqlite3.ErrBusy failure it 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 XormLogger

type XormLogger struct {
	// contains filtered or unexported fields
}

func NewXormLogger

func NewXormLogger(level glog.Lvl, grafanaLog glog.Logger) *XormLogger

func (*XormLogger) Debug

func (s *XormLogger) Debug(v ...interface{})

Debug implement core.ILogger

func (*XormLogger) Debugf

func (s *XormLogger) Debugf(format string, v ...interface{})

Debugf implement core.ILogger

func (*XormLogger) Error

func (s *XormLogger) Error(v ...interface{})

Error implement core.ILogger

func (*XormLogger) Errorf

func (s *XormLogger) Errorf(format string, v ...interface{})

Errorf implement core.ILogger

func (*XormLogger) Info

func (s *XormLogger) Info(v ...interface{})

Info implement core.ILogger

func (*XormLogger) Infof

func (s *XormLogger) Infof(format string, v ...interface{})

Infof implement core.ILogger

func (*XormLogger) IsShowSQL

func (s *XormLogger) IsShowSQL() bool

IsShowSQL implement core.ILogger

func (*XormLogger) Level

func (s *XormLogger) Level() core.LogLevel

Level 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) Warn

func (s *XormLogger) Warn(v ...interface{})

Warn implement core.ILogger

func (*XormLogger) Warnf

func (s *XormLogger) Warnf(format string, v ...interface{})

Warnf implement core.ILogger

Directories

Path Synopsis
Package searchstore converts search queries to SQL.
Package searchstore converts search queries to SQL.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL