Releases: drizzle-team/drizzle-orm
0.44.2
0.44.1
0.44.0
Error handling
Starting from this version, we’ve introduced a new DrizzleQueryError that wraps all errors from database drivers and provides a set of useful information:
- A proper stack trace to identify which exact
Drizzlequery failed - The generated SQL string and its parameters
- The original stack trace from the driver that caused the DrizzleQueryError
Drizzle cache module
Drizzle sends every query straight to your database by default. There are no hidden actions, no automatic caching or invalidation - you’ll always see exactly what runs. If you want caching, you must opt in.
By default, Drizzle uses a explicit caching strategy (i.e. global: false), so nothing is ever cached unless you ask. This prevents surprises or hidden performance traps in your application. Alternatively, you can flip on all caching (global: true) so that every select will look in cache first.
Out first native integration was built together with Upstash team and let you natively use upstash as a cache for your drizzle queries
import { upstashCache } from "drizzle-orm/cache/upstash";
import { drizzle } from "drizzle-orm/...";
const db = drizzle(process.env.DB_URL!, {
cache: upstashCache({
// 👇 Redis credentials (optional — can also be pulled from env vars)
url: '<UPSTASH_URL>',
token: '<UPSTASH_TOKEN>',
// 👇 Enable caching for all queries by default (optional)
global: true,
// 👇 Default cache behavior (optional)
config: { ex: 60 }
})
});You can also implement your own cache, as Drizzle exposes all the necessary APIs, such as get, put, mutate, etc.
You can find full implementation details on the website
import Keyv from "keyv";
export class TestGlobalCache extends Cache {
private globalTtl: number = 1000;
// This object will be used to store which query keys were used
// for a specific table, so we can later use it for invalidation.
private usedTablesPerKey: Record<string, string[]> = {};
constructor(private kv: Keyv = new Keyv()) {
super();
}
// For the strategy, we have two options:
// - 'explicit': The cache is used only when .$withCache() is added to a query.
// - 'all': All queries are cached globally.
// The default behavior is 'explicit'.
override strategy(): "explicit" | "all" {
return "all";
}
// This function accepts query and parameters that cached into key param,
// allowing you to retrieve response values for this query from the cache.
override async get(key: string): Promise<any[] | undefined> {
...
}
// This function accepts several options to define how cached data will be stored:
// - 'key': A hashed query and parameters.
// - 'response': An array of values returned by Drizzle from the database.
// - 'tables': An array of tables involved in the select queries. This information is needed for cache invalidation.
//
// For example, if a query uses the "users" and "posts" tables, you can store this information. Later, when the app executes
// any mutation statements on these tables, you can remove the corresponding key from the cache.
// If you're okay with eventual consistency for your queries, you can skip this option.
override async put(
key: string,
response: any,
tables: string[],
config?: CacheConfig,
): Promise<void> {
...
}
// This function is called when insert, update, or delete statements are executed.
// You can either skip this step or invalidate queries that used the affected tables.
//
// The function receives an object with two keys:
// - 'tags': Used for queries labeled with a specific tag, allowing you to invalidate by that tag.
// - 'tables': The actual tables affected by the insert, update, or delete statements,
// helping you track which tables have changed since the last cache update.
override async onMutate(params: {
tags: string | string[];
tables: string | string[] | Table<any> | Table<any>[];
}): Promise<void> {
...
}
}For more usage example you can check our docs
drizzle-kit@0.31.1
Fixed drizzle-kit pull bugs when using Gel extensions.
Because Gel extensions create schema names containing :: (for example, ext::auth), Drizzle previously handled these names incorrectly. Starting with this release, you can use Gel extensions without any problems. Here’s what you should do:
- Enable extensions schemas in
drizzle.config.ts
import { defineConfig } from "drizzle-kit";
export default defineConfig({
dialect: 'gel',
schemaFilter: ['ext::auth', 'public']
});-
Run
drizzle-kit pull -
Done!
0.43.1
0.43.0
Features
- Added
cross join(#1414) - Added lateral
left,inner,crossjoins toPostgreSQL,MySQL,Gel,SingleStore - Added drizzle connection attributes to
SingleStore's driver instances
Fixes
- Removed unsupported by dialect
full joinfromMySQLselect api - Forced
Gelcolumns to always have explicit schema & table prefixes due to potential errors caused by lack of such prefix in subquery's selection when there's already a column bearing same name in context - Added missing export for
PgTextBuilderInitialtype - Removed outdated
IfNotImportedtype check fromSingleStoredriver initializer - Fixed incorrect type inferrence for insert and update models with non-strict
tsconfigs (#2654) - Fixed invalid spelling of
nowaitflag (#3554) - Add join lateral support
- Remove .fullJoin() from MySQL API
0.42.0
Features
Duplicate imports removal
When importing from drizzle-orm using custom loaders, you may encounter issues such as: SyntaxError: The requested module 'drizzle-orm' does not provide an export named 'eq'
This issue arose because there were duplicated exports in drizzle-orm. To address this, we added a set of tests that checks every file in drizzle-orm to ensure all exports are valid. These tests will fail if any new duplicated exports appear.
In this release, we’ve removed all duplicated exports, so you should no longer encounter this issue.
pgEnum and mysqlEnum now can accept both strings and TS enums
If you provide a TypeScript enum, all your types will be inferred as that enum - so you can insert and retrieve enum values directly. If you provide a string union, it will work as before.
enum Test {
a = 'a',
b = 'b',
c = 'c',
}
const tableWithTsEnums = mysqlTable('enums_test_case', {
id: serial().primaryKey(),
enum1: mysqlEnum(Test).notNull(),
enum2: mysqlEnum(Test).default(Test.a),
});
await db.insert(tableWithTsEnums).values([
{ id: 1, enum1: Test.a, enum2: Test.b, enum3: Test.c },
{ id: 2, enum1: Test.a, enum3: Test.c },
{ id: 3, enum1: Test.a },
]);
const res = await db.select().from(tableWithTsEnums);
expect(res).toEqual([
{ id: 1, enum1: 'a', enum2: 'b', enum3: 'c' },
{ id: 2, enum1: 'a', enum2: 'a', enum3: 'c' },
{ id: 3, enum1: 'a', enum2: 'a', enum3: 'b' },
]);Improvements
- Make
inArrayacceptReadonlyArrayas a value - thanks @Zamiell - Pass row type parameter to
@planetscale/database's execute - thanks @ayrton - New
InferEnumtype - thanks @totigm
Issues closed
drizzle-kit@0.31.0
Features and improvements
Enum DDL improvements
For situations where you drop an enum value or reorder values in an enum, there is no native way to do this in PostgreSQL. To handle these cases, drizzle-kit used to:
- Change the column data types from the enum to text
- Drop the old enum
- Add the new enum
- Change the column data types back to the new enum
However, there were a few scenarios that weren’t covered: PostgreSQL wasn’t updating default expressions for columns when their data types changed
Therefore, for cases where you either change a column’s data type from an enum to some other type, drop an enum value, or reorder enum values, we now do the following:
- Change the column data types from the enum to text
- Set the default using the ::text expression
- Drop the old enum
- Add the new enum
- Change the column data types back to the new enum
- Set the default using the ::<new_enum> expression
esbuild version upgrade
For drizzle-kit we upgraded the version to latest (0.25.2), thanks @paulmarsicloud
Bug fixes
drizzle-kit@0.30.6
0.41.0
bigint,numbermodes forSQLite,MySQL,PostgreSQL,SingleStoredecimal&numericcolumn types- Changed behavior of
sql-jsquery preparation to query prebuild instead of db-side prepare due to need to manually free prepared queries, removed.free()method - Fixed
MySQL,SingleStorevarcharallowing not specifyinglengthin config - Fixed
MySQL,SingleStorebinary,varbinarydata\type mismatches - Fixed
numeric\decimaldata\type mismatches: #1290, #1453 - Fixed
drizzle-studio+AWS Data Apiconnection issue: #3224 - Fixed
isConfigutility function checking types of wrong fields - Enabled
supportBigNumbersin auto-createdmysql2driver instances - Fixed custom schema tables querying in RQBv1: #4060
- Removed in-driver mapping for postgres types
1231(numeric[]),1115(timestamp[]),1185(timestamp_with_timezone[]),1187(interval[]),1182(date[]), preventing precision loss and data\type mismatches - Fixed
SQLitebuffer-modeblobsometimes returningnumber[]