db

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2020 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SerializationRetryMaxAttempts   = 10
	SerializationRetryStartInterval = time.Millisecond * 2
)

Variables

View Source
var (
	ErrNotFound      = errors.New("not found")
	ErrAlreadyExists = errors.New("already exists")
	ErrSerialization = errors.New("serialization error")
)

Functions

func GetLastMigrationAvailable

func GetLastMigrationAvailable(from uint) (uint, error)

func IsSerializationError

func IsSerializationError(err error) bool

func IsUniqueViolation

func IsUniqueViolation(err error) bool

func MigrateDown

func MigrateDown(connectionString string) error

func MigrateTo

func MigrateTo(connectionString string, version uint) error

func MigrateUp

func MigrateUp(connectionString string) error

func MigrateVersion

func MigrateVersion(connectionString string) (uint, bool, error)

func Prefix

func Prefix(prefix string) string

Types

type Database

type Database interface {
	io.Closer
	Queryx(query string, args ...interface{}) (*Rows, error)
	Transact(fn TxFunc, opts ...TxOpt) (interface{}, error)
	Metadata() (map[string]string, error)
	Stats() sql.DBStats
}

func ConnectDB

func ConnectDB(driver string, uri string) (Database, error)

type DatabaseMigrator

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

func NewDatabaseMigrator

func NewDatabaseMigrator(connectionString string) *DatabaseMigrator

func (*DatabaseMigrator) Migrate

func (d *DatabaseMigrator) Migrate(ctx context.Context) error

type Migrator

type Migrator interface {
	Migrate(ctx context.Context) error
}

type Rows

type Rows = sqlx.Rows

type SqlxDatabase

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

func NewSqlxDatabase

func NewSqlxDatabase(db *sqlx.DB) *SqlxDatabase

func (*SqlxDatabase) Close

func (d *SqlxDatabase) Close() error

func (*SqlxDatabase) Metadata

func (d *SqlxDatabase) Metadata() (map[string]string, error)

func (*SqlxDatabase) Queryx

func (d *SqlxDatabase) Queryx(query string, args ...interface{}) (*Rows, error)

func (*SqlxDatabase) Stats

func (d *SqlxDatabase) Stats() sql.DBStats

func (*SqlxDatabase) Transact

func (d *SqlxDatabase) Transact(fn TxFunc, opts ...TxOpt) (interface{}, error)

type Tx

type Tx interface {
	Query(query string, args ...interface{}) (*sqlx.Rows, error)
	Select(dest interface{}, query string, args ...interface{}) error
	Get(dest interface{}, query string, args ...interface{}) error
	Exec(query string, args ...interface{}) (sql.Result, error)
}

type TxFunc

type TxFunc func(tx Tx) (interface{}, error)

type TxOpt

type TxOpt func(*TxOptions)

func ReadOnly

func ReadOnly() TxOpt

func WithContext

func WithContext(ctx context.Context) TxOpt

func WithIsolationLevel

func WithIsolationLevel(level sql.IsolationLevel) TxOpt

func WithLogger

func WithLogger(logger logging.Logger) TxOpt

type TxOptions

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

func DefaultTxOptions

func DefaultTxOptions() *TxOptions

Jump to

Keyboard shortcuts

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