Advanced Query Features
Pack:
drizzle-ormParent skill: Drizzle ORM Queries and SQL Source:drizzle-orm/drizzle-orm-queries-and-sql/references/advanced-query-features.md
Read this when
Section titled “Read this when”- using transactions or nested savepoints
- building reusable query-builder helpers
- enabling batch, cache, or read replicas
- working across stable and beta query APIs
Transactions
Section titled “Transactions”- Use
db.transaction(...)for all-or-nothing multi-step work. - Nested transactions create savepoints.
- The docs expose dialect-specific transaction config types for PostgreSQL, MySQL, SQLite, SingleStore, MSSQL, and CockroachDB.
Dynamic query building
Section titled “Dynamic query building”- Builder methods are single-use by default.
- Switch to
.$dynamic()before passing a query builder through helper functions that add clauses later.
Batch, cache, and replicas
Section titled “Batch, cache, and replicas”db.batch(...)is documented for LibSQL, Neon, and D1.- Drizzle cache is opt-in by default. Global caching is a separate explicit mode.
- Read replicas are a dedicated advanced surface; keep read/write ownership obvious when introducing them.
Version-sensitive relation/query note
Section titled “Version-sensitive relation/query note”- Stable docs still document
db.query.<table>. - The beta line adds RQB v2 /
db._queryanddefineRelations. - Treat those as coordinated query-and-schema upgrades rather than isolated syntax swaps.
Source map
Section titled “Source map”https://orm.drizzle.team/docs/rqbhttps://orm.drizzle.team/docs/rqb-v2https://orm.drizzle.team/docs/relations-v1-v2https://orm.drizzle.team/docs/transactionshttps://orm.drizzle.team/docs/batch-apihttps://orm.drizzle.team/docs/cachehttps://orm.drizzle.team/docs/read-replicashttps://orm.drizzle.team/docs/dynamic-query-buildinghttps://orm.drizzle.team/docs/set-operations