Drizzle Castor is built to work identically across PostgreSQL, MySQL, and SQLite without any configuration changes. The library detects which database engine you are running at runtime through a duck-typing probe on the Drizzle instance, then automatically selects the correct SQL generation strategy for mutations, JSON operations, and transaction safety. This page explains how that detection works, how each dialect handles atomic mutations, and how JSON paths differ across engines.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.
Dialect detection
ThegetDialect() function in src/helper/dialect-helper.ts never reads a config string or environment variable. Instead it probes two behavioral characteristics of the Drizzle dialect object — the parameter placeholder style and the identifier quoting style — to determine which engine is in use:
The
supportsReturning(db) helper is a thin wrapper over getDialect() that returns true for PostgreSQL and SQLite and false for MySQL. All mutation executors call this before choosing a strategy.Mutation strategies
Different SQL engines expose different capabilities for returning the rows affected by anUPDATE or DELETE. Drizzle Castor bridges this gap with two strategies.
- PostgreSQL
- MySQL
- SQLite
Strategy A: RETURNING clause
PostgreSQL’sRETURNING clause lets an UPDATE or DELETE statement return the affected rows atomically within the same statement. Drizzle Castor uses this to avoid a second SELECT to identify which rows changed.pg (node-postgres) or postgres (postgres.js)JSON path handling
JSON columns require dialect-specific SQL operators for both reading (extraction) and writing (mutation). Drizzle Castor normalizes these differences so you always write the same dot-notation path in your queries.Extraction — reading nested values
When a projection or filter references a nested JSON path such as"settings.theme", the buildJsonExtractionSql function converts it to the correct dialect syntax:
- PostgreSQL
- MySQL
- SQLite
PostgreSQL uses the
#>> operator to extract a nested value as unquoted text. The dot-notation path settings.theme becomes a brace-delimited array literal:Mutation — updating nested values
When anupdateOne or updateMany set payload uses a dot-notation key such as "settings.theme": "light", the parseUpdateSet function generates the correct dialect-specific merge:
- PostgreSQL
- MySQL
- SQLite
PostgreSQL uses
jsonb_set() combined with COALESCE to merge the new value into the existing JSON object without overwriting sibling keys:Driver packages
Each dialect requires a specific database driver alongside Drizzle ORM. Drizzle Castor does not bundle any drivers.PostgreSQL
Install
pg or postgres. Pass the Drizzle instance created with drizzle-orm/node-postgres or drizzle-orm/postgres-js.MySQL
Install
mysql2. Pass the Drizzle instance created with drizzle-orm/mysql2.SQLite
Install
better-sqlite3. Pass the Drizzle instance created with drizzle-orm/better-sqlite3 or drizzle-orm/bun-sqlite.Related pages
Safe pagination with CTE split queries
See how the CTE split query strategy handles
LIMIT/OFFSET correctly across dialects.Type system and inference
Explore how TypeScript generics enforce type safety end-to-end regardless of which dialect you use.