Queries
Queries from JavaScript can be written in a SQL-Like syntax.
Simple Query
Queries can be constructed using the Query
class. Calling the toReadRequest
method returns a ReadRequest
, which can be passed to the authRequest.read
method to retrieve the result set.
src / pages / index.tsx
Fields
Select the fields to return by providing a string array to the Query
constructor.
Query
Select all fields by providing a *
.
Query
Filtering
Results can be filtered using the where
method on the Query class.
Query
Additional criteria can be provided using the and
and or
methods.
Query
Filter Operators
The following are valid filter operators. Contains applies to string fields only.
==
!=
>
<
>=
<=
Contains
Inner Join
Inner joins can be performed by using the join
method.
Query
The parameters for a join are -
- From table and field
- To table and field
- Alias
- Fields to include (Can be '*' for all fields)
Filter on Join Fields
Queries can be filtered on their joined tables by referencing their alias in the filters.
Query
Left Join
Left joins can be performed using the leftjoin
method.
Query
Top
The number of results returned can be limited by using the top
method. In the example below, the first 100 results are returned.
Query
Paging
Paging can be performed by using the page
method. The below example will return records 21 to 30.
Query
Order
The order of records can be set using the orderBy
method.
Query
Parameters for orderBy are -
- Name of field
- Order ("asc", "desc")
There can be multiple orders. In the example below, first the Widgets are ordered by Price, then by Name.
Query
Ordering can also be performed on joined tables.
Query
Denormalize
Denormalize is useful when joined tables need to return their data in arrays. Denormalization can be enabled by using the denormalize
method.
For example, a query without denormalization like the query below will return the following json.
Query
Response
When denormalization is enabled as seen in the query below, the following json is returned.
Query
Query
Notice the contacts are now grouped into an array named after the alias provided.