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
- Relational Conditions (relConditions)
- 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. BAASIX supports powerful wildcard patterns for field selection.
Basic Field Selection
Select specific fields by name:
?fields=id,name,emailWildcard Patterns
| Pattern | Description | Example |
|---|---|---|
* | All direct fields of the collection | ?fields=* |
relation.* | All fields of a related entity (one level) | ?fields=id,author.* |
relation.*.* | All fields of a related entity and ALL its nested relations (recursive) | ?fields=id,posts.*.* |
*.* | All direct fields + all fields of all direct relations | ?fields=*.* |
*.*.* | All fields at all levels (full tree expansion) | ?fields=*.*.* |
Examples
-
Select all direct fields:
?fields=*Returns:
id,name,email,createdAt, etc. (all columns of the collection) -
Select specific fields:
?fields=id,name,emailReturns only the specified fields
-
Select all fields of a relation (one level):
?fields=id,name,author.*Returns:
id,name, and all fields of theauthorrelation (author.id,author.name,author.email, etc.) -
Select specific fields of a relation:
?fields=id,name,author.id,author.nameReturns only the specified fields from the main collection and the relation
-
Deep nesting with specific fields:
?fields=id,title,author.name,author.role.nameReturns:
id,title,author.name, andauthor.role.name -
Select all nested fields recursively:
?fields=id,name,posts.*.*Returns:
id,name, and ALL fields frompostsincluding all its nested relations (e.g.,posts.id,posts.title,posts.comments.id,posts.comments.author.name, etc.) -
Select all direct fields plus all relation fields (one level):
?fields=*.*Returns: All direct fields + all fields from all direct relations
-
Full tree expansion:
?fields=*.*.*Returns: Everything - all fields at all nesting levels
Field Exclusion
You can exclude specific fields using the - prefix:
?fields=*,-password,-secretKeyReturns all fields except password and secretKey.
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
See Field Selection for comprehensive wildcard pattern documentation.
Quick Reference:
| Pattern | Matches |
|---|---|
* | All direct fields |
relation.* | All fields of one relation |
relation.*.* | All fields of relation + all nested relations |
*.* | All fields + all direct relations |
*.*.* | Complete tree (all levels) |
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}}
Relational Conditions (relConditions)
The relConditions parameter is a deep filter for filtering within relations that return arrays. When you query records with O2M (One-to-Many) or M2M (Many-to-Many) relations, those relations return as arrays. While regular filter filters the main records, relConditions filters what appears inside those arrays.
When to Use
| Relation Type | Returns | Use relConditions? |
|---|---|---|
| BelongsTo (N:1) | Single object | No - use filter |
| HasOne (1:1) | Single object | No - use filter |
| HasMany (O2M) | Array | ✅ Yes |
| BelongsToMany (M2M) | Array | ✅ Yes |
Basic Syntax
?relConditions={"relationName":{"fieldName":{"operator":"value"}}}Note: The parameter is always relConditions (plural).
How It Works
filter: Filters the main records (e.g., which posts to return)relConditions: Filters within the relation arrays (e.g., which comments appear in each post'scommentsarray)
Examples
-
Filter comments array within posts:
?fields=*,comments.* &relConditions={"comments":{"isApproved":{"eq":true}}}Returns all posts, but each post's
commentsarray only contains approved comments. -
Filter tags array within posts (M2M):
?fields=*,tags.* &relConditions={"tags":{"status":{"eq":"active"}}}Returns all posts, but each post's
tagsarray only contains active tags. -
Multiple conditions on array items:
?fields=*,orders.* &relConditions={"orders":{"status":{"eq":"completed"},"total":{"gte":100}}}Returns all users, but each user's
ordersarray only contains completed orders over $100. -
Nested relConditions (array within array):
?fields=*,posts.*,posts.comments.* &relConditions={"posts":{"status":{"eq":"published"},"comments":{"isApproved":{"eq":true}}}}Returns users, with each user's
postsarray containing only published posts, and each post'scommentsarray containing only approved comments. -
Using dynamic variables:
?fields=*,tasks.* &relConditions={"tasks":{"assignedTo":{"eq":"$CURRENT_USER"}}}Returns all projects, but each project's
tasksarray only contains tasks assigned to the current user. -
Logical operators:
?fields=*,comments.* &relConditions={"comments":{"OR":[{"authorId":{"eq":"$CURRENT_USER"}},{"isPublic":{"eq":true}}]}}Each post's
commentsarray contains only comments that are either by the current user OR public.
filter vs relConditions
GET /items/posts?fields=*,comments.*
&filter={"status":{"eq":"published"}}
&relConditions={"comments":{"isApproved":{"eq":true}}}filter={"status":{"eq":"published"}}→ Only return published postsrelConditions={"comments":{"isApproved":true}}→ Within each post, only include approved comments in the array
Key Points
- Regular filter can also be applied to array relations for filtering main records (e.g., "get posts that have at least one approved comment")
- relConditions filters what items appear in the array that's returned with each record
- Only applies to relations that return arrays (O2M and M2M)
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