Queries
Deta Base comes with its own query language for fetching data that match certain conditions. Queries are regular objects/dicts/maps with conventions for different operators for specifying the conditions. You can use queries in Base UI,the Base SDK, or the Base HTTP API.
Base Queries come with a number of operators for querying data, and logical operators AND and OR.
Operators
Queries support the following operators:
Equal
Not Equal
Less Than
Greater Than
Less Than or Equal
Greater Than or Equal
Prefix
Range
Contains
Not Contains
?contains
and?not_contains
only works for a list of strings if checking for membership in a list; it does not apply to list of other data types. You can store your lists always as a list of strings if you want to check for membership.
Logical Operators
AND
The entries in a single query object are AND
ed together. For e.g. the query:
will retrieve items where active
is true
and age
is greater than or equal to 22
.
The query above would translate to SQL
as:
OR
Multiple query objects in a list are OR
ed together. For eg. the queries:
will retrieve items where age
is less than equal to 30
or age
is greater than equal to 40
.
The query above would translate to SQL
as:
Hierarchy
You can use the period character .
to query for hierarchical fields within the data. For instance if you have the following item in the base:
Then you can query for the active
and age
within profile
directly:
Querying Keys
You need to consider the following when querying on keys:
- The keys must be strings hence the operation values must also be strings.
- The contains and not-contains operators are not supported.
- The
AND
andOR
operations for different query values are not supported.
For e.g. the following queries are invalid: