Documentation
¶
Overview ¶
Package sql provides database steps: services, seeds, selections (with polling and JSONB containment), JSON column assertions, row locks and trigger fault injection, before a row's insert, update or delete (PostgreSQL and Oracle).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DuplicateKeyHint ¶ added in v0.1.10
func DuplicateKeyHint() string
DuplicateKeyHint completes the error of a seed whose row has a key the database already holds: data stays after a scenario, so it is most often a row of an earlier run, or of another scenario's seed.
Types ¶
type Dataset ¶
type Dataset struct {
Tables []DatasetTable
}
Dataset is an ordered set of tables to insert (DbUnit/Database Rider compatible).
func LoadDataset ¶
LoadDataset reads a dataset file, choosing the format by extension.
type DatasetRow ¶
DatasetRow is an ordered column -> value mapping. A nil value is NULL.
type DatasetTable ¶
type DatasetTable struct {
Name string
Rows []DatasetRow
}
DatasetTable is one table's rows. Each row lists its own columns, so rows may omit columns (their database defaults apply).
type Dialect ¶
type Dialect struct {
Name string
Driver string
// ForUpdate is appended to SELECT to lock rows ("" when unsupported).
ForUpdate string
// ForUpdateHint is inserted after the table name (SQL Server style).
ForUpdateHint string
// Postgres enables JSONB steps and trigger simulation.
Postgres bool
// BackslashEscapes means backslashes in string literals are escapes (MySQL).
BackslashEscapes bool
// BitBooleans means there is no TRUE or FALSE to count on: booleans are 1 and
// 0 (SQL Server's bits; Oracle's numbers, and its BOOLEAN takes them too).
BitBooleans bool
// Oracle enables its session, catalogs, numbers and triggers.
Oracle bool
// TimeOffset means a time's literal has its offset: every column of that database
// takes one, and one that holds a moment needs it. A column with no time zone keeps
// the wall clock.
TimeOffset bool
}
Dialect captures the database-specific parts of the SQL pack.
func (Dialect) Literal ¶
Literal renders s as a SQL string literal, escaping quotes (and backslashes where they are escapes), so values containing quotes are safe.
func (Dialect) Time ¶ added in v0.2.14
Time renders a moment as a literal of its wall-clock time, with its offset where the dialect takes one. A seed's relative times are the database's clock (databaseNow).
func (Dialect) Value ¶ added in v0.3.0
Value renders a value of a step's table as a SQL value of its type (core.ParseValue, ADR 0014): a string is a string literal, an integer or a decimal a number, true and false booleans, and JSON (an object or an array) the string of its text. Null is the caller's: `IS NULL`.
type ScenarioContext ¶
type ScenarioContext struct {
// contains filtered or unexported fields
}
func Context ¶
func Context(sc *core.Scenario) *ScenarioContext
Context returns the sql pack's context for a scenario: the databases registered in it with their connections, selections, triggers and row locks. The pack's steps and other packs share it.
func (*ScenarioContext) AddService ¶
func (c *ScenarioContext) AddService(svc *Service) error
AddService registers a service under its Name. The first service registered is the default; registering a name twice is an error.
func (*ScenarioContext) Service ¶
func (c *ScenarioContext) Service(name ...string) (*Service, error)
Service returns the named service, or the first one registered (the default) when no name is given.
func (*ScenarioContext) Services ¶
func (c *ScenarioContext) Services() []*Service
Services returns the registered services in registration order.
type Selection ¶
type Selection struct {
Table string
Query string
Columns []string
Rows [][]any
// contains filtered or unexported fields
}
Selection is a materialized query result (like DbUnit's ITable).
type Service ¶
type Service struct {
Name string
URL string
User string
Password string
Schema string
Target Target
DB *dbsql.DB
// contains filtered or unexported fields
}
Service is a database registered in a scenario.
func Connect ¶
Connect opens (or reuses, for the whole run) a connection pool and returns an unregistered service; add it with AddService. url may be a JDBC URL (jdbc:postgresql://...) or a native one.
func (*Service) AddSelection ¶
AddSelection appends a selection, so the pack's selection steps see it as the next one.
func (*Service) Query ¶
Query runs a SELECT on the service's connection pool and returns the rows as a selection, without adding it.
func (*Service) Selections ¶
Selections returns the service's selections in the order they were retrieved.