Documentation
¶
Index ¶
- Variables
- func AcquireLock(ctx context.Context, tx *sqlx.Tx, driverName string, lockKey string) error
- func Connect(ctx context.Context) (*sqlx.DB, error)
- func ConnectWithOptions(ctx context.Context, options *Options) (*sqlx.DB, error)
- func ConnectWithRetry(ctx context.Context, options *Options) (db *sqlx.DB, err error)
- func ParseDSN(conn string) (string, string)
- type Credentials
- type Options
Constants ¶
This section is empty.
Variables ¶
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
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 ¶
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 ¶
ConnectWithOptions connects to host based on Options{}.
func ConnectWithRetry ¶
ConnectWithRetry uses retry options set in Options{}.
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.