Drizzle Castor expresses everyDocumentation 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.
WHERE, SELECT, and ORDER BY clause as a plain JavaScript object rather than a builder chain. You write a JSON payload, the AST translator pipeline converts it into dialect-aware Drizzle SQL, and the query executes without you authoring a single SQL string. This approach works identically across PostgreSQL, MySQL, and SQLite because the translator handles dialect differences internally.
How the filter syntax works
AFilterQuery<T> is an object whose keys are dot-notation paths into the entity type and whose values are operator objects. The path can target a direct column, a nested JSON property inside a JSON column, or a column on a related table.
FlattenPaths<TEntity> and validates every operator value against the column’s inferred type via FieldOperators<ValueAt<TEntity, K>>.
Comparison operators
$eq and $ne
$eq and $ne
Exact equality and inequality checks.
$gt, $gte, $lt, $lte
$gt, $gte, $lt, $lte
Orderable comparisons. Available on
string, number, and Date columns.String operators
Available on columns whose TypeScript type extendsstring.
$like and $notLike
$like and $notLike
Case-sensitive pattern matching using SQL
LIKE syntax. Use % for any sequence of characters.$ilike and $notIlike
$ilike and $notIlike
Case-insensitive pattern matching (PostgreSQL) or fallback on other dialects.
Null operators
Range operators
$between and $notBetween
$between and $notBetween
Inclusive range check. Available on
string, number, and Date columns.Set membership operators
$in and $notIn
$in and $notIn
Check whether a column value appears in (or not in) a provided list.
$inArray and $notInArray
$inArray and $notInArray
Database-level array membership operators (PostgreSQL array columns). Checks whether a scalar value appears in a database array column.
Array containment operators
Available on columns whose TypeScript type extendsReadonlyArray.
Logical operators
Logical operators accept nestedFilterQuery objects. They can be arbitrarily nested.
- $and
- $or
- $not
All conditions must be true. This is the default behaviour when multiple keys are at the same level.
Dot-notation paths
Castor uses a single dot-notation string to address columns at any depth. The AST translator inspects the path and determines whether it points to a direct column, a JSON sub-property, or a related table column.JSON column paths
If a column is typed as a JSON object, append dot-separated keys to reach nested properties. Use a numeric index to target a JSON array element.column #>> '{key}'. On MySQL they use ->>. On SQLite, json_extract(column, '$.key') is used.
Relational paths
If a column name resolves to a registered relation, Castor automatically emits the necessaryLEFT JOIN before applying the filter or projection.
posts.comments.content — generate two joins: one to posts and one to comments, each aliased uniquely (e.g., rel_posts, rel_posts_comments) to avoid ambiguous column names.
Projections
A projection array selects which fields to return. Each entry is a dot-notation path validated againstFlattenPaths<TEntity>. Omitting projection returns all columns on the base table.
admin user querying the example schema would receive:
Order query syntax
Theorder field of a SearchQuery accepts a map from dot-notation paths to an OrderFieldConfig. The config can be a direction shorthand or a full configuration object.
- Direction shorthand
- Full config object
- Aggregate ordering
The AST translator pipeline
Every query object passes through a multi-stage pipeline before reaching Drizzle ORM:RBAC trimming
The unified RBAC middleware intercepts the raw payload and silently removes fields the active profile is not permitted to filter, project, sort, or set. Prohibited actions throw
AccessDeniedError immediately.Path analysis
analyzeQuery traverses the filter, order, and projection trees and identifies every unique relational hop needed to satisfy the query (e.g., Set(["posts", "posts.comments"])).Alias management
buildAliases generates unique SQL table aliases for every hop (rel_posts, rel_posts_comments) to prevent ambiguous column names across joins.AST compilation
parseFilter recursively walks logical operators and leaf fields, mapping each operator to its Drizzle counterpart (eq(), like(), and(), etc.). buildSelection assembles the SELECT list; parseOrder builds the ORDER BY clause.Join injection
applyJoins emits LEFT JOIN statements for every alias in the map, wiring localKey to foreignKey. Soft-delete filters are injected into join conditions automatically.Complete query example
The following query demonstrates all features — logical operators, JSON paths, relational paths, projections, and order — taken from the quickstart:Related pages
Defining table relations
Learn how relation metadata is registered so that relational paths resolve correctly.
Filter query API
Full type reference for FilterQuery, FieldOperators, and all operator types.
Search query API
Full type reference for SearchQuery, OrderQuery, and projection inference.
Access control profiles
Understand how RBAC trims filter and projection fields per profile.