Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedSQLDriver        = errors.New("unsupported sql driver")
	ErrFailedToEstablishConnection = errors.New("failed to establish connection")

	ErrMigrationsOutOfSync = errors.New("migrations out of sync: not all migrations applied")
)

Functions

func ApplyMigrations

func ApplyMigrations(
	ctx context.Context,
	logger logx.Logger,
	conn *DB,
	tableName string,
	migrations []Migration,
) error

func Commit

func Commit(logger logx.Logger, tx *Tx, err error) error

func RetrieveAppliedMigrations

func RetrieveAppliedMigrations(
	ctx context.Context,
	logger logx.Logger,
	conn *DB,
	tableName string,
) (map[int]AppliedMigration, error)

func RollbackMigrations

func RollbackMigrations(
	ctx context.Context,
	logger logx.Logger,
	conn *DB,
	tableName string,
	migrations []Migration,
	all bool,
) error

func VerifyAppliedMigrations

func VerifyAppliedMigrations(
	ctx context.Context,
	logger logx.Logger,
	conn *DB,
	tableName string,
	migrations []Migration,
) error

Types

type AppliedMigration

type AppliedMigration struct {
	Version   int
	Name      string
	AppliedAt time.Time
}

type DB

type DB struct {
	Conn *sql.DB
	// contains filtered or unexported fields
}

func Connect

func Connect(driver DBDriver, options ...DBOption) (*DB, error)

func (*DB) BeginTx

func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

    BeginTx will generate a Database-aware transaction, with all database information duplicated from the Database-aware connection

    func (*DB) Close

    func (db *DB) Close() error

    func (*DB) Exec

    func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error)

    func (*DB) ExecContext

    func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

    func (*DB) Ping

    func (db *DB) Ping() error

    func (*DB) Query

    func (db *DB) Query(query string, args ...interface{}) (*sql.Rows, error)

    func (*DB) QueryContext

    func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

    func (*DB) QueryRow

    func (db *DB) QueryRow(query string, args ...interface{}) squirrel.RowScanner

    func (*DB) QueryRowContext

    func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) squirrel.RowScanner

    type DBDriver

    type DBDriver string
    const (
    	DBDriverMySQL DBDriver = "mysql"
    )

    type DBOption

    type DBOption interface {
    	// contains filtered or unexported methods
    }

    func DBConnectionMaxLifetime

    func DBConnectionMaxLifetime(max time.Duration) DBOption

    func DBDatabaseName

    func DBDatabaseName(dbName string) DBOption

    func DBHost

    func DBHost(host string) DBOption

    func DBPassword

    func DBPassword(password string) DBOption

    func DBPort

    func DBPort(port int) DBOption

    func DBRootCAPool

    func DBRootCAPool(rootCAPool *x509.CertPool) DBOption

    func DBUsername

    func DBUsername(username string) DBOption

    type Migration

    type Migration struct {
    	Name string
    	Up   MigrationFunc
    	Down MigrationFunc
    }

    type MigrationFunc

    type MigrationFunc func(context.Context, logx.Logger, *Tx) error

    type Tx

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

    func (*Tx) Commit

    func (tx *Tx) Commit() error

    func (*Tx) Exec

    func (tx *Tx) Exec(query string, args ...interface{}) (sql.Result, error)

    func (*Tx) ExecContext

    func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

    func (*Tx) Query

    func (tx *Tx) Query(query string, args ...interface{}) (*sql.Rows, error)

    func (*Tx) QueryContext

    func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

    func (*Tx) QueryRow

    func (tx *Tx) QueryRow(query string, args ...interface{}) squirrel.RowScanner

    func (*Tx) QueryRowContext

    func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...interface{}) squirrel.RowScanner

    func (*Tx) Rollback

    func (tx *Tx) Rollback() error

    Directories

    Path Synopsis