JCC Eloquent ORM
Query Builder
Introduction
The Builder class is the underlying query layer for all model queries and raw DB access. It wraps Knex with a Laravel-style fluent API.
Most methods are also available as static shortcuts on any model class.
Select and projection
Clearing query clauses
Useful when reusing a query builder instance:
Raw results (skip model hydration)
getRaw() and firstRaw() return plain objects even when a model is set:
Useful for lightweight projections, exports, or reporting where model overhead is unnecessary.
Clone
Duplicate the current query state so you can branch without mutating the original:
Existence helpers
Value helper
Get a single column value from the first matching row:
Aggregates
Aggregates also accept aliases via an object:
Where variants
LIKE helpers
JSON column paths
Grouped conditions
Array of conditions
Date helpers
Column comparison
Group By
Raw helpers
Joins with callbacks
Available join types: join, innerJoin, leftJoin, rightJoin, leftOuterJoin, rightOuterJoin, fullOuterJoin.
Subquery joins
Union
Increment / Decrement
JSON column updates
Cursor pagination
For large datasets where COUNT(*) is too slow, use cursor-based (keyset) pagination:
Response shape:
Pass the next page by forwarding ?cursor=<token> from meta.next_cursor.
Simple pagination
Offset pagination without a COUNT(*) query — faster for large tables:
Response:
Pluck
Get an array of values for a single column:
Transactions
Wrap multiple operations in a transaction — rolls back automatically on error:
The transaction context propagates to all Builder and Model calls within the callback via AsyncLocalStorage — no need to pass trx manually.
Summary
- Use
clone()to branch a query without mutation. - Use
getRaw()/firstRaw()when you don't need model instances. - Use
cursorPaginate()for stable, high-performance pagination on large tables. - Use
transaction(cb)for atomic multi-step writes. - Use JSON path helpers (
where("col.key", val),updateJson(...)) for JSON columns.