dbutil

package
Version: v0.0.0-...-4734d62 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2021 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMigrationsFailed = errors.New("database migrations failed")
	ErrNotConnected     = errors.New("not connected to database")
)

Common errors

Functions

func Connect

func Connect(cfg Config) (*sql.DB, error)

Connect establishes and tests a new database connection.

func Connected

func Connected(db *sql.DB) error

Connected checks that the client is connected to the database.

func Downgrade

func Downgrade(path, driver string, db *sql.DB) error

Downgrade runs downgrade database mirgrations.

func MustConnect

func MustConnect(cfg Config) *sql.DB

MustConnect establishes and tests a new database connection, and panics on errors.

func RecordQueryError

func RecordQueryError(name string)

RecordQuerySuccess records the execution of a named query as failed

func RecordQuerySuccess

func RecordQuerySuccess(name string)

RecordQuerySuccess records the execution of a named query as successfull

func Rollback

func Rollback(tx *sql.Tx)

Rollback rolls back a transaction and logs any errors that occured.

func Upgrade

func Upgrade(path, driver string, db *sql.DB) error

Upgrade runs upgrade database mirgrations.

Types

type Config

type Config interface {
	DSN() string
	Driver() string
}

Config interface for a database config.

type MysqlConfig

type MysqlConfig struct {
	Protocol         string `json:"protocol"`
	Host             string `json:"host"`
	Port             string `json:"port"`
	User             string `json:"username"`
	Password         string `json:"password"`
	Database         string `json:"database"`
	ConnectionParams string `json:"connectionParams"`
}

MysqlConfig configuration info for a MySQL databse.

func (MysqlConfig) DSN

func (cfg MysqlConfig) DSN() string

DSN gets the datasource name.

func (MysqlConfig) Driver

func (cfg MysqlConfig) Driver() string

Driver gets the SQLite driver name.

type QueryTimer

type QueryTimer struct {
	QueryName string
	// contains filtered or unexported fields
}

QueryTimer struct to keep track of a queries execution time.

func NewQueryTimer

func NewQueryTimer(name string) QueryTimer

func (QueryTimer) Stop

func (t QueryTimer) Stop()

type SqliteConfig

type SqliteConfig struct {
	DriverName string `json:"driverName"`
	Name       string `json:"name"`
}

SqliteConfig configuration info for a SQLite databse.

func (SqliteConfig) DSN

func (cfg SqliteConfig) DSN() string

DSN gets the datasource name.

func (SqliteConfig) Driver

func (cfg SqliteConfig) Driver() string

Driver gets the SQLite driver name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL