TQL
Torpedo Query Language (TQL)
TQL is a data store agnostic query language which is available out of the box to query any entity. Each time that an entity is created a /query
endpoint
is added to this one letting users fetch entities applying filters, pagination and more!.
For further information about entity endpoints please refer to Entity API endpoints
Disclaimer
String sensitive match or not will deppends on each storage engine.
TQL defines a JSON based query language with next capabilities:
- Querying
- Sorting
- Projection
- Pagination
Query format
The query object contains 3 sections: filter
, projection
and pagination
.
The query skeleton is described as a JSON object like:
Filter section
This section is used to apply a filter over the records that you would like to fetch. The filter is composed by two fields:
Type (type
) can be set as:
all
(and) all field query in the filter must match with the recordsany
(or) any field query in the filter must match with the records
And fields (fields
) a list of fields query to be applied, each field object in the query contains 3 keys:
field
: the field name to query in the conditionoperator
: the operator conditionvalue
: the value to be queryed
An example of that could be:
or for a list operator could be:Filter operators
The next table describes the available filter operators per field
Operator | Description | Type |
---|---|---|
== | Equal | int, float, string, bool |
!= | Not Equal | int, float, string, bool |
> | Greater than | int, float |
>= | Greater than or Equal | int, float |
< | Less than | int, float |
<= | Less than or Equal | int, float |
[n] | Between includes limits | int, float |
(n) | Between excludes limits | int, float |
[n) | Between includes left limit | int, float |
(n] | Between includes right limit | int, float |
[?] | In list | int, float, string |
.s. | Contains | string |
s.. | Prefix | string |
..s | Suffix | string |
Boundary Operators behaviour
The boundary operators follows the next behaviour
Projection section
The projection is a list of field names to return as part of the expected result. This is usefull when you don't need the full object fields. An example of this one could be:
Pagination section
This section helps developers to run paginated queries over your datastore. Two alternatives are available: cursor
and offset
.
Offset pagination
The offset pagination uses the well known storage offset
and limit
to run the query and let you sort the results by the specified fields.
The query should be configured with the number of items to get and the page number to retrieve.
Cursor pagination
The cursor pagination is useful to query page by page calling with the given nextToken
. Also a sorting by only one field is supported.
Entity ID
Due to the cursor pagination works querying records via the entity ID, this one must be lexicographically (timed) sortable
because
of this the UUID cannot be used for this kind of pagination, instead use the provided ULID