Using External Test Data.
WHERE
clause, or leave blank. The WHERE
clause allows you to use ORDER BY
, LIMIT
and OFFSET
to get
consistent ordering and pagination.
WHERE
clause of a standard SQL statement that is executed on the data source.
The columns of a data source can be queried as if they were columns of an SQL table.
For instance, if your data source has an “age” column of type INTEGER
, you can retrieve all rows where age is greater than twenty-five using the query age > 25
.
Each data source column type maps to an SQL column type:
Data source type | SQL type |
---|---|
BOOLEAN | BOOLEAN |
DECIMAL | FLOAT |
INTEGER | INTEGER |
STRING | VARCHAR |
DATE | DATE |
TIME (time zoned) | TIME WITH TIME ZONE |
TIME (not time zoned) | TIME |
DATETIME (time zoned) | TIMESTAMP WITH TIME ZONE |
DATETIME (not time zoned) | TIMESTAMP |
+
, -
, =
, <
, >
, AND
, OR
, EXISTS
, BETWEEN
, etc.).
first_name = '{{request.query.name}}'
.
When a request is sent to the mock API with a name
query parameter, the value of this parameter will be inserted into the WHERE
clause.
So a query string that contains name=alice
will result in a WHERE
clause of first_name = 'alice'
.
"first name" == 'bob'
).
Quoting a column name also enforces case sensitivity (i.e. the casing in the query must match the casing of the column name exactly).
Currently, only simple WHERE
clause expressions that are part of the ANSI standard SQL specification are supported including
ORDER BY
, LIMIT
and OFFSET
. Sub-queries are not officially supported.
An empty query will return the entirety of the data source.
Thus, the stub’s data matcher will always return a match, as long as the data source itself is not empty.
age > 25
, then the data available in the response template will be limited to all rows whose “age” column exceeds twenty-five.
This data can be referenced in the response template via the data.items
property.
This property is a list of all the rows returned by the data source query.
For example, to render a JSON array of the name of each returned row, the following response template could be used:
{{ data.items.0.name }}'
).
{{ data.items.0.[first name] }}'
.
Supplying an empty query will provide the entirety of the data source to the template model.