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.
UpdateSet<T> describes the payload passed to updateOne and updateMany. Each key is a ValidPath<T> — a dot-notation string pointing to a column or a nested property inside a JSON column — and the corresponding value is the new value to write at that path. The library translates these keys into dialect-specific SQL at runtime: regular column updates become standard SET col = value clauses, while dot-notation paths targeting JSON columns are converted into jsonb_set, JSON_SET, or json_set calls depending on the database in use.
Type definition
ValidPath<T> is the same recursive union used by FilterQuery and SearchQuery, so every path you can filter on you can also update. ValueAt<T, K> resolves to the exact TypeScript type at that path, giving you compile-time safety over the value you assign.
Key categories
Regular column updates
Keys that map directly to a top-level column name produce a standardSET column = value SQL assignment.
JSON column partial updates
Keys that contain a dot and resolve inside a JSON-typed column trigger a partial JSON mutation. The library merges the incoming value into the existing document rather than replacing the entire column, so untouched sibling keys are preserved.PostgreSQL — jsonb_set with COALESCE
PostgreSQL — jsonb_set with COALESCE
PostgreSQL uses nested
jsonb_set() calls combined with COALESCE to handle NULL columns gracefully.MySQL — JSON_SET
MySQL — JSON_SET
MySQL uses
JSON_SET() with CAST(value AS JSON) to preserve object data types.SQLite — json_set
SQLite — json_set
SQLite uses
json_set() with json(value).JSON array index updates
Numeric segments in the path are treated as zero-based array indices. The same dialect-specific JSON mutation functions handle array slots the same way they handle object properties.Full example
The following call updates both a regular column and two nested JSON properties in a single round-trip:name becomes a direct column set, while settings.theme and occupational.company each become separate JSON mutation expressions targeting the settings and occupational columns respectively.
Batch updates with updateMany
updateMany accepts a FilterQuery<T> as the first argument and an UpdateSet<T> as the second. The library builds an EXISTS subquery from the filter and applies the mutation to all matching rows atomically within a transaction.
RETURNING-based transaction. On MySQL, the library creates a temporary table to snapshot the target IDs before executing the update, avoiding race conditions. See the multi-dialect page for the full transaction strategies.
RBAC: allowedSets
When RBAC is active, theallowedSets policy controls which keys in the UpdateSet are permitted for a given profile. Any key not listed is silently stripped from the payload before the query reaches the AST compiler.
user profile active, an attempt to update name or occupational.company alongside the allowed paths results in those keys being stripped silently:
If stripping removes every key and the resulting
UpdateSet is empty, the RBAC middleware throws an AccessDeniedError rather than executing a no-op update.Path security
All dot-notation paths in anUpdateSet are validated by validateJsonPath() before being passed to the dialect-specific JSON functions. This check restricts path strings strictly to alphanumerics, dots, and array indices, preventing SQL injection and prototype pollution from user-supplied keys.