database

package
v0.28.2 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MySQLUniqueViolation

func MySQLUniqueViolation(err error) bool

MySQLUniqueViolation returns true when the provided error matches the MySQL code for duplicate entries (violating a unique table constraint).

func New

func New(logger log.Logger, _type string) (*sql.DB, error)

func NewMySQLConnection added in v0.22.0

func NewMySQLConnection(logger log.Logger, conf MySQLConfig) (*sql.DB, error)

func SqliteUniqueViolation

func SqliteUniqueViolation(err error) bool

SqliteUniqueViolation returns true when the provided error matches the SQLite error for duplicate entries (violating a unique table constraint).

func TestMySQLConnection added in v0.22.0

func TestMySQLConnection(t *testing.T) *sql.DB

func UniqueViolation

func UniqueViolation(err error) bool

UniqueViolation returns true when the provided error matches a database error for duplicate entries (violating a unique table constraint).

Types

type MySQLConfig added in v0.22.0

type MySQLConfig struct {
	Address  string
	Username string
	Password string
	Database string
}

func CreateTestDatabase added in v0.22.0

func CreateTestDatabase(t *testing.T, config MySQLConfig) MySQLConfig

func TestDatabaseConfig added in v0.22.0

func TestDatabaseConfig() MySQLConfig

type TestSQLiteDB

type TestSQLiteDB struct {
	DB *sql.DB
	// contains filtered or unexported fields
}

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

Jump to

Keyboard shortcuts

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