abcdatabase

package
v2.1.5+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2017 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNoMigrations occurs if no migration files can be found on disk
	ErrNoMigrations = errors.New("no migrations found")
)

Functions

func ExecuteScript

func ExecuteScript(cfg abcconfig.DBConfig, script []byte) error

ExecuteScript executes the passed in SQL script against the passed in db

func GetConnStr

func GetConnStr(cfg abcconfig.DBConfig) (string, error)

GetConnStr returns a connection string for the database software used

func IsMigrated

func IsMigrated(cfg abcconfig.DBConfig) (bool, int64, error)

IsMigrated returns true if the database is migrated to the latest migration in the db/migrations folder. It also returns the current database migration version number.

func RunMigrations

func RunMigrations(cfg abcconfig.DBConfig, migrationsPath string) (int, error)

RunMigrations executes the migrations "up" against the passed in database and returns the number of migrations run.

func SetupDBData

func SetupDBData(cfg abcconfig.DBConfig, testdata TestdataFunc) (int, error)

SetupDBData executes the migrations "up" against the passed in database and also inserts the test data defined in testdata.sql and executes the passed in TestdataFunc handler if present, and then returns the number of migrations run.

func SetupTestSuite

func SetupTestSuite(testdata TestdataFunc) (*sql.DB, int, error)

SetupTestSuite fully initializes a test database for you and returns a database connection to that test database and the number of migrations executed. It executes migrations testdata.sql and a TestdataFunc against your test database if present.

SetupTestSuite retrieves the test database configuration from the config.toml file located in the root of the app, and loads the "test" section of the config file. It also sets the environment prefix to the name of the app (in uppercase, i.e. "my app" -> "MY_APP").

SetupTestSuite will run the migrations located at approot/db/migrations and then execute the testdata.sql file located at approot/db/testdata.sql if it exists. If a TestdataFunc is provided to SetupTestSuite it will execute this handler after executing the testdata.sql file.

SetupTestSuite returns a connection to the test database, the number of migrations executed, and an error if present.

func SetupTestdata

func SetupTestdata(cfg abcconfig.DBConfig, testdataPath string, testdataFunc TestdataFunc) error

SetupTestdata executes the passed in sql file against the passed in database and then executes the testdata handler function.

SetupTestdata takes an db config, and an optional testdata.sql file path and optional testdata function handler.

If path or handler is nil they will be skipped. If both are nil an error will be thrown.

Types

type TestdataFunc

type TestdataFunc func(driver, conn string) error

TestdataFunc is the function signature for the sql testdata function that performs database operations once the test suite is initialized with migrations and the sql testdata file.

Jump to

Keyboard shortcuts

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