Skip to content

Commit 42c284e

Browse files
authored
beta.10 (#5230)
* Tagged effect errors for effect drivers, fixed kit `bun-sql` `sqlite`, `mysql` driver variants using `pg` functions * Typo fix * Extended type tests for columns with `strictNullChecks: false` * Fixed broken type inferrence of `PgColumn`s with `"strictNullChecks": false` typescript option caused by updates in `1.0.0-beta.9`
1 parent e89174b commit 42c284e

41 files changed

Lines changed: 428 additions & 195 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Bug fixes
2+
3+
- Fixed usage of `pg` dialect functions while using `bun-sql` with `sqlite`, `mysql` dialects
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Tagged `DrizzleError`, `DrizzleQueryError`, `TransactionRollbackError` error variants for `Effect` drivers for usage with `Effect.catchTag('DrizzleQueryError', (e: TaggedDrizzleQueryError) => { ... })`
2+
- Fixed broken type inferrence of `PgColumn`s with `"strictNullChecks": false` typescript option caused by updates in `1.0.0-beta.9`

drizzle-arktype/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-arktype",
3-
"version": "1.0.0-beta.9",
3+
"version": "1.0.0-beta.10",
44
"description": "Generate arktype schemas from Drizzle ORM schemas",
55
"type": "module",
66
"scripts": {

drizzle-kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-kit",
3-
"version": "1.0.0-beta.9",
3+
"version": "1.0.0-beta.10",
44
"homepage": "https://orm.drizzle.team",
55
"keywords": [
66
"drizzle",

drizzle-kit/src/cli/connections.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,8 @@ export const preparePostgresDB = async (
735735
if (await checkPackage('bun')) {
736736
console.log(withStyle.info(`Using 'bun' driver for database querying`));
737737
const { SQL } = await import('bun');
738-
const { drizzle } = await import('drizzle-orm/bun-sql');
739-
const { migrate } = await import('drizzle-orm/bun-sql/migrator');
738+
const { drizzle } = await import('drizzle-orm/bun-sql/postgres');
739+
const { migrate } = await import('drizzle-orm/bun-sql/postgres/migrator');
740740

741741
const ssl = 'ssl' in credentials
742742
? credentials.ssl === 'prefer'
@@ -1546,8 +1546,8 @@ export const connectToMySQL = async (
15461546
if (await checkPackage('bun')) {
15471547
console.log(withStyle.info(`Using 'bun' driver for database querying`));
15481548
const { SQL } = await import('bun');
1549-
const { drizzle } = await import('drizzle-orm/bun-sql');
1550-
const { migrate } = await import('drizzle-orm/bun-sql/migrator');
1549+
const { drizzle } = await import('drizzle-orm/bun-sql/mysql');
1550+
const { migrate } = await import('drizzle-orm/bun-sql/mysql/migrator');
15511551

15521552
const ssl = result.credentials && 'ssl' in result.credentials
15531553
? result.credentials.ssl === 'prefer'
@@ -2174,8 +2174,8 @@ export const connectToSQLite = async (
21742174
if (await checkPackage('bun')) {
21752175
console.log(withStyle.info(`Using 'bun' driver for database querying`));
21762176
const { SQL } = await import('bun');
2177-
const { drizzle } = await import('drizzle-orm/bun-sql');
2178-
const { migrate } = await import('drizzle-orm/bun-sql/migrator');
2177+
const { drizzle } = await import('drizzle-orm/bun-sql/sqlite');
2178+
const { migrate } = await import('drizzle-orm/bun-sql/sqlite/migrator');
21792179

21802180
const client = new SQL({
21812181
adapter: 'sqlite',

drizzle-orm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-orm",
3-
"version": "1.0.0-beta.9",
3+
"version": "1.0.0-beta.10",
44
"description": "Drizzle ORM package for SQL databases",
55
"type": "module",
66
"scripts": {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { TaggedError } from 'effect/Data';
2+
import { entityKind } from '~/entity.ts';
3+
4+
export class TaggedDrizzleError extends TaggedError('DrizzleError') {
5+
static readonly [entityKind]: string = 'TaggedDrizzleError';
6+
7+
override readonly message: string;
8+
override readonly cause?: unknown;
9+
10+
constructor({ message, cause }: { message?: string; cause?: unknown }) {
11+
super();
12+
this.name = 'TaggedDrizzleError';
13+
this.message = message ?? '';
14+
this.cause = cause;
15+
}
16+
}
17+
18+
export class TaggedDrizzleQueryError extends TaggedError('DrizzleQueryError') {
19+
static readonly [entityKind]: string = 'TaggedDrizzleQueryError';
20+
21+
override readonly message: string;
22+
23+
constructor(
24+
public readonly query: string,
25+
public readonly params: any[],
26+
public override cause?: Error,
27+
) {
28+
super();
29+
this.message = `Failed query: ${query}\nparams: ${params}`;
30+
Error.captureStackTrace(this, TaggedDrizzleQueryError);
31+
32+
// ES2022+: preserves original error on `.cause`
33+
if (cause) (this as any).cause = cause;
34+
}
35+
}
36+
37+
export class TaggedTransactionRollbackError extends TaggedError('TransactionRollbackError') {
38+
static readonly [entityKind]: string = 'TaggedTransactionRollbackError';
39+
40+
override readonly message = 'Rollback';
41+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './errors.ts';
2+
export * from './query-effect.ts';

drizzle-orm/src/effect-core/query-effect.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { Effect } from 'effect';
22
import type { Pipeable } from 'effect/Pipeable';
33
import { entityKind } from '~/entity.ts';
4-
import type { DrizzleQueryError } from '~/errors.ts';
54
import { applyMixins } from '~/utils.ts';
5+
import type { TaggedDrizzleQueryError } from './errors.ts';
66

7-
export interface QueryEffect<Succes = never, Failure = DrizzleQueryError, Context = never>
8-
extends Effect.Effect<Succes, Failure, Context>
7+
export interface QueryEffect<Success = never, Failure = TaggedDrizzleQueryError, Context = never>
8+
extends Effect.Effect<Success, Failure, Context>
99
{
1010
}
1111

12-
export abstract class QueryEffect<Succes = never, Failure = DrizzleQueryError, Context = never> {
12+
export abstract class QueryEffect<Success = never, Failure = TaggedDrizzleQueryError, Context = never> {
1313
static readonly [entityKind]: string = 'EffectWrapper';
1414

15-
protected _effect!: Effect.Effect<Succes, Failure, Context>;
15+
protected _effect!: Effect.Effect<Success, Failure, Context>;
1616
protected get effect() {
1717
this._effect = Effect.suspend(() => this.execute());
1818

@@ -40,7 +40,7 @@ export abstract class QueryEffect<Succes = never, Failure = DrizzleQueryError, C
4040
return this._pipe;
4141
}
4242

43-
abstract execute(...args: any[]): Effect.Effect<Succes, Failure, Context>;
43+
abstract execute(...args: any[]): Effect.Effect<Success, Failure, Context>;
4444

4545
get [Effect.EffectTypeId]() {
4646
return this.effect[Effect.EffectTypeId];

drizzle-orm/src/effect-postgres/session.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { Effect } from 'effect';
33
import type * as V1 from '~/_relations.ts';
44
import type { EffectCache } from '~/cache/core/cache-effect.ts';
55
import type { WithCacheConfig } from '~/cache/core/types.ts';
6+
import { TaggedDrizzleQueryError, type TaggedTransactionRollbackError } from '~/effect-core/errors.ts';
67
import { entityKind } from '~/entity.ts';
7-
import { DrizzleQueryError, type TransactionRollbackError } from '~/errors.ts';
88
import { type Logger, NoopLogger } from '~/logger.ts';
99
import type { PgDialect } from '~/pg-core/dialect.ts';
1010
import { PgEffectPreparedQuery, PgEffectSession, PgEffectTransaction } from '~/pg-core/effect/session.ts';
@@ -46,7 +46,7 @@ export class EffectPgPreparedQuery<T extends PreparedQueryConfig, TIsRqbV2 exten
4646
super({ sql: queryString, params }, cache, queryMetadata, cacheConfig);
4747
}
4848

49-
execute(placeholderValues?: Record<string, unknown>): Effect.Effect<T['execute'], DrizzleQueryError> {
49+
execute(placeholderValues?: Record<string, unknown>): Effect.Effect<T['execute'], TaggedDrizzleQueryError> {
5050
if (this.isRqbV2Query) return this.executeRqbV2(placeholderValues);
5151

5252
const { query, logger, customResultMapper, fields, joinsNotNullableMap, client } = this;
@@ -82,7 +82,7 @@ export class EffectPgPreparedQuery<T extends PreparedQueryConfig, TIsRqbV2 exten
8282

8383
private executeRqbV2(
8484
placeholderValues?: Record<string, unknown>,
85-
): Effect.Effect<T['execute'], DrizzleQueryError> {
85+
): Effect.Effect<T['execute'], TaggedDrizzleQueryError> {
8686
const { query, logger, customResultMapper, client } = this;
8787
const params = fillPlaceholders(query.params, placeholderValues ?? {});
8888

@@ -97,12 +97,12 @@ export class EffectPgPreparedQuery<T extends PreparedQueryConfig, TIsRqbV2 exten
9797
),
9898
).pipe(Effect.catchAll((e) => {
9999
// eslint-disable-next-line @drizzle-internal/no-instanceof
100-
return Effect.fail(new DrizzleQueryError(query.sql, params, e instanceof Error ? e : undefined));
100+
return Effect.fail(new TaggedDrizzleQueryError(query.sql, params, e instanceof Error ? e : undefined));
101101
}))
102102
);
103103
}
104104

105-
override all(placeholderValues?: Record<string, unknown>): Effect.Effect<T['all'], DrizzleQueryError, never> {
105+
override all(placeholderValues?: Record<string, unknown>): Effect.Effect<T['all'], TaggedDrizzleQueryError, never> {
106106
const { query, logger, client } = this;
107107
const params = fillPlaceholders(query.params, placeholderValues ?? {});
108108

@@ -194,7 +194,7 @@ export class EffectPgSession<
194194
);
195195
}
196196

197-
override execute<T>(query: SQL): Effect.Effect<T, DrizzleQueryError> {
197+
override execute<T>(query: SQL): Effect.Effect<T, TaggedDrizzleQueryError> {
198198
return this.prepareQuery<PreparedQueryConfig & { execute: T }>(
199199
this.dialect.sqlToQuery(query),
200200
undefined,
@@ -203,7 +203,7 @@ export class EffectPgSession<
203203
).execute();
204204
}
205205

206-
override all<T>(query: SQL): Effect.Effect<T, DrizzleQueryError> {
206+
override all<T>(query: SQL): Effect.Effect<T, TaggedDrizzleQueryError> {
207207
return this.prepareQuery<PreparedQueryConfig & { all: T }>(
208208
this.dialect.sqlToQuery(query),
209209
undefined,
@@ -224,8 +224,8 @@ export class EffectPgSession<
224224
TRelations,
225225
TSchema
226226
>,
227-
) => Effect.Effect<T, DrizzleQueryError | TransactionRollbackError, never>,
228-
): Effect.Effect<T, DrizzleQueryError | TransactionRollbackError, never> {
227+
) => Effect.Effect<T, TaggedDrizzleQueryError | TaggedTransactionRollbackError, never>,
228+
): Effect.Effect<T, TaggedDrizzleQueryError | TaggedTransactionRollbackError, never> {
229229
const { dialect, relations, schema } = this;
230230
const session = this;
231231

@@ -238,7 +238,7 @@ export class EffectPgSession<
238238
);
239239

240240
return yield* transaction(tx);
241-
}));
241+
})) as Effect.Effect<T, TaggedDrizzleQueryError | TaggedTransactionRollbackError, never>;
242242
}
243243
}
244244

@@ -253,8 +253,8 @@ export class EffectPgTransaction<
253253
override transaction<T>(
254254
transaction: (
255255
tx: PgEffectTransaction<TQueryResult, TFullSchema, TRelations, TSchema>,
256-
) => Effect.Effect<T, DrizzleQueryError | TransactionRollbackError, never>,
257-
): Effect.Effect<T, DrizzleQueryError | TransactionRollbackError, never> {
256+
) => Effect.Effect<T, TaggedDrizzleQueryError | TaggedTransactionRollbackError, never>,
257+
): Effect.Effect<T, TaggedDrizzleQueryError | TaggedTransactionRollbackError, never> {
258258
return this.session.transaction(transaction);
259259
}
260260
}

0 commit comments

Comments
 (0)