sqlutils

package
v0.0.0-...-6e4a9c2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2016 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTable

func CreateTable(t *testing.T, sqlDB *gosql.DB, tableName, schema string, numRows int, fn GenRowFn)

CreateTable creates a table in the "test" database with the given number of rows and using the given row generation function.

func IntToEnglish

func IntToEnglish(val int) string

IntToEnglish returns an English (pilot style) string for the given integer, for example:

IntToEnglish(135) = "one-three-five"

func PGUrl

func PGUrl(t testing.TB, servingAddr, prefix string, user *url.Userinfo) (url.URL, func())

PGUrl returns a postgres connection url which connects to this server with the given user, and a cleanup function which must be called after all connections created using the connection url have been closed.

In order to connect securely using postgres, this method will create temporary on-disk copies of certain embedded security certificates. The certificates will be created in a new temporary directory. The returned cleanup function will delete this temporary directory. Note that two calls to this function for the same `user` will generate different copies of the certificates, so the cleanup function must always be called.

Args:

prefix: A prefix to be prepended to the temp file names generated, for debugging.

func QueryTableID

func QueryTableID(t *testing.T, sqlDB *gosql.DB, dbName, tableName string) uint32

QueryTableID returns the table ID of the specified database.table using the system.namespace table.

func RowEnglishFn

func RowEnglishFn(row int) parser.Datum

RowEnglishFn is a GenValueFn which returns an English representation of the row number, as a DString

func RowIdxFn

func RowIdxFn(row int) parser.Datum

RowIdxFn is a GenValueFn that returns the row number as a DInt

Types

type GenRowFn

type GenRowFn func(row int) []parser.Datum

GenRowFn is a function that takes a (1-based) row index and returns a row of Datums that will be converted to strings to form part of an INSERT statement.

func ToRowFn

func ToRowFn(fn ...GenValueFn) GenRowFn

ToRowFn creates a GenRowFn that returns rows of values generated by the given GenValueFns (one per column).

type GenValueFn

type GenValueFn func(row int) parser.Datum

GenValueFn is a function that takes a (1-based) row index and returns a Datum which will be converted to a string to form part of an INSERT statement.

func RowModuloFn

func RowModuloFn(modulo int) GenValueFn

RowModuloFn creates a GenValueFn that returns the row number modulo a given value as a DInt

type Row

type Row struct {
	testing.TB
	// contains filtered or unexported fields
}

Row is a wrapper around gosql.Row that kills the test on error.

func (*Row) Scan

func (r *Row) Scan(dest ...interface{})

Scan is a wrapper around (*gosql.Row).Scan that kills the test on error.

type SQLRunner

type SQLRunner struct {
	testing.TB
	DB *gosql.DB
}

SQLRunner wraps a testing.TB and *gosql.DB connection and provides convenience functions to run SQL statements and fail the test on any errors.

func MakeSQLRunner

func MakeSQLRunner(tb testing.TB, db *gosql.DB) *SQLRunner

MakeSQLRunner returns a SQLRunner for the given database connection.

func (*SQLRunner) CheckQueryResults

func (sr *SQLRunner) CheckQueryResults(query string, expected [][]string)

CheckQueryResults checks that the rows returned by a query match the expected response.

func (*SQLRunner) Exec

func (sr *SQLRunner) Exec(query string, args ...interface{}) gosql.Result

Exec is a wrapper around gosql.Exec that kills the test on error.

func (*SQLRunner) ExecRowsAffected

func (sr *SQLRunner) ExecRowsAffected(expRowsAffected int, query string, args ...interface{})

ExecRowsAffected executes the statement and verifies that RowsAffected() matches the expected value. It kills the test on errors.

func (*SQLRunner) Query

func (sr *SQLRunner) Query(query string, args ...interface{}) *gosql.Rows

Query is a wrapper around gosql.Query that kills the test on error.

func (*SQLRunner) QueryRow

func (sr *SQLRunner) QueryRow(query string, args ...interface{}) *Row

QueryRow is a wrapper around gosql.QueryRow that kills the test on error.

Jump to

Keyboard shortcuts

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