db

package
v0.0.0-...-a3b5a27 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

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

Connect connects to a database and produces the handle for injection

func ConnectWithOptions

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

ConnectWithOptions connect 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{}

Types

type Credentials

type Credentials struct {
	DSN    string
	Driver string
}

Credentials contains DSN and Driver

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() *Options

Bind binds the options variable flags with `db` prefix for the default database connection

func (*Options) BindWithPrefix

func (options *Options) BindWithPrefix(prefix string) *Options

Bind binds the options variable flags with a custom prefix for multiple database connections

func (*Options) Init

func (options *Options) Init() *Options

Init sets default *Options values

Jump to

Keyboard shortcuts

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