Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion drizzle-orm/src/aws-data-api/pg/driver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RDSDataClient, type RDSDataClientConfig } from '@aws-sdk/client-rds-data';
import { entityKind, is } from '~/entity.ts';
import type { DrizzleQueryError } from '~/errors.ts';
import type { Logger } from '~/logger.ts';
import { DefaultLogger } from '~/logger.ts';
import { PgDatabase } from '~/pg-core/db.ts';
Expand All @@ -22,6 +23,7 @@ import { AwsDataApiSession } from './session.ts';
export interface PgDriverOptions {
logger?: Logger;
cache?: Cache;
onError?: (error: DrizzleQueryError) => void;
database: string;
resourceArn: string;
secretArn: string;
Expand Down Expand Up @@ -119,7 +121,12 @@ function construct<TSchema extends Record<string, unknown> = Record<string, neve
};
}

const session = new AwsDataApiSession(client, dialect, schema, { ...config, logger, cache: config.cache }, undefined);
const session = new AwsDataApiSession(client, dialect, schema, {
...config,
logger,
cache: config.cache,
onError: config.onError,
}, undefined);
const db = new AwsDataApiPgDatabase(dialect, session, schema as any);
(<any> db).$client = client;
(<any> db).$cache = config.cache;
Expand Down
31 changes: 18 additions & 13 deletions drizzle-orm/src/aws-data-api/pg/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { Cache } from '~/cache/core/cache.ts';
import { NoopCache } from '~/cache/core/cache.ts';
import type { WithCacheConfig } from '~/cache/core/types.ts';
import { entityKind } from '~/entity.ts';
import type { DrizzleQueryError } from '~/errors.ts';
import type { Logger } from '~/logger.ts';
import {
type PgDialect,
Expand Down Expand Up @@ -151,6 +152,7 @@ export class AwsDataApiPreparedQuery<
export interface AwsDataApiSessionOptions {
logger?: Logger;
cache?: Cache;
onError?: (error: DrizzleQueryError) => void;
database: string;
resourceArn: string;
secretArn: string;
Expand Down Expand Up @@ -188,6 +190,7 @@ export class AwsDataApiSession<
database: options.database,
};
this.cache = options.cache ?? new NoopCache();
this.onError = options.onError;
}

prepareQuery<
Expand All @@ -206,19 +209,21 @@ export class AwsDataApiSession<
cacheConfig?: WithCacheConfig,
transactionId?: string,
): AwsDataApiPreparedQuery<T> {
return new AwsDataApiPreparedQuery(
this.client,
query.sql,
query.params,
query.typings ?? [],
this.options,
this.cache,
queryMetadata,
cacheConfig,
fields,
transactionId ?? this.transactionId,
isResponseInArrayMode,
customResultMapper,
return this.attachErrorHandler(
new AwsDataApiPreparedQuery(
this.client,
query.sql,
query.params,
query.typings ?? [],
this.options,
this.cache,
queryMetadata,
cacheConfig,
fields,
transactionId ?? this.transactionId,
isResponseInArrayMode,
customResultMapper,
),
);
}

Expand Down
2 changes: 1 addition & 1 deletion drizzle-orm/src/better-sqlite3/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function construct<TSchema extends Record<string, unknown> = Record<string, neve
};
}

const session = new BetterSQLiteSession(client, dialect, schema, { logger });
const session = new BetterSQLiteSession(client, dialect, schema, { logger, onError: config.onError });
const db = new BetterSQLite3Database('sync', dialect, session, schema);
(<any> db).$client = client;
// (<any> db).$cache = config.cache;
Expand Down
27 changes: 16 additions & 11 deletions drizzle-orm/src/better-sqlite3/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Database, RunResult, Statement } from 'better-sqlite3';
import { type Cache, NoopCache } from '~/cache/core/index.ts';
import type { WithCacheConfig } from '~/cache/core/types.ts';
import { entityKind } from '~/entity.ts';
import type { DrizzleQueryError } from '~/errors.ts';
import type { Logger } from '~/logger.ts';
import { NoopLogger } from '~/logger.ts';
import type { RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';
Expand All @@ -21,6 +22,7 @@ import { mapResultRow } from '~/utils.ts';
export interface BetterSQLiteSessionOptions {
logger?: Logger;
cache?: Cache;
onError?: (error: DrizzleQueryError) => void;
}

type PreparedQueryConfig = Omit<PreparedQueryConfigBase, 'statement' | 'run'>;
Expand All @@ -43,6 +45,7 @@ export class BetterSQLiteSession<
super(dialect);
this.logger = options.logger ?? new NoopLogger();
this.cache = options.cache ?? new NoopCache();
this.onError = options.onError;
}

prepareQuery<T extends Omit<PreparedQueryConfig, 'run'>>(
Expand All @@ -58,17 +61,19 @@ export class BetterSQLiteSession<
cacheConfig?: WithCacheConfig,
): PreparedQuery<T> {
const stmt = this.client.prepare(query.sql);
return new PreparedQuery(
stmt,
query,
this.logger,
this.cache,
queryMetadata,
cacheConfig,
fields,
executeMethod,
isResponseInArrayMode,
customResultMapper,
return this.attachErrorHandler(
new PreparedQuery(
stmt,
query,
this.logger,
this.cache,
queryMetadata,
cacheConfig,
fields,
executeMethod,
isResponseInArrayMode,
customResultMapper,
),
);
}

Expand Down
6 changes: 5 additions & 1 deletion drizzle-orm/src/bun-sql/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ function construct<TSchema extends Record<string, unknown> = Record<string, neve
};
}

const session = new BunSQLSession(client, dialect, schema, { logger, cache: config.cache });
const session = new BunSQLSession(client, dialect, schema, {
logger,
cache: config.cache,
onError: config.onError,
});
const db = new BunSQLDatabase(dialect, session, schema as any) as BunSQLDatabase<TSchema>;
(<any> db).$client = client;
(<any> db).$cache = config.cache;
Expand Down
27 changes: 16 additions & 11 deletions drizzle-orm/src/bun-sql/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { SavepointSQL, SQL, TransactionSQL } from 'bun';
import { type Cache, NoopCache } from '~/cache/core/index.ts';
import type { WithCacheConfig } from '~/cache/core/types.ts';
import { entityKind } from '~/entity.ts';
import type { DrizzleQueryError } from '~/errors.ts';
import type { Logger } from '~/logger.ts';
import { NoopLogger } from '~/logger.ts';
import type { PgDialect } from '~/pg-core/dialect.ts';
Expand Down Expand Up @@ -105,6 +106,7 @@ export class BunSQLPreparedQuery<T extends PreparedQueryConfig> extends PgPrepar
export interface BunSQLSessionOptions {
logger?: Logger;
cache?: Cache;
onError?: (error: DrizzleQueryError) => void;
}

export class BunSQLSession<
Expand All @@ -127,6 +129,7 @@ export class BunSQLSession<
super(dialect);
this.logger = options.logger ?? new NoopLogger();
this.cache = options.cache ?? new NoopCache();
this.onError = options.onError;
}

prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(
Expand All @@ -141,17 +144,19 @@ export class BunSQLSession<
},
cacheConfig?: WithCacheConfig,
): PgPreparedQuery<T> {
return new BunSQLPreparedQuery(
this.client,
query.sql,
query.params,
this.logger,
this.cache,
queryMetadata,
cacheConfig,
fields,
isResponseInArrayMode,
customResultMapper,
return this.attachErrorHandler(
new BunSQLPreparedQuery(
this.client,
query.sql,
query.params,
this.logger,
this.cache,
queryMetadata,
cacheConfig,
fields,
isResponseInArrayMode,
customResultMapper,
),
);
}

Expand Down
2 changes: 1 addition & 1 deletion drizzle-orm/src/bun-sqlite/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function construct<TSchema extends Record<string, unknown> = Record<string, neve
};
}

const session = new SQLiteBunSession(client, dialect, schema, { logger });
const session = new SQLiteBunSession(client, dialect, schema, { logger, onError: config.onError });
const db = new BunSQLiteDatabase('sync', dialect, session, schema) as BunSQLiteDatabase<TSchema>;
(<any> db).$client = client;

Expand Down
21 changes: 13 additions & 8 deletions drizzle-orm/src/bun-sqlite/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import type { Database, Statement as BunStatement } from 'bun:sqlite';
import { entityKind } from '~/entity.ts';
import type { DrizzleQueryError } from '~/errors.ts';
import type { Logger } from '~/logger.ts';
import { NoopLogger } from '~/logger.ts';
import type { RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';
Expand All @@ -19,6 +20,7 @@ import { mapResultRow } from '~/utils.ts';

export interface SQLiteBunSessionOptions {
logger?: Logger;
onError?: (error: DrizzleQueryError) => void;
}

type PreparedQueryConfig = Omit<PreparedQueryConfigBase, 'statement' | 'run'>;
Expand All @@ -40,6 +42,7 @@ export class SQLiteBunSession<
) {
super(dialect);
this.logger = options.logger ?? new NoopLogger();
this.onError = options.onError;
}

exec(query: string): void {
Expand All @@ -54,14 +57,16 @@ export class SQLiteBunSession<
customResultMapper?: (rows: unknown[][]) => unknown,
): PreparedQuery<T> {
const stmt = this.client.prepare(query.sql);
return new PreparedQuery(
stmt,
query,
this.logger,
fields,
executeMethod,
isResponseInArrayMode,
customResultMapper,
return this.attachErrorHandler(
new PreparedQuery(
stmt,
query,
this.logger,
fields,
executeMethod,
isResponseInArrayMode,
customResultMapper,
),
);
}

Expand Down
6 changes: 5 additions & 1 deletion drizzle-orm/src/d1/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ export function drizzle<
};
}

const session = new SQLiteD1Session(client as D1Database, dialect, schema, { logger, cache: config.cache });
const session = new SQLiteD1Session(client as D1Database, dialect, schema, {
logger,
cache: config.cache,
onError: config.onError,
});
const db = new DrizzleD1Database('async', dialect, session, schema) as DrizzleD1Database<TSchema>;
(<any> db).$client = client;
(<any> db).$cache = config.cache;
Expand Down
27 changes: 16 additions & 11 deletions drizzle-orm/src/d1/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { BatchItem } from '~/batch.ts';
import { type Cache, NoopCache } from '~/cache/core/index.ts';
import type { WithCacheConfig } from '~/cache/core/types.ts';
import { entityKind } from '~/entity.ts';
import type { DrizzleQueryError } from '~/errors.ts';
import type { Logger } from '~/logger.ts';
import { NoopLogger } from '~/logger.ts';
import type { RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';
Expand All @@ -23,6 +24,7 @@ import { mapResultRow } from '~/utils.ts';
export interface SQLiteD1SessionOptions {
logger?: Logger;
cache?: Cache;
onError?: (error: DrizzleQueryError) => void;
}

type PreparedQueryConfig = Omit<PreparedQueryConfigBase, 'statement' | 'run'>;
Expand All @@ -45,6 +47,7 @@ export class SQLiteD1Session<
super(dialect);
this.logger = options.logger ?? new NoopLogger();
this.cache = options.cache ?? new NoopCache();
this.onError = options.onError;
}

prepareQuery(
Expand All @@ -60,17 +63,19 @@ export class SQLiteD1Session<
cacheConfig?: WithCacheConfig,
): D1PreparedQuery {
const stmt = this.client.prepare(query.sql);
return new D1PreparedQuery(
stmt,
query,
this.logger,
this.cache,
queryMetadata,
cacheConfig,
fields,
executeMethod,
isResponseInArrayMode,
customResultMapper,
return this.attachErrorHandler(
new D1PreparedQuery(
stmt,
query,
this.logger,
this.cache,
queryMetadata,
cacheConfig,
fields,
executeMethod,
isResponseInArrayMode,
customResultMapper,
),
);
}

Expand Down
5 changes: 4 additions & 1 deletion drizzle-orm/src/durable-sqlite/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export function drizzle<
};
}

const session = new SQLiteDOSession(client as DurableObjectStorage, dialect, schema, { logger });
const session = new SQLiteDOSession(client as DurableObjectStorage, dialect, schema, {
logger,
onError: config.onError,
});
const db = new DrizzleSqliteDODatabase('sync', dialect, session, schema) as DrizzleSqliteDODatabase<TSchema>;
(<any> db).$client = client;

Expand Down
Loading