database

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: Apache-2.0 Imports: 12 Imported by: 5 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const SqlDbVersionTableAlter1 = "ALTER TABLE db_version ADD COLUMN code_version_string TEXT"
View Source
const SqlDbVersionTableCreate = "" /* 211-byte string literal not displayed */

tables

Variables

Functions

func AssertIndex added in v1.10.0

func AssertIndex(t *testing.T, tableName string, wantIndexName string, wantDefinition string, indexes IndexSearchResult)

AssertIndex validates that the index exists

func AssertTableColumnsEqual added in v1.10.0

func AssertTableColumnsEqual(t *testing.T, want *TableColumn, actual *TableColumn)

AssertTableColumnsEqual is well-named

func CheckDatabaseExistsWithNewConnection added in v1.10.0

func CheckDatabaseExistsWithNewConnection(dbname string) bool

CheckDatabaseExistsWithNewConnection is well-named

func CheckTableExists added in v1.10.0

func CheckTableExists(db *sql.DB, tableName string) bool

CheckTableExists is well-named

func ConnectInitializedDatabase

func ConnectInitializedDatabase(postgresDbConfig *postgresdb.Config, upgradeScripts []*UpgradeScript, codeVersionString string) (*sql.DB, error)

ConnectInitializedDatabase creates a database with the required metadata tables

func GetNumTablesInDb added in v1.10.0

func GetNumTablesInDb(db *sql.DB) int

GetNumTablesInDb is well-named

func PostTestWithDbClose added in v1.10.0

func PostTestWithDbClose(db *sql.DB, dbname string)

PostTestWithDbClose logic for tests related to db upgrades

func PreTest added in v1.10.0

func PreTest(t *testing.T) (*sql.DB, string)

PreTest logic for tests related to db upgrades

func QueryAllRows added in v1.10.0

func QueryAllRows(db *sql.DB, tableName string) [][]interface{}

QueryAllRows queries all the rows of a given table in a database

func QueryDbVersion

func QueryDbVersion(db *sql.DB) (uint32, error)
query helper functions

QueryDbVersion queries for the version of the database

func RunUpgradeScripts added in v1.10.0

func RunUpgradeScripts(db *sql.DB, scripts []*UpgradeScript, codeVersionString string) error

RunUpgradeScripts is a utility function that can be run from outside this package so we need to export it

func ValidateDBVersionRow added in v1.10.0

func ValidateDBVersionRow(
	t *testing.T,
	actualRow []interface{},
	wantVersion int,
	wantDateCompletedUTC time.Time,
	wantNumScripts int,
	wantTimeElapsedMillis int,
	wantCodeVersionString *string,
)

ValidateDBVersionRow is well-named

Types

type IndexSearchResult added in v1.10.0

type IndexSearchResult map[string]string

IndexSearchResult captures the result from GetTableIndexes() and is used as input to AssertIndex()

func GetTableIndexes added in v1.10.0

func GetTableIndexes(db *sql.DB, tableName string) IndexSearchResult

GetTableIndexes is well-named

type TableColumn added in v1.10.0

type TableColumn struct {
	ColumnName             string      // `db:"column_name"`
	OrdinalPosition        int         // `db:"ordinal_position"`
	ColumnDefault          interface{} // `db:"column_default"`
	IsNullable             string      // `db:"is_nullable"`        // uses "YES" / "NO" instead of a boolean
	DataType               string      // `db:"data_type"`
	CharacterMaximumLength interface{} // `db:"character_maximum_length"`
}

TableColumn is a column in a table specefied generically

func GetTableSchema added in v1.10.0

func GetTableSchema(db *sql.DB, tableName string) []TableColumn

GetTableSchema is well-named

type UpgradeScript

type UpgradeScript struct {
	// contains filtered or unexported fields
}

UpgradeScript encapsulates a script to be run to upgrade the database from one version to the next

func MakeUpgradeScript

func MakeUpgradeScript(version uint32, command string, moreCommands ...string) *UpgradeScript

MakeUpgradeScript encapsulates a script to be run to upgrade the database from one version to the next

Jump to

Keyboard shortcuts

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