Documentation ¶
Index ¶
- Variables
- func GetDriver(db *sql.DB, config DatabaseConfig) (database.Driver, error)
- func MySQLUniqueViolation(err error) bool
- func MySqlDriver(db *sql.DB) (database.Driver, error)
- func New(ctx context.Context, logger log.Logger, config DatabaseConfig) (*sql.DB, error)
- func NewAndMigrate(config DatabaseConfig, logger log.Logger, ctx context.Context) (*sql.DB, func(), error)
- func RunMigrations(log logging.Logger, db *sql.DB, config DatabaseConfig) error
- func Sqlite3Driver(db *sql.DB) (database.Driver, error)
- func SqliteUniqueViolation(err error) bool
- func UniqueViolation(err error) bool
- type DatabaseConfig
- type MySqlConfig
- type SqlLiteConfig
- type TestMySQLDB
- type TestSQLiteDB
Constants ¶
This section is empty.
Variables ¶
var InMemorySqliteConfig = DatabaseConfig{ DatabaseName: "sqlite", SqlLite: &SqlLiteConfig{ Path: ":memory:", }, }
Functions ¶
func MySQLUniqueViolation ¶
MySQLUniqueViolation returns true when the provided error matches the MySQL code for duplicate entries (violating a unique table constraint).
func New ¶
New establishes a database connection according to the type and environmental variables for that specific database.
func NewAndMigrate ¶
func RunMigrations ¶
func SqliteUniqueViolation ¶
SqliteUniqueViolation returns true when the provided error matches the SQLite error for duplicate entries (violating a unique table constraint).
func UniqueViolation ¶
UniqueViolation returns true when the provided error matches a database error for duplicate entries (violating a unique table constraint).
Types ¶
type DatabaseConfig ¶
type DatabaseConfig struct { MySql *MySqlConfig SqlLite *SqlLiteConfig DatabaseName string }
type MySqlConfig ¶
type SqlLiteConfig ¶
type SqlLiteConfig struct {
Path string
}
type TestMySQLDB ¶
TestMySQLDB is a wrapper around sql.DB for MySQL connections designed for tests to provide a clean database for each testcase. Callers should cleanup with Close() when finished.
func CreateTestMySQLDB ¶
func CreateTestMySQLDB(t *testing.T) *TestMySQLDB
CreateTestMySQLDB returns a TestMySQLDB which can be used in tests as a clean mysql database. All migrations are ran on the db before.
Callers should call close on the returned *TestMySQLDB.
func (*TestMySQLDB) Close ¶
func (r *TestMySQLDB) Close() error
type TestSQLiteDB ¶
TestSQLiteDB is a wrapper around sql.DB for SQLite connections designed for tests to provide a clean database for each testcase. Callers should cleanup with Close() when finished.
func CreateTestSqliteDB ¶
func CreateTestSqliteDB(t *testing.T) *TestSQLiteDB
CreateTestSqliteDB returns a TestSQLiteDB which can be used in tests as a clean sqlite database. All migrations are ran on the db before.
Callers should call close on the returned *TestSQLiteDB.
func (*TestSQLiteDB) Close ¶
func (r *TestSQLiteDB) Close() error