dbsql

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// SQLConfMigrationsAuto enables automatic migrations
	SQLConfMigrationsAuto = "migrations.auto"
	// SQLConfMigrationsDirectory is the directory containing the numerically ordered migration DDL files to apply to the database
	SQLConfMigrationsDirectory = "migrations.directory"
	// SQLConfDatasourceURL is the datasource connection URL string
	SQLConfDatasourceURL = "url"
	// SQLConfMaxConnections maximum connections to the database
	SQLConfMaxConnections = "maxConns"
	// SQLConfMaxConnIdleTime maximum connections to the database
	SQLConfMaxConnIdleTime = "maxConnIdleTime"
	// SQLConfMaxIdleConns maximum connections to the database
	SQLConfMaxIdleConns = "maxIdleConns"
	// SQLConfMaxConnLifetime maximum connections to the database
	SQLConfMaxConnLifetime = "maxConnLifetime"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

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

func (*Database) AcquireLockTx

func (s *Database) AcquireLockTx(ctx context.Context, lockName string, tx *TXWrapper) error

func (*Database) BeginOrUseTx

func (s *Database) BeginOrUseTx(ctx context.Context) (ctx1 context.Context, tx *TXWrapper, autoCommit bool, err error)

func (*Database) BuildUpdate

func (s *Database) BuildUpdate(sel sq.UpdateBuilder, update ffapi.Update, typeMap map[string]string) (sq.UpdateBuilder, error)

func (*Database) Close

func (s *Database) Close()

func (*Database) CommitTx

func (s *Database) CommitTx(ctx context.Context, tx *TXWrapper, autoCommit bool) error

func (*Database) ConnLimit

func (s *Database) ConnLimit() int

func (*Database) CountQuery

func (s *Database) CountQuery(ctx context.Context, table string, tx *TXWrapper, fop sq.Sqlizer, countExpr string) (count int64, err error)

func (*Database) DB

func (s *Database) DB() *sql.DB

func (*Database) DeleteTx

func (s *Database) DeleteTx(ctx context.Context, table string, tx *TXWrapper, q sq.DeleteBuilder, postCommit func()) error

func (*Database) FilterSelect

func (s *Database) FilterSelect(ctx context.Context, tableName string, sel sq.SelectBuilder, filter ffapi.Filter, typeMap map[string]string, defaultSort []interface{}, preconditions ...sq.Sqlizer) (sq.SelectBuilder, sq.Sqlizer, *ffapi.FilterInfo, error)

func (*Database) FilterUpdate

func (s *Database) FilterUpdate(ctx context.Context, update sq.UpdateBuilder, filter ffapi.Filter, typeMap map[string]string) (sq.UpdateBuilder, error)

func (*Database) Init

func (s *Database) Init(ctx context.Context, provider Provider, config config.Section) (err error)

func (*Database) InitConfig

func (s *Database) InitConfig(provider Provider, config config.Section)

func (*Database) InsertTx

func (s *Database) InsertTx(ctx context.Context, table string, tx *TXWrapper, q sq.InsertBuilder, postCommit func()) (int64, error)

func (*Database) InsertTxExt

func (s *Database) InsertTxExt(ctx context.Context, table string, tx *TXWrapper, q sq.InsertBuilder, postCommit func(), requestConflictEmptyResult bool) (int64, error)

func (*Database) InsertTxRows

func (s *Database) InsertTxRows(ctx context.Context, table string, tx *TXWrapper, q sq.InsertBuilder, postCommit func(), sequences []int64, requestConflictEmptyResult bool) error

func (*Database) Query

func (s *Database) Query(ctx context.Context, table string, q sq.SelectBuilder) (*sql.Rows, *TXWrapper, error)

func (*Database) QueryRes

func (s *Database) QueryRes(ctx context.Context, table string, tx *TXWrapper, fop sq.Sqlizer, fi *ffapi.FilterInfo) *ffapi.FilterResult

func (*Database) QueryTx

func (s *Database) QueryTx(ctx context.Context, table string, tx *TXWrapper, q sq.SelectBuilder) (*sql.Rows, *TXWrapper, error)

func (*Database) RollbackTx

func (s *Database) RollbackTx(ctx context.Context, tx *TXWrapper, autoCommit bool)

RollbackTx be safely called as a defer, as it is a cheap no-op if the transaction is complete

func (*Database) RunAsGroup

func (s *Database) RunAsGroup(ctx context.Context, fn func(ctx context.Context) error) error

func (*Database) SequenceColumn

func (s *Database) SequenceColumn() string

func (*Database) UpdateTx

func (s *Database) UpdateTx(ctx context.Context, table string, tx *TXWrapper, q sq.UpdateBuilder, postCommit func()) (int64, error)

type PreCommitAccumulator

type PreCommitAccumulator interface {
	PreCommit(ctx context.Context, tx *TXWrapper) error
}

PreCommitAccumulator is a structure that can accumulate state during the transaction, then has a function that is called just before commit.

type Provider

type Provider interface {

	// Name is the name of the database driver
	Name() string

	// MigrationDir is the subdirectory for migrations
	MigrationsDir() string

	// SequenceColumn is the name of the sequence column to use
	SequenceColumn() string

	// Open creates the DB instances
	Open(url string) (*sql.DB, error)

	// GetDriver returns the driver implementation
	GetMigrationDriver(*sql.DB) (migratedb.Driver, error)

	// Features returns database specific configuration switches
	Features() SQLFeatures

	// ApplyInsertQueryCustomizations updates the INSERT query for returning the Sequence, and returns whether it needs to be run as a query to return the Sequence field
	ApplyInsertQueryCustomizations(insert sq.InsertBuilder, requestConflictEmptyResult bool) (updatedInsert sq.InsertBuilder, runAsQuery bool)
}

Provider defines the interface an individual provider muse implement to customize the Database implementation

type SQLFeatures

type SQLFeatures struct {
	UseILIKE          bool
	MultiRowInsert    bool
	PlaceholderFormat sq.PlaceholderFormat
	AcquireLock       func(lockName string) string
}

func DefaultSQLProviderFeatures

func DefaultSQLProviderFeatures() SQLFeatures

type TXWrapper

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

func (*TXWrapper) AddPostCommitHook

func (tx *TXWrapper) AddPostCommitHook(fn func())

func (*TXWrapper) PreCommitAccumulator

func (tx *TXWrapper) PreCommitAccumulator() PreCommitAccumulator

func (*TXWrapper) SetPreCommitAccumulator

func (tx *TXWrapper) SetPreCommitAccumulator(pca PreCommitAccumulator)

Jump to

Keyboard shortcuts

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