Item Query Reference Guide
Note: Operator and parameter reference. For patterns and end-to-end examples, see Advanced Query Guide.
This guide provides detailed information about all supported query parameters, wildcards, dynamic variables, and other options for querying items in BAASIX.
Table of Contents
- Query Parameters
- Filtering
- Sorting
- Pagination
- Field Selection
- Search
- Aggregation
- Grouping
- Wildcards
- Dynamic Variables
- Relational Queries
- Geospatial Queries
Query Parameters
| Parameter | Type | Description |
|---|---|---|
| fields | string | Comma-separated list of fields to return |
| sort | string | Field(s) to sort by (JSON string) |
| filter | string | Filter conditions (JSON string) |
| limit | integer | Number of items to return |
| page | integer | Page number for pagination |
| search | string | Search term for full-text search |
| searchFields | string | Comma-separated list of fields to search in |
| aggregate | string | Aggregation functions (JSON string) |
| groupBy | string | Fields to group by (comma-separated) |
| sortByRelevance | boolean | Sort by search relevance |
Filtering
The filter parameter supports complex conditions using a JSON object.
Operators
- Comparison:
eq,ne,gt,gte,lt,lte - Logical:
AND,OR - Array:
in,notIn,arraycontains,arraycontained - String:
like(auto-adds %),iLike(auto-adds %),startsWith,endsWith - Null:
isNull,isNotNull - Range:
between - Geospatial:
within,containsGEO,intersects,dwithin - Column Comparisons: Use
$COL(columnName)to compare against other fields
Column-to-Column Comparisons
Use $COL(columnName) to compare field values against other field values:
# Compare actual vs estimated cost
?filter={"actualCost":{"gt":"$COL(estimatedCost)"}}
# Compare with type casting
?filter={"startTime":{"gt":"$COL(endTime)","cast":"time"}}
# PostgreSQL casting syntax in column reference
?filter={"startTime":{"gt":"$COL(endTime::time)","cast":"time"}}Examples
-
Simple equality:
?filter={"status":{"eq":"active"}} -
Multiple conditions (AND):
?filter={"status":{"eq":"active"},"age":{"gt":30}} -
Logical OR:
?filter={"OR":[{"status":{"eq":"active"}},{"age":{"gt":30}}]} -
Nested AND/OR:
?filter={"AND":[{"OR":[{"status":{"eq":"active"}},{"status":{"eq":"pending"}}]},{"age":{"gt":30}}]} -
In array:
?filter={"status":{"in":["active","pending"]}} -
String matching (auto-adds % wildcards):
?filter={"name":{"like":"John"}} -
Null check:
?filter={"deletedAt":{"isNull":true}} -
Range:
?filter={"createdAt":{"between":["2023-01-01","2023-12-31"]}}
Sorting
The sort parameter accepts a JSON object specifying fields and directions.
Examples
-
Single field ascending:
?sort={"name":"asc"} -
Multiple fields:
?sort={"status":"asc","createdAt":"desc"} -
Sort by distance (for geospatial fields):
?sort={"_distance":{"target":[0,0],"column":"location","direction":"ASC"}}
Pagination
Use limit and page parameters for pagination.
Example:
?limit=20&page=2Field Selection
Use the fields parameter to specify which fields to return.
Examples
-
Select specific fields:
?fields=id,name,email -
Select all fields of a relation:
?fields=id,name,posts.* -
Select specific fields of a relation:
?fields=id,name,posts.id,posts.title -
Deep nesting:
?fields=id,name,posts.id,posts.title,posts.author.name
Search
Use search for full-text search and searchFields to specify which fields to search in.
Example:
?search=John&searchFields=name,emailAggregation
The aggregate parameter allows for complex calculations.
Supported Functions
countsumavgminmax
Examples
-
Single aggregation:
?aggregate={"totalUsers":{"function":"count","field":"id"}} -
Multiple aggregations:
?aggregate={"totalUsers":{"function":"count","field":"id"},"avgAge":{"function":"avg","field":"age"}}
Grouping
Use groupBy in combination with aggregate for grouped calculations.
Example:
?groupBy=status&aggregate={"userCount":{"function":"count","field":"id"}}Wildcards
Wildcards are supported in field selection and filtering.
Examples
-
Select all fields:
?fields=* -
Select all fields of a relation:
?fields=id,name,posts.* -
Select all nested fields:
?fields=id,name,posts.**
Dynamic Variables
Dynamic variables can be used in filters to reference properties of the authenticated user.
Available Variables
$CURRENT_USER- Current user ID$CURRENT_TENANT- Current tenant ID$USER_ROLE- Current user role$NOW- Current timestamp
Examples
-
Filter by current user:
?filter={"authorId":{"eq":"$CURRENT_USER"}} -
Filter by current tenant (multi-tenant mode):
?filter={"tenant_Id":{"eq":"$CURRENT_TENANT"}} -
Filter by current timestamp:
?filter={"publishedAt":{"lte":"$NOW"}}
Relational Queries
You can query related data using dot notation in filters and field selection.
Examples
-
Filter by related field:
?filter={"author.name":{"eq":"John Doe"}} -
Select fields from related entities:
?fields=id,title,author.name,author.email -
Filter with nested relations:
?filter={"posts.comments.author.id":{"eq":"$CURRENT_USER"}} -
Require related entities:
?filter={"comments":{"required":true}}
Geospatial Queries
For fields of type Point, LineString, Polygon, or Geography, you can use geospatial operators.
Operators
withincontainsGEOintersectsdwithin
Examples
-
Points within a polygon:
?filter={"location":{"within":{"type":"Polygon","coordinates":[[[0,0],[1,0],[1,1],[0,1],[0,0]]]}}} -
Polygon contains point:
?filter={"area":{"containsGEO":{"type":"Point","coordinates":[0,0]}}} -
Intersecting geometries:
?filter={"route":{"intersects":{"type":"LineString","coordinates":[[0,0],[1,1]]}}} -
Distance within:
?filter={"location":{"dwithin":{"geometry":{"type":"Point","coordinates":[0,0]},"distance":1000}}} -
Sort by distance:
?sort={"_distance":{"target":[0,0],"column":"location","direction":"ASC"}}
This reference guide covers all the querying capabilities of the BAASIX Item Routes, including advanced filtering, sorting, pagination, field selection, search, aggregation, grouping, wildcards, dynamic variables, relational queries, and geospatial queries. Use these options in combination to create powerful and flexible queries for your data.
Related Documentation
- Item Routes - API endpoints for data operations
- Schema Reference Guide - Data model definitions
- API Routes Reference - Complete list of all API endpoints