db

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2018 License: Apache-2.0 Imports: 12 Imported by: 17

Documentation

Index

Constants

View Source
const DefaultMaxOpenConn = 100

DefaultMaxOpenConn will applied for db object

Variables

This section is empty.

Functions

func CopyDBResources

func CopyDBResources(input, output DB, overrideExisting bool) error

CopyDBResources copies resources from input database to output database

func GetRetryInterval

func GetRetryInterval(retryInterval time.Duration) time.Duration

func InitDBConnWithSchemas

func InitDBConnWithSchemas(aDb DB, initDBParams InitDBParams) error

InitDBConnWithSchemas initializes database connection using schemas stored in Manager

func InitDBWithSchemas

func InitDBWithSchemas(dbType, dbConnection string, initDBParams InitDBParams) error

InitDBWithSchemas initializes database using schemas stored in Manager

func IsDeadlock

func IsDeadlock(err error) bool

IsDeadlock checks if error is deadlock

func Within

func Within(db DB, fn func(transaction.Transaction) error) error

Within executes a scoped transaction on a database

func WithinTemplate

func WithinTemplate(
	retries int,
	retryStrategy func() time.Duration,
	beginStrategy func() (ITransaction, error),
	fn func(ITransaction) error,
) error

func WithinTx

func WithinTx(ctx context.Context, db DB, options *transaction.TxOptions, fn func(transaction.Transaction) error) error

WithinTx executes a scoped transaction with options on a database

Types

type DB

type DB interface {
	Connect(string, string, int) error
	Close()
	Begin() (transaction.Transaction, error)
	BeginTx(ctx context.Context, options *transaction.TxOptions) (transaction.Transaction, error)
	RegisterTable(s *schema.Schema, cascade, migrate bool) error
	DropTable(*schema.Schema) error

	// options
	Options() options.Options
}

DB is a common interface for handing db

func ConnectDB

func ConnectDB(dbType, conn string, maxOpenConn int, opt options.Options) (DB, error)

ConnectDB is builder function of DB

func CreateFromConfig

func CreateFromConfig(config *util.Config) (DB, error)

CreateFromConfig creates db connection from config

type ITransaction

type ITransaction interface {
	Commit() error
	Close() error
	Closed() bool
}

ITransaction is a common interface for transaction

type InitDBParams

type InitDBParams struct {
	DropOnCreate, Cascade, AutoMigrate, AllowEmpty bool
}

func DefaultTestInitDBParams

func DefaultTestInitDBParams() InitDBParams

Directories

Path Synopsis
Package mock_db is a generated GoMock package.
Package mock_db is a generated GoMock package.
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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