db

package
v0.3.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunMigrations

func RunMigrations(config Config, embeddedMigrations fs.FS, resourcePath string) error

func RunRollback

func RunRollback(config Config, embeddedMigrations fs.FS, resourcePath string) error

Types

type Client

type Client struct {
	*sqlx.DB
	// contains filtered or unexported fields
}

func New

func New(cfg Config) (*Client, error)

NewClient creates a new sqlx database client

func (*Client) Close

func (c *Client) Close() error

Close closes the database connection

func (*Client) ConnectionURL added in v0.3.2

func (c *Client) ConnectionURL() string

ConnectionURL fetch the database connection url

func (Client) WithTimeout

func (c Client) WithTimeout(ctx context.Context, op func(ctx context.Context) error) (err error)

func (Client) WithTxn

func (c Client) WithTxn(ctx context.Context, txnOptions sql.TxOptions, txFunc func(*sqlx.Tx) error) (err error)

type Config

type Config struct {
	Driver          string        `yaml:"driver" mapstructure:"driver"`
	URL             string        `yaml:"url" mapstructure:"url"`
	MaxIdleConns    int           `yaml:"max_idle_conns" mapstructure:"max_idle_conns" default:"10"`
	MaxOpenConns    int           `yaml:"max_open_conns" mapstructure:"max_open_conns" default:"10"`
	ConnMaxLifeTime time.Duration `yaml:"conn_max_life_time" mapstructure:"conn_max_life_time" default:"10ms"`
	MaxQueryTimeout time.Duration `yaml:"max_query_timeout" mapstructure:"max_query_timeout" default:"100ms"`
}

Jump to

Keyboard shortcuts

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