Back to godoc.org

Package dbutil

v0.0.0-...-e9dd525
Latest Go to latest

The latest major version is .

Published: Jun 1, 2020 | License: MIT | Module: github.com/CzarSimon/httputil

Index

Variables

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

Common errors

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 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.

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 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.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier