db

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: Apache-2.0 Imports: 9 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyDSN = errors.New("empty dsn")

ErrEmptyDSN is returned when connecting without a DSN, which is a connection with nothing to connect to rather than one to retry.

Functions

func AcquireLock added in v0.0.2

func AcquireLock(ctx context.Context, tx *sqlx.Tx, driverName string, lockKey string) error

AcquireLock acquires a database-specific advisory lock for a given key. This is used to prevent concurrent migrations from conflicting. The lock is released when the transaction commits or rolls back.

func Connect

func Connect(ctx context.Context) (*sqlx.DB, error)

Connect connects to a database and produces the handle for injection. It takes its DSN from MIG_DB_DSN; use ConnectWithRetry to pass your own Options.

func ConnectWithOptions

func ConnectWithOptions(ctx context.Context, options *Options) (*sqlx.DB, error)

ConnectWithOptions connects to host based on Options{}.

func ConnectWithRetry

func ConnectWithRetry(ctx context.Context, options *Options) (db *sqlx.DB, err error)

ConnectWithRetry uses retry options set in Options{}.

func ParseDSN added in v0.3.1

func ParseDSN(conn string) (string, string)

ParseDSN will return driver and dsn valid for db.Open.

Types

type Credentials

type Credentials struct {
	DSN string
}

Credentials contains database connection DSN with a schema:// driver hint.

func NewCredentials added in v0.3.1

func NewCredentials(dsn string) Credentials

NewCredentials returns a filled Credentials.

func (Credentials) Open added in v0.3.0

func (c Credentials) Open() (string, string)

Open returns the driver and the connection string.

type Options

type Options struct {
	Credentials Credentials

	// Connector is an optional parameter to produce our
	// own *sql.DB, which is then wrapped in *sqlx.DB
	Connector func(context.Context, Credentials) (*sql.DB, error)

	Retries        int
	RetryDelay     time.Duration
	ConnectTimeout time.Duration
}

Options include database connection options.

func NewOptions

func NewOptions() *Options

NewOptions provides an initialized *Options object.

func (*Options) Bind

func (options *Options) Bind(fs *flag.FlagSet) *Options

Bind registers database flags on the given FlagSet with `db` prefix.

func (*Options) BindWithPrefix

func (options *Options) BindWithPrefix(fs *flag.FlagSet, prefix string) *Options

BindWithPrefix registers database flags on the given FlagSet with a custom prefix for multiple database connections.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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