{"modulePath":"github.com/a10y/cockroach","version":"v0.0.0-20160920194302-ad86efcaa21b","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package sqlutils\n\n## Functions\n\n```go\nfunc CreateTable(\n\tt *testing.T, sqlDB *gosql.DB, tableName, schema string, numRows int, fn GenRowFn,\n)\n```\nCreateTable creates a table in the \"test\" database with the given number of rows and using the given row generation function.\n\n```go\nfunc IntToEnglish(val int) string\n```\nIntToEnglish returns an English (pilot style) string for the given integer, for example:\n\n\tIntToEnglish(135) = \"one-three-five\"\n\n```go\nfunc PGUrl(t testing.TB, servingAddr, user, prefix string) (url.URL, func())\n```\nPGUrl 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.\n\nIn 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.\n\nArgs:\n\n\tprefix: A prefix to be prepended to the temp file names generated, for debugging.\n\n```go\nfunc RowEnglishFn(row int) parser.Datum\n```\nRowEnglishFn is a GenValueFn which returns an English representation of the row number, as a DString\n\n```go\nfunc RowIdxFn(row int) parser.Datum\n```\nRowIdxFn is a GenValueFn that returns the row number as a DInt\n\n## Types\n\n```go\ntype GenRowFn func(row int) []parser.Datum\n```\nGenRowFn 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.\n\n```go\nfunc ToRowFn(fn ...GenValueFn) GenRowFn\n```\nToRowFn creates a GenRowFn that returns rows of values generated by the given GenValueFns (one per column).\n\n```go\ntype GenValueFn func(row int) parser.Datum\n```\nGenValueFn 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.\n\n```go\nfunc RowModuloFn(modulo int) GenValueFn\n```\nRowModuloFn creates a GenValueFn that returns the row number modulo a given value as a DInt\n\n```go\ntype SQLRunner struct {\n\ttesting.TB\n\tDB *gosql.DB\n}\n```\nSQLRunner wraps a testing.TB and \\*gosql.DB connection and provides convenience functions to run SQL statements and fail the test on any errors.\n\n```go\nfunc MakeSQLRunner(tb testing.TB, db *gosql.DB) *SQLRunner\n```\nMakeSQLRunner returns a SQLRunner for the given database connection.\n\n```go\nfunc (sr *SQLRunner) Exec(query string, args ...interface{}) gosql.Result\n```\nExec is a wrapper around gosql.Exec that kills the test on error.\n\n```go\nfunc (sr *SQLRunner) ExecRowsAffected(expRowsAffected int, query string, args ...interface{})\n```\nExecRowsAffected executes the statement and verifies that RowsAffected() matches the expected value. It kills the test on errors.\n\n```go\nfunc (sr *SQLRunner) Query(query string, args ...interface{}) *gosql.Rows\n```\nQuery is a wrapper around gosql.Query that kills the test on error.\n\n","path":"github.com/a10y/cockroach/testutils/sqlutils","name":"sqlutils","synopsis":"","isRedistributable":true}
