Documentation ¶
Index ¶
- Variables
- func ExecuteScript(cfg abcconfig.DBConfig, script []byte) error
- func GetConnStr(cfg abcconfig.DBConfig) (string, error)
- func IsMigrated(cfg abcconfig.DBConfig) (bool, int64, error)
- func RunMigrations(cfg abcconfig.DBConfig, migrationsPath string) (int, error)
- func SetupDBData(cfg abcconfig.DBConfig, testdata TestdataFunc) (int, error)
- func SetupTestSuite(testdata TestdataFunc) (*sql.DB, int, error)
- func SetupTestdata(cfg abcconfig.DBConfig, testdataPath string, testdataFunc TestdataFunc) error
- type TestdataFunc
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoMigrations occurs if no migration files can be found on disk ErrNoMigrations = errors.New("no migrations found") )
Functions ¶
func ExecuteScript ¶
ExecuteScript executes the passed in SQL script against the passed in db
func GetConnStr ¶
GetConnStr returns a connection string for the database software used
func IsMigrated ¶
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 ¶
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 ¶
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.