Documentation
¶
Overview ¶
Package testdb provides go db testing utilities
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrResultColumnNotFound = errors.New("result column not found")
)
Functions ¶
This section is empty.
Types ¶
type TestDB ¶
type TestDB interface {
// Open starts a new sqlite database, destroying any previous one with
// TestDB.Close first
Open() (err error)
// Close stops the existing sqlite connection and if the database is not
// ":memory:", removes the db file
Close()
// DBH returns the sql.DB instance opened during NewTestDBWith
DBH() *sql.DB
// SqliteDB returns the main database path from the "pragma_database_list"
// table
SqliteDB() (file string)
// Tables returns the list of non-sqlite tables from the "sqlite_schema"
// table
Tables() (names []string)
// HasTable returns true if the given table name is present in the
// "sqlite_schema" table
HasTable(name string) (present bool)
// TableSchema returns the SQL definition from the "sqlite_schema" table
// for the named table
TableSchema(name string) (schema string)
// Indexes returns the list of non-sqlite indexes from the "sqlite_schema"
// table
Indexes() (names []string)
// HasIndex returns true if the given table name is present in the
// "sqlite_schema" table
HasIndex(name string) (present bool)
// IndexSchema returns the SQL definition from the "sqlite_schema" table
// for the named index
IndexSchema(name string) (schema string)
// Select is a very simple wrapper around a sql.DB Query call, gathering
// all the results in a simple mapping of column names to interface{}
// values
Select(query string, argv ...interface{}) (results []map[string]interface{}, err error)
// SelectOne is a wrapper around Select and returning just the first result's
// specific column value
SelectOne(column, query string, argv ...interface{}) (value interface{}, err error)
// SelectList is a wrapper around Select and returning a list of just the
// specific column values
SelectList(column, query string, argv ...interface{}) (values []interface{}, err error)
}
TestDB is the interface for Sqlite3 based test databases. These databases are intended to be ephemeral and easily reset for the purposes of unit testing within other projects
func NewTestDB ¶
NewTestDB is a wrapper around a default call to NewTestDBWith (creating an in-memory db)
func NewTestDBWith ¶
NewTestDBWith opens the given database file and returns a new TestDB instance, if the file argument is empty, an in-memory database is used
Note that if the database file given is actually a file, the file will be deleted when the Close method is called
Click to show internal directories.
Click to hide internal directories.