dbutil

package
v0.0.0-...-fd3f659 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2019 License: MIT Imports: 5 Imported by: 0

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

type PostgresConfig struct {
	Host            string `json:"host,omitempty"`
	Port            string `json:"port,omitempty"`
	User            string `json:"user,omitempty"`
	Password        string `json:"password,omitempty"`
	Database        string `json:"database,omitempty"`
	SSLMode         string `json:"sslMode,omitempty"`
	BinaryParamters string `json:"binaryParamters,omitempty"`
}

PostgresConfig configuration info for a MySQL databse.

func (PostgresConfig) DSN

func (cfg PostgresConfig) DSN() string

DSN gets the datasource name.

func (PostgresConfig) Driver

func (cfg PostgresConfig) 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.

Jump to

Keyboard shortcuts

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