Documentation Index
Fetch the complete documentation index at: https://mintlify.com/fajarnugraha37/drizzle-castor/llms.txt
Use this file to discover all available pages before exploring further.
SearchQuery<T> is the unified input type for all read operations in drizzle-castor. It collects every dimension of a query — which fields to return, how to filter rows, how to sort them, and how to paginate — into a single typed object. You pass it to searchOne, searchMany, or searchPage and the library’s AST compiler handles the rest: building joins, injecting JSON extraction functions, and running the CTE split-query strategy for accurate pagination.
Type definition
projection returns the full entity. Omitting filter removes the WHERE clause. Omitting order returns rows in database-natural order. page and pageSize are meaningful only when calling searchPage.
Fields
An array of
ValidPath<T> strings selecting which fields to include in the result. Paths may reference direct columns, dot-notation JSON sub-paths, and relational traversals. Omit this field to return the full entity type.When a relational path is included (for example "posts.title"), the compiler automatically fetches the related table’s primary key as well — this is required for the hydration step that collapses flat SQL rows into nested JavaScript objects.A
FilterQuery<T> object describing WHERE conditions. Supports comparison, string, null, range, collection, array-containment, and logical operators. See the FilterQuery reference for the full operator list.An
OrderQuery<T> object controlling the ORDER BY clause. Keys are ValidPath<T> strings; values are OrderFieldConfig (see below). Multiple keys are applied in the order they appear in the object.1-indexed page number. Only meaningful when calling
searchPage. The first page is 1.Number of records per page. Only meaningful when calling
searchPage.OrderFieldConfig
Each value in anorder object is an OrderFieldConfig:
Simple shorthand
Simple shorthand
Pass Translates to:
"asc" or "desc" directly for a basic sort with no null-handling or aggregation.Null position control
Null position control
Use the object form with Translates to:
nulls: "first" or nulls: "last" to control where NULL values appear in the result set.Aggregate ordering
Aggregate ordering
Set Translates to:You can also pass an arbitrary SQL function name as a string for advanced use cases, as the
aggregate to apply an aggregation function before ordering. This is useful when grouping results by a related field and ordering by a derived value such as comment count.Supported values: "min", "max", "avg", "sum", "count".AggregateFunction type includes string & {} to allow this.Usage examples
Fetch a single record with deep relations
Fetch a list without pagination
Paginated search with searchPage
searchPage response shape
searchPage wraps the results in a meta envelope:
Array of hydrated entity objects shaped by the
projection field (or the full entity type if projection is omitted).Pagination metadata.
Pagination internals
To avoid Cartesian fan-out when joining one-to-many relationships,searchPage uses a CTE split-query strategy:
- CTE query — fetches exactly the requested page of base entity IDs using filters, grouping, and
LIMIT/OFFSET. - Main query —
INNER JOINs against the CTE result to hydrate the full relational graph for only those IDs.
pageSize: 10 returns exactly 10 top-level entities, regardless of how many related rows each entity has.
RBAC interaction
The RBAC engine trims theSearchQuery before it reaches the AST compiler:
allowedProjections— unauthorized paths are removed fromprojection.allowedFilters— unauthorized paths are removed fromfilter(recursively, including inside$and/$or/$not).allowedSorts— unauthorized paths are removed fromorder.
AccessDeniedError is thrown.