database

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 14 Imported by: 1

Documentation

Overview

Package database contains utilities for interacting with databases.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotADirectory = errors.New("invalid migration directory")

ErrNotADirectory is returned if attempting to migrate without a valid directory.

Functions

func FromInterval

func FromInterval(interval pgtype.Interval) time.Duration

FromInterval converts a given pgtype.Interval instance into a time.Duration instance. It assumes the interval is set using microseconds, as that is how `ToInterval` will create them.

func FromTextArray

func FromTextArray(ta pgtype.TextArray) []string

FromTextArray converts an instance of pgtype.TextArray to a string array.

func Migrate

func Migrate(action func(*migrate.Migrate) error, source *MigrationSource, db *sql.DB) error

Migrate performs the migration action given a source driver.

func MigrateDown

func MigrateDown(s *MigrationSource, db *sql.DB) error

MigrateDown reverts all migrations from the migration source that have already been applied.

func MigrateUp

func MigrateUp(s *MigrationSource, db *sql.DB) error

MigrateUp applies all migrations from the migration source that haven't been applied yet.

func ToInterval

func ToInterval(dur time.Duration) pgtype.Interval

ToInterval converts a given time.Duration to a pgtype.Interval instance. Will panic if Set returns an error.

func ToTextArray

func ToTextArray(arr []string) pgtype.TextArray

ToTextArray converts a given string slice to a pgtype.TextArray instance. Will panic if Set returns an error.

func WithinTransaction

func WithinTransaction(ctx context.Context, db *sql.DB, cb func(ctx context.Context, tx *sql.Tx) error) error

WithinTransaction invokes 'cb' within an SQL transaction. If the callback returns an error, the transaction is rolled back.

Types

type MigrationSource

type MigrationSource struct {
	// contains filtered or unexported fields
}

The MigrationSource type is used as a source of migration info for performing migration actions against a database.

func NewBindataMigration

func NewBindataMigration(dbDriver func(db *sql.DB) (database.Driver, error), b *bindata.AssetSource) *MigrationSource

NewBindataMigration creates a migration from the provided bindata asset.

func NewDirectoryMigration

func NewDirectoryMigration(dbDriver func(db *sql.DB) (database.Driver, error), dir string) *MigrationSource

NewDirectoryMigration creates a migration from the provided directory path. The parameter must be a directory.

Directories

Path Synopsis
Package badger provides an instrumented wrapper around a badger database.
Package badger provides an instrumented wrapper around a badger database.
Package postgres is used to perform operations against postgres databases
Package postgres is used to perform operations against postgres databases
Package sqlite is used to perform operations against sqlite databases
Package sqlite is used to perform operations against sqlite databases

Jump to

Keyboard shortcuts

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