Querying Data
Querying Data
ObjectQL uses a JSON-based Protocol for all data operations. Unlike SQL (strings) or Query Builders (chained methods), ObjectQL queries are Data Structures.
This design makes it strictly typed, easy to serialise/transport over HTTP, and safe from injection—perfect for both human developers and AI Agents.
📖 Looking for query best practices and optimization strategies?
Check out the Query Best Practices Guide for a comprehensive guide on choosing the right approach (JSON-DSL, REST, GraphQL) and performance optimization techniques.
The find() Operation
The find method recovers a list of records matching specific criteria.
Filters
Filters are defined as a 2D array: [[ field, operator, value ]].
Implicit AND:
Explicit OR:
Use the _or special operator in complex filters (see advanced docs).
Sorting
field: Ascending.-field: Descending.
CRUD Operations
Create (Insert)
Update
Updates are always bulk operations targeted by filters. To update a single record, filter by ID.
Delete
Relationships (Joins & Expand)
ObjectQL handles relationships distinctively. Instead of SQL JOIN keywords, we use the expand property to hydrate related records. This ensures compatibility across SQL and NoSQL drivers (where joins might be separate queries).
1. The expand Syntax
To get related data, define the relationship in expand.
2. Nested Expansion
You can nest expansions arbitrarily deep.
3. Filtering on Related Records
There are two ways to filter based on relationships:
A. Filter the Root (Dot Notation) Find tasks where the project's status is active. (Note: Requires a driver that supports SQL Joins)
B. Filter the Expanded List Find projects, but only include completed tasks in the expansion.
Aggregation
ObjectQL supports SQL-like aggregation via the aggregate() method on the repository.
Supported Functions
countsumavgminmax
Why JSON?
- Transportable: The query IS the HTTP request body. No translation needed.
- Secure: Impossible to inject SQL syntax.
- Generatable: LLMs produce perfect JSON structures naturally.