Drizzle ORM version
0.29.0
will require a minimum Drizzle Kit version of0.20.0
, and vice versa. Therefore, when upgrading to a newer version of Drizzle ORM, you will also need to upgrade Drizzle Kit. This may result in some breaking changes throughout the versions, especially if you need to upgrade Drizzle Kit and your Drizzle ORM version is older than<0.28.0
New Features
🎉 MySQL unsigned
option for bigint
You can now specify bigint unsigned
type
Read more in docs
🎉 Improved query builder types
Starting from 0.29.0
by default, as all the query builders in Drizzle try to conform to SQL as much as possible, you can only invoke most of the methods once. For example, in a SELECT statement there might only be one WHERE clause, so you can only invoke .where() once:
This behavior is useful for conventional query building, i.e. when you create the whole query at once. However, it becomes a problem when you want to build a query dynamically, i.e. if you have a shared function that takes a query builder and enhances it. To solve this problem, Drizzle provides a special ‘dynamic’ mode for query builders, which removes the restriction of invoking methods only once. To enable it, you need to call .$dynamic() on a query builder.
Let’s see how it works by implementing a simple withPagination function that adds LIMIT and OFFSET clauses to a query based on the provided page number and an optional page size:
Note that the withPagination function is generic, which allows you to modify the result type of the query builder inside it, for example by adding a join:
Read more in docs
🎉 Possibility to specify name for primary keys and foreign keys
There is an issue when constraint names exceed the 64-character limit of the database. This causes the database engine to truncate the name, potentially leading to issues. Starting from 0.29.0
, you have the option to specify custom names for both primaryKey()
and foreignKey()
. We have also deprecated the old primaryKey()
syntax, which can still be used but will be removed in future releases
Read more in docs
🎉 Read Replicas Support
You can now use the Drizzle withReplica
function to specify different database connections for read replicas and the main instance for write operations. By default, withReplicas
will use a random read replica for read operations and the main instance for all other data modification operations. You can also specify custom logic for choosing which read replica connection to use. You have the freedom to make any weighted, custom decision for that. Here are some usage examples:
Implementation example of custom logic for selecting read replicas, where the first replica has a 70% chance of being chosen, and the second replica has a 30% chance of being chosen. Note that you can implement any type of random selection for read replicas
withReplicas
function is available for all dialects in Drizzle ORM
Read more in docs
🎉 Set operators support (UNION, UNION ALL, INTERSECT, INTERSECT ALL, EXCEPT, EXCEPT ALL)
Huge thanks to @Angelelz for the significant contribution he made, from API discussions to proper type checks and runtime logic, along with an extensive set of tests. This greatly assisted us in delivering this feature in this release
Usage examples:
All set operators can be used in a two ways: import approach
or builder approach
Read more in docs
🎉 New MySQL Proxy Driver
A new driver has been released, allowing you to create your own implementation for an HTTP driver using a MySQL database. You can find usage examples in the ./examples/mysql-proxy
folder
You need to implement two endpoints on your server that will be used for queries and migrations(Migrate endpoint is optional and only if you want to use drizzle migrations). Both the server and driver implementation are up to you, so you are not restricted in any way. You can add custom mappings, logging, and much more
You can find both server and driver implementation examples in the ./examples/mysql-proxy
folder
Read more in docs
🎉 New PostgreSQL Proxy Driver
Same as MySQL you can now implement your own http driver for PostgreSQL database. You can find usage examples in the ./examples/pg-proxy
folder
You need to implement two endpoints on your server that will be used for queries and migrations (Migrate endpoint is optional and only if you want to use drizzle migrations). Both the server and driver implementation are up to you, so you are not restricted in any way. You can add custom mappings, logging, and much more
You can find both server and driver implementation examples in the ./examples/pg-proxy
folder
Read more in docs
🎉 D1
Batch API support
Reference: https://developers.cloudflare.com/d1/platform/client-api/#dbbatch
Batch API usage example:
All possible builders that can be used inside db.batch
:
More usage examples here: integration-tests/tests/d1-batch.test.ts and in docs
Drizzle Kit 0.20.0
- New way to define drizzle.config using
defineConfig
function - Possibility to access Cloudflare D1 with Drizzle Studio using wrangler.toml file
- Drizzle Studio is migrating to https://local.drizzle.studio/
bigint unsigned
supportprimaryKeys
andforeignKeys
now can have custom names- Environment variables are now automatically fetched
- Some bug fixes and improvements
You can read more about drizzle-kit updates here