Queries
Deta Base supports queries for fetching data that match certain conditions. Queries are regular objects/dicts/maps with conventions for different operators for specifying the conditions.
#
OperatorsQueries support the following operators:
#
Equal#
Not Equal#
Less Than#
Greater Than#
Less Than or Equal#
Greater Than or Equal#
Prefix#
Range#
Contains#
Not Containsnote
?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#
ANDThe 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:
#
ORMultiple 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:
#
HierarchyYou 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 KeysYou 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:
#
IssuesIf you run into any issues, consider reporting them in our Github Discussions.