drizzle-orm
0.45.4ORM
- Maintenance
- Slow8 commits in 3 months · bus factor 2
- License
- Apache-2.0Permissive · OSI-approved
- Security
- 1 advisory1 high
- Supported versions
- No scheduleendoflife.date does not track this project
36.3k stars · 1.8k forks · 2.1k open issues · last release 1 month ago · data checked 3 hours ago
Release history
All releases on GitHubAtom feed/feed/drizzle-team/drizzle-orm
Badge
[](/p/drizzle-team/drizzle-orm)
ORM
- [BREAKING] Fixed
postgres-jstransparent parsers set bydrizzle()constructors breaking driver's own serializers fortimestamptz,timestamp,date,time,json,jsonbtypes (fixes #3171, #4426, #5789) paramsInErrors
:exclamation: Any existing workarounds with manual JSON.stringify(jsonValue) in raw sql or raw driver calls must be removed to prevent double stringification of JSON params; For array-type JSON params in sql use sql.param(jsonArrayValue) to avoid it being parsed as value list instead of param.
- [BREAKING] Restricted
undefinedvalue passed to fields in relational queries'where- now throws an error upon encounteringundefinedin filters, addedEmptyFiltersymbol (import { EmptyFilter } from 'drizzle-orm/relations') that can be used as an explicit replacement ofundefinedwhere possibly absent filter is desired by design rather than possible bug (fixes #5636)
Example:
db.query.users.findMany({ where: { isActive: params.isActive ?? EmptyFilter } })
- [BREAKING] Relation filters without conditions (
{}, or containing only empty conditions) are now skipped like any other empty filter instead of generatingexists (...)check of relation's presence - usetrueto filter by relation's presence,false- by its absence
Example:
// Previously: `where exists (select * from "posts" ...)`, now: no filter
db.query.users.findMany({ where: { posts: {} } })
// Users with at least one post
db.query.users.findMany({ where: { posts: true } })
- [BREAKING] Updated
postgrescodecs: now generic codecs contain only in-json codecs (mirroringmysql), contents of drivers' codecs remain unchanged - [BREAKING] Switched
pgbyteain-json codecs fromencode(..., 'base64')casts to decodingto_json's native hex output - [BREAKING] Made nested select join nullification consider
SQLfield data during nullification - [BREAKING] Fixed
sqliteignoring.$defaultFn(...)on insert when.default(...)is present - [BREAKING] Untied
bun-sql/mysql,mysql2,singlestorecolumn mapping from connection config, removed forcedbigintparams on their respective configs, replaced with more stablecastcodecs - [BREAKING] Reworked
cockroachcolumn builders to mirrorpg- now both have same.array('[][]...')syntax - [BREAKING] Moved
Viewexports fromdrizzle-orm/sql/sqltodrizzle-orm/view - [BREAKING]
getTableUniqueNameno longer prefixes aliased views or tables with theirschema - [BREAKING]
getTableUniqueNameno longer setspublic.prefix for entities withoutschema - [BREAKING] Updated
Viewclass: switched toTable-like object config for type template, typedschemaproperty - [BREAKING] Updated
withReplicas(indirectly fixes #4185): - Now every query goes to primary db by default
- To query replica, explicitly call
db.$replica - [BREAKING] Added
withCastCodecs = falseswitch togetSQL(),withCastCodecs = trueswitch totoSQL()of non-relational query builders - nowdb.select(...).from(...).getSQL()emits query without cast codecs by default - [BREAKING] Reworked
sqlite-proxy: - Added
rowMode: 'array' | 'object'switch for'all' | 'get'execute methods - Dropped
{ rows: Result[] }callback result wrapping - now expected direct return of expected data - Replaced
callback,batchCallbackwithSqliteProxyExecutorsobject - must providerun,all,gethandlers & optionalbatchhandler - Dropped
valuesexecute method due to it being duplicate of array-modeall - Added
TRunResulttype inferrence based on return type ofrunexecutor, updatedSqliteRemoteDatabasetemplate withTRunResultargument - Added per-item
rowMode: 'array' | 'object'tobatch,batchis expected to mirror executors' return types per query - [BREAKING] Fixed runtime-type expected result mismatch for
get(data | undefinedin runtime,data[]in types) (fixes #5461, #3394) - [BREAKING] Fixed
sqlitedb.get(sql)return type lacking| undefinedfor queries without returned rows - [BREAKING] Omitted query
paramsfromDrizzleQueryErrorby default, addedparamsInErrorsoption todrizzleconstructor to enable queryparamsinDrizzleQueryError(fixes #5939)
Example:
const db = drizzle({
connection: 'postgres://...',
paramsInErrors: true
})
- [BREAKING] For
mysql,postgres,cockroach,mssqlset RQBv2 to new query build strategy to fix slow query plans (fixes #5245)
Can be opted out of per query via strategy switch: db.query.findMany({ strategy: 'basic' })
When used, may break direct references to relations in raw SQL syntax where, orderBy:
// posts with the most comments first
db.query.posts.findMany({
with: { author: true, comments: true },
orderBy: (t, { sql }) => sql`json_array_length("comments"."r") desc, ${t.id}`, // "comments" becomes unreachable due to query nesting
limit: 2,
});
// posts of verified authors
db.query.posts.findMany({
with: { author: true },
where: { RAW: (t, { sql }) => sql`("author"."r"->>'verified')::boolean` }, // "author" becomes unreachable due to query nesting
});
- [BREAKING] Moved
StringChunk,commonStringChunksexports fromdrizzle-orm/sql/sqltodrizzle-orm/sql/common-chunks(still exported fromdrizzle-orm/sql) - [BREAKING] Switched RQBv2 build functions to chunk collection: each accepts optional trailing
collectTo: SQLChunk[]array to push chunks to and returns chunk arrays instead ofSQL
:exclamation: Chunk arrays embedded into sql directly are rendered as value lists - wrap them in new SQL(chunks) to use them as query parts
relationsFilterToSQL(...).sql:SQL | undefined->SQLChunk[] | undefined, addedcollectToparameter