database

package
v1.5.11 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Overview

Package database provides support for access the database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(ctx context.Context, cfg Config) (*sqlx.DB, error)

Open knows how to open a database connection based on the configuration. It also performs a health check to make sure the connection is healthy.

func StatusCheck

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

StatusCheck returns nil if it can successfully talk to the database. It returns a non-nil error otherwise.

func WithinTran

func WithinTran(l log.Logger, db *sqlx.DB, fn func(*sqlx.Tx) error) error

WithinTran runs passed function and do commit/rollback at the end.

Types

type Config

type Config struct {
	User           string
	Password       string
	Host           string
	Name           string
	ConnectTimeout int
	MaxIdleConns   int
	MaxOpenConns   int
	DisableTLS     bool
}

Config is the required properties to use the database.

func ConfigFromDSN

func ConfigFromDSN(dsn string) (Config, error)

ConfigFromDSN provides support for creating a config from a DSN.

Jump to

Keyboard shortcuts

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