Skip to content

Commit b5a2614

Browse files
committed
Merge branch 'alternation-engine' of github.com:drizzle-team/drizzle-orm into alternation-engine
2 parents 5759e61 + acd9982 commit b5a2614

File tree

305 files changed

+6355
-27714
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

305 files changed

+6355
-27714
lines changed

.github/workflows/release-feature-branch.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ jobs:
237237

238238
- uses: actions/setup-node@v4
239239
with:
240-
node-version: '18.18'
240+
node-version: '22'
241241
registry-url: 'https://registry.npmjs.org'
242242

243243
- uses: pnpm/action-setup@v3
@@ -334,7 +334,7 @@ jobs:
334334

335335
- uses: actions/setup-node@v4
336336
with:
337-
node-version: '18.18'
337+
node-version: '22'
338338
registry-url: 'https://registry.npmjs.org'
339339

340340
- uses: pnpm/action-setup@v3
@@ -415,4 +415,4 @@ jobs:
415415
working-directory: ${{ matrix.package }}
416416
shell: bash
417417
env:
418-
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
418+
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}

.github/workflows/release-latest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ jobs:
360360

361361
- uses: actions/setup-node@v4
362362
with:
363-
node-version: '18.18'
363+
node-version: '22'
364364
registry-url: 'https://registry.npmjs.org'
365365

366366
- uses: pnpm/action-setup@v3

.github/workflows/unpublish-release-feature-branch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
- uses: actions/setup-node@v4
2323
with:
24-
node-version: '18.18'
24+
node-version: '22'
2525
registry-url: 'https://registry.npmjs.org'
2626

2727
- name: Unpublish

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18.18
1+
22

changelogs/drizzle-arktype/0.1.3.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- TS language server performance improvements
2+
- Fixed [Buffer is not defined using drizzle-arktype client side with vite](https://github.com/drizzle-team/drizzle-orm/issues/4383)
3+
- Fixed [[BUG]: drizzle-arktype Buffer is undefined](https://github.com/drizzle-team/drizzle-orm/issues/4371)

changelogs/drizzle-orm/0.44.0.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
## Error handling
2+
3+
Starting from this version, we’ve introduced a new `DrizzleQueryError` that wraps all errors from database drivers and provides a set of useful information:
4+
5+
1. A proper stack trace to identify which exact `Drizzle` query failed
6+
2. The generated SQL string and its parameters
7+
3. The original stack trace from the driver that caused the DrizzleQueryError
8+
9+
## Drizzle `cache` module
10+
11+
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.
12+
13+
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.
14+
15+
Out first native integration was built together with Upstash team and let you natively use `upstash` as a cache for your drizzle queries
16+
17+
```ts
18+
import { upstashCache } from "drizzle-orm/cache/upstash";
19+
import { drizzle } from "drizzle-orm/...";
20+
21+
const db = drizzle(process.env.DB_URL!, {
22+
cache: upstashCache({
23+
// 👇 Redis credentials (optional — can also be pulled from env vars)
24+
url: '<UPSTASH_URL>',
25+
token: '<UPSTASH_TOKEN>',
26+
// 👇 Enable caching for all queries by default (optional)
27+
global: true,
28+
// 👇 Default cache behavior (optional)
29+
config: { ex: 60 }
30+
})
31+
});
32+
```
33+
34+
You can also implement your own cache, as Drizzle exposes all the necessary APIs, such as get, put, mutate, etc.
35+
You can find full implementation details on the [website](https://orm.drizzle.team/docs/cache#custom-cache)
36+
37+
```ts
38+
import Keyv from "keyv";
39+
export class TestGlobalCache extends Cache {
40+
private globalTtl: number = 1000;
41+
// This object will be used to store which query keys were used
42+
// for a specific table, so we can later use it for invalidation.
43+
private usedTablesPerKey: Record<string, string[]> = {};
44+
constructor(private kv: Keyv = new Keyv()) {
45+
super();
46+
}
47+
// For the strategy, we have two options:
48+
// - 'explicit': The cache is used only when .$withCache() is added to a query.
49+
// - 'all': All queries are cached globally.
50+
// The default behavior is 'explicit'.
51+
override strategy(): "explicit" | "all" {
52+
return "all";
53+
}
54+
// This function accepts query and parameters that cached into key param,
55+
// allowing you to retrieve response values for this query from the cache.
56+
override async get(key: string): Promise<any[] | undefined> {
57+
...
58+
}
59+
// This function accepts several options to define how cached data will be stored:
60+
// - 'key': A hashed query and parameters.
61+
// - 'response': An array of values returned by Drizzle from the database.
62+
// - 'tables': An array of tables involved in the select queries. This information is needed for cache invalidation.
63+
//
64+
// For example, if a query uses the "users" and "posts" tables, you can store this information. Later, when the app executes
65+
// any mutation statements on these tables, you can remove the corresponding key from the cache.
66+
// If you're okay with eventual consistency for your queries, you can skip this option.
67+
override async put(
68+
key: string,
69+
response: any,
70+
tables: string[],
71+
config?: CacheConfig,
72+
): Promise<void> {
73+
...
74+
}
75+
// This function is called when insert, update, or delete statements are executed.
76+
// You can either skip this step or invalidate queries that used the affected tables.
77+
//
78+
// The function receives an object with two keys:
79+
// - 'tags': Used for queries labeled with a specific tag, allowing you to invalidate by that tag.
80+
// - 'tables': The actual tables affected by the insert, update, or delete statements,
81+
// helping you track which tables have changed since the last cache update.
82+
override async onMutate(params: {
83+
tags: string | string[];
84+
tables: string | string[] | Table<any> | Table<any>[];
85+
}): Promise<void> {
86+
...
87+
}
88+
}
89+
```
90+
91+
For more usage example you can check our [docs](https://orm.drizzle.team/docs/cache#cache-usage-examples)

changelogs/drizzle-orm/0.44.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- [[BUG]: Drizzle can no longer run on Durable Objects](https://github.com/drizzle-team/drizzle-orm/issues/4586)

changelogs/drizzle-typebox/0.3.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- TS language server performance improvements

changelogs/drizzle-valibot/0.4.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- TS language server performance improvements

changelogs/drizzle-zod/0.8.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Support for Zod v4: Starting with this release, `drizzle-zod` now requires Zod v3.25 or later

changelogs/drizzle-zod/0.8.1.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Support for Zod v4: Starting with this release, `drizzle-zod` now requires Zod v3.25.1 or later
2+
3+
This version was released to resolve several compatibility issues with the `ZodObject` type, which were fixed in `[email protected]`, so version `0.8.0` can be skipped

changelogs/drizzle-zod/0.8.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- [[BUG]: drizzle-zod: incorrect inferred types for columns .generatedAlwaysAsIdentity()](https://github.com/drizzle-team/drizzle-orm/issues/4553)

drizzle-arktype/benchmarks/types.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { bench, setup } from '@ark/attest';
2+
import { type } from 'arktype';
3+
import { boolean, integer, pgTable, text } from 'drizzle-orm/pg-core';
4+
import { createSelectSchema } from '~/index.ts';
5+
6+
const users = pgTable('users', {
7+
id: integer().primaryKey(),
8+
firstName: text().notNull(),
9+
middleName: text(),
10+
lastName: text().notNull(),
11+
age: integer().notNull(),
12+
admin: boolean().notNull().default(false),
13+
});
14+
15+
const teardown = setup();
16+
17+
bench('select schema', () => {
18+
return createSelectSchema(users);
19+
}).types([13129, 'instantiations']);
20+
21+
bench('select schema with refinements', () => {
22+
return createSelectSchema(users, {
23+
firstName: (t) => t.atMostLength(100),
24+
middleName: (t) => t.atMostLength(100),
25+
lastName: (t) => t.atMostLength(100),
26+
age: type.number.atLeast(1),
27+
});
28+
}).types([21631, 'instantiations']);
29+
30+
teardown();

drizzle-arktype/package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-arktype",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "Generate arktype schemas from Drizzle ORM schemas",
55
"type": "module",
66
"scripts": {
@@ -9,7 +9,8 @@
99
"test:types": "cd tests && tsc",
1010
"pack": "(cd dist && npm pack --pack-destination ..) && rm -f package.tgz && mv *.tgz package.tgz",
1111
"publish": "npm publish package.tgz",
12-
"test": "vitest run"
12+
"test": "vitest run",
13+
"bench:types": "tsx ./benchmarks/types.ts"
1314
},
1415
"exports": {
1516
".": {
@@ -59,16 +60,18 @@
5960
"drizzle-orm": ">=0.36.0"
6061
},
6162
"devDependencies": {
63+
"@ark/attest": "^0.45.8",
6264
"@rollup/plugin-typescript": "^11.1.0",
6365
"@types/node": "^18.15.10",
6466
"arktype": "^2.1.10",
6567
"cpy": "^10.1.0",
6668
"drizzle-orm": "link:../drizzle-orm/dist",
67-
"json-rules-engine": "7.3.0",
69+
"json-rules-engine": "7.3.1",
6870
"rimraf": "^5.0.0",
69-
"rollup": "^3.20.7",
71+
"rollup": "^3.29.5",
72+
"tsx": "^4.19.3",
7073
"vite-tsconfig-paths": "^4.3.2",
71-
"vitest": "^1.6.0",
74+
"vitest": "^3.1.3",
7275
"zx": "^7.2.2"
7376
}
7477
}

drizzle-arktype/src/column.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ import { isColumnType, isWithEnum } from './utils.ts';
5959

6060
export const literalSchema = type.string.or(type.number).or(type.boolean).or(type.null);
6161
export const jsonSchema = literalSchema.or(type.unknown.as<any>().array()).or(type.object.as<Record<string, any>>());
62-
export const bufferSchema = type.instanceOf(Buffer); // eslint-disable-line no-instanceof/no-instanceof
62+
export const bufferSchema = type.unknown.narrow((value) => value instanceof Buffer).as<Buffer>().describe( // eslint-disable-line no-instanceof/no-instanceof
63+
'a Buffer instance',
64+
);
6365

6466
export function columnToSchema(column: Column): Type {
6567
let schema!: Type;

drizzle-arktype/src/column.types.ts

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
import { Type, type } from 'arktype';
2-
import type { Assume, Column } from 'drizzle-orm';
3-
import type { ColumnIsGeneratedAlwaysAs, IsEnumDefined, IsNever, IsUnknown, Json } from './utils.ts';
2+
import type { Column } from 'drizzle-orm';
3+
import type { Json } from './utils.ts';
44

5-
export type ArktypeNullable<TSchema> = Type<type.infer<TSchema> | null, {}>;
5+
export type ArktypeNullable<TSchema> = Type<type.infer<TSchema> | null>;
66

7-
export type ArktypeOptional<TSchema> = [Type<type.infer<TSchema>, {}>, '?'];
8-
9-
export type GetEnumValuesFromColumn<TColumn extends Column> = TColumn['_'] extends { enumValues: [string, ...string[]] }
10-
? TColumn['_']['enumValues']
11-
: undefined;
7+
export type ArktypeOptional<TSchema> = [Type<type.infer<TSchema>>, '?'];
128

139
export type GetArktypeType<
14-
TData,
15-
TColumnType extends string,
16-
TEnumValues extends [string, ...string[]] | undefined,
17-
> = IsEnumDefined<TEnumValues> extends true ? Type<Assume<TEnumValues, any[]>[number]>
18-
: TColumnType extends 'PgJson' | 'PgJsonb' | 'MySqlJson' | 'SingleStoreJson' | 'SQLiteTextJson' | 'SQLiteBlobJson'
19-
? IsUnknown<TData> extends true ? Type<Json> : Type<TData>
20-
: Type<TData>;
10+
TColumn extends Column,
11+
> = TColumn['_']['columnType'] extends
12+
'PgJson' | 'PgJsonb' | 'MySqlJson' | 'SingleStoreJson' | 'SQLiteTextJson' | 'SQLiteBlobJson'
13+
? unknown extends TColumn['_']['data'] ? Type<Json> : Type<TColumn['_']['data']>
14+
: Type<TColumn['_']['data']>;
2115

2216
type HandleSelectColumn<
2317
TSchema,
@@ -28,27 +22,20 @@ type HandleSelectColumn<
2822
type HandleInsertColumn<
2923
TSchema,
3024
TColumn extends Column,
31-
> = ColumnIsGeneratedAlwaysAs<TColumn> extends true ? never
32-
: TColumn['_']['notNull'] extends true ? TColumn['_']['hasDefault'] extends true ? ArktypeOptional<TSchema>
33-
: TSchema
25+
> = TColumn['_']['notNull'] extends true ? TColumn['_']['hasDefault'] extends true ? ArktypeOptional<TSchema>
26+
: TSchema
3427
: ArktypeOptional<ArktypeNullable<TSchema>>;
3528

3629
type HandleUpdateColumn<
3730
TSchema,
3831
TColumn extends Column,
39-
> = ColumnIsGeneratedAlwaysAs<TColumn> extends true ? never
40-
: TColumn['_']['notNull'] extends true ? ArktypeOptional<TSchema>
32+
> = TColumn['_']['notNull'] extends true ? ArktypeOptional<TSchema>
4133
: ArktypeOptional<ArktypeNullable<TSchema>>;
4234

4335
export type HandleColumn<
4436
TType extends 'select' | 'insert' | 'update',
4537
TColumn extends Column,
46-
> = GetArktypeType<
47-
TColumn['_']['data'],
48-
TColumn['_']['columnType'],
49-
GetEnumValuesFromColumn<TColumn>
50-
> extends infer TSchema ? TType extends 'select' ? HandleSelectColumn<TSchema, TColumn>
51-
: TType extends 'insert' ? HandleInsertColumn<TSchema, TColumn>
52-
: TType extends 'update' ? HandleUpdateColumn<TSchema, TColumn>
53-
: TSchema
54-
: Type;
38+
> = TType extends 'select' ? HandleSelectColumn<GetArktypeType<TColumn>, TColumn>
39+
: TType extends 'insert' ? HandleInsertColumn<GetArktypeType<TColumn>, TColumn>
40+
: TType extends 'update' ? HandleUpdateColumn<GetArktypeType<TColumn>, TColumn>
41+
: GetArktypeType<TColumn>;

drizzle-arktype/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export { bufferSchema, jsonSchema, literalSchema } from './column.ts';
22
export * from './column.types.ts';
33
export * from './schema.ts';
4-
export type { BuildSchema } from './schema.types.internal.ts';
54
export * from './schema.types.internal.ts';
65
export * from './schema.types.ts';
76
export * from './utils.ts';

0 commit comments

Comments
 (0)