@leonardovida-md/drizzle-neo-duckdb 1.5.1-3 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,7 +37,7 @@ npm install @duckdbfan/drizzle-duckdb @duckdb/node-api
37
37
  pnpm add @duckdbfan/drizzle-duckdb @duckdb/node-api
38
38
  ```
39
39
 
40
- Supported client versions include `@duckdb/node-api@1.4.4-r.1` and `@duckdb/node-api@1.5.1-r.1`. The repo now develops against `1.5.1-r.1`, and `1.4.4-r.1` remains supported.
40
+ Supported client versions include `@duckdb/node-api@1.4.4-r.1` and `@duckdb/node-api@1.5.2-r.1`. The repo now develops against `1.5.2-r.1`, and `1.4.4-r.1` remains supported.
41
41
  Tested `drizzle-orm` versions currently span `0.40.1` through `0.45.x`.
42
42
 
43
43
  ## Quick Start
package/dist/driver.d.ts CHANGED
@@ -17,6 +17,7 @@ import { type DuckLakeConfig } from './ducklake.ts';
17
17
  export interface PgDriverOptions {
18
18
  logger?: Logger;
19
19
  rejectStringArrayLiterals?: boolean;
20
+ arrayLiteralWarning?: (query: string) => void;
20
21
  prepareCache?: PreparedStatementCacheConfig;
21
22
  }
22
23
  export declare class DuckDBDriver {
@@ -36,6 +37,7 @@ export interface DuckDBConnectionConfig {
36
37
  }
37
38
  export interface DuckDBDrizzleConfig<TSchema extends Record<string, unknown> = Record<string, never>> extends DrizzleConfig<TSchema> {
38
39
  rejectStringArrayLiterals?: boolean;
40
+ arrayLiteralWarning?: (query: string) => void;
39
41
  prepareCache?: PrepareCacheOption;
40
42
  /** Pool configuration. Use preset name, size config, or false to disable. */
41
43
  pool?: DuckDBPoolConfig | PoolPreset | false;
@@ -943,6 +943,10 @@ class DuckDBSession extends PgSession {
943
943
  return;
944
944
  }
945
945
  this.hasWarnedArrayLiteral = true;
946
+ if (this.options.arrayLiteralWarning) {
947
+ this.options.arrayLiteralWarning(query);
948
+ return;
949
+ }
946
950
  this.logger.logQuery(`[duckdb] ${arrayLiteralWarning}
947
951
  query: ${query}`, []);
948
952
  };
@@ -981,6 +985,12 @@ query: ${query}`, []);
981
985
 
982
986
  class DuckDBTransaction extends PgTransaction {
983
987
  static [entityKind] = "DuckDBTransaction";
988
+ getInternals() {
989
+ return this;
990
+ }
991
+ markRollbackOnly() {
992
+ this.getInternals().session.markRollbackOnly();
993
+ }
984
994
  rollback() {
985
995
  throw new TransactionRollbackError;
986
996
  }
@@ -1007,26 +1017,26 @@ class DuckDBTransaction extends PgTransaction {
1007
1017
  return sql.raw(chunks.join(" "));
1008
1018
  }
1009
1019
  setTransaction(config) {
1010
- return this.session.execute(sql`set transaction ${this.getTransactionConfigSQL(config)}`);
1020
+ return this.getInternals().session.execute(sql`set transaction ${this.getTransactionConfigSQL(config)}`);
1011
1021
  }
1012
1022
  executeBatches(query, options = {}) {
1013
- return this.session.executeBatches(query, options);
1023
+ return this.getInternals().session.executeBatches(query, options);
1014
1024
  }
1015
1025
  executeBatchesRaw(query, options = {}) {
1016
- return this.session.executeBatchesRaw(query, options);
1026
+ return this.getInternals().session.executeBatchesRaw(query, options);
1017
1027
  }
1018
1028
  executeArrow(query) {
1019
- return this.session.executeArrow(query);
1029
+ return this.getInternals().session.executeArrow(query);
1020
1030
  }
1021
1031
  async transaction(transaction) {
1022
- const internals = this;
1032
+ const internals = this.getInternals();
1023
1033
  const savepoint = `drizzle_savepoint_${this.nestedIndex + 1}`;
1024
1034
  const savepointSql = sql.raw(`savepoint ${savepoint}`);
1025
1035
  const releaseSql = sql.raw(`release savepoint ${savepoint}`);
1026
1036
  const rollbackSql = sql.raw(`rollback to savepoint ${savepoint}`);
1027
1037
  const nestedTx = new DuckDBTransaction(internals.dialect, internals.session, this.schema, this.nestedIndex + 1);
1028
1038
  if (internals.dialect.areSavepointsUnsupported()) {
1029
- return this.runNestedWithoutSavepoint(transaction, nestedTx, internals);
1039
+ return this.runNestedWithoutSavepoint(transaction, nestedTx);
1030
1040
  }
1031
1041
  let createdSavepoint = false;
1032
1042
  try {
@@ -1038,7 +1048,7 @@ class DuckDBTransaction extends PgTransaction {
1038
1048
  throw error;
1039
1049
  }
1040
1050
  internals.dialect.markSavepointsUnsupported();
1041
- return this.runNestedWithoutSavepoint(transaction, nestedTx, internals);
1051
+ return this.runNestedWithoutSavepoint(transaction, nestedTx);
1042
1052
  }
1043
1053
  try {
1044
1054
  const result = await transaction(nestedTx);
@@ -1050,13 +1060,13 @@ class DuckDBTransaction extends PgTransaction {
1050
1060
  if (createdSavepoint) {
1051
1061
  await internals.session.execute(rollbackSql);
1052
1062
  }
1053
- internals.session.markRollbackOnly();
1063
+ this.markRollbackOnly();
1054
1064
  throw error;
1055
1065
  }
1056
1066
  }
1057
- runNestedWithoutSavepoint(transaction, nestedTx, internals) {
1067
+ runNestedWithoutSavepoint(transaction, nestedTx) {
1058
1068
  return transaction(nestedTx).catch((error) => {
1059
- internals.session.markRollbackOnly();
1069
+ this.markRollbackOnly();
1060
1070
  throw error;
1061
1071
  });
1062
1072
  }
@@ -2482,6 +2492,7 @@ class DuckDBDriver {
2482
2492
  return new DuckDBSession(this.client, this.dialect, schema, {
2483
2493
  logger: this.options.logger,
2484
2494
  rejectStringArrayLiterals: this.options.rejectStringArrayLiterals,
2495
+ arrayLiteralWarning: this.options.arrayLiteralWarning,
2485
2496
  prepareCache: this.options.prepareCache
2486
2497
  });
2487
2498
  }
@@ -2517,6 +2528,7 @@ function createFromClient(client, config = {}, instance) {
2517
2528
  const driver = new DuckDBDriver(finalClient, dialect, {
2518
2529
  logger,
2519
2530
  rejectStringArrayLiterals: config.rejectStringArrayLiterals,
2531
+ arrayLiteralWarning: config.arrayLiteralWarning,
2520
2532
  prepareCache
2521
2533
  });
2522
2534
  const session = driver.createSession(schema);
package/dist/index.mjs CHANGED
@@ -996,6 +996,10 @@ class DuckDBSession extends PgSession {
996
996
  return;
997
997
  }
998
998
  this.hasWarnedArrayLiteral = true;
999
+ if (this.options.arrayLiteralWarning) {
1000
+ this.options.arrayLiteralWarning(query);
1001
+ return;
1002
+ }
999
1003
  this.logger.logQuery(`[duckdb] ${arrayLiteralWarning}
1000
1004
  query: ${query}`, []);
1001
1005
  };
@@ -1034,6 +1038,12 @@ query: ${query}`, []);
1034
1038
 
1035
1039
  class DuckDBTransaction extends PgTransaction {
1036
1040
  static [entityKind] = "DuckDBTransaction";
1041
+ getInternals() {
1042
+ return this;
1043
+ }
1044
+ markRollbackOnly() {
1045
+ this.getInternals().session.markRollbackOnly();
1046
+ }
1037
1047
  rollback() {
1038
1048
  throw new TransactionRollbackError;
1039
1049
  }
@@ -1060,26 +1070,26 @@ class DuckDBTransaction extends PgTransaction {
1060
1070
  return sql.raw(chunks.join(" "));
1061
1071
  }
1062
1072
  setTransaction(config) {
1063
- return this.session.execute(sql`set transaction ${this.getTransactionConfigSQL(config)}`);
1073
+ return this.getInternals().session.execute(sql`set transaction ${this.getTransactionConfigSQL(config)}`);
1064
1074
  }
1065
1075
  executeBatches(query, options = {}) {
1066
- return this.session.executeBatches(query, options);
1076
+ return this.getInternals().session.executeBatches(query, options);
1067
1077
  }
1068
1078
  executeBatchesRaw(query, options = {}) {
1069
- return this.session.executeBatchesRaw(query, options);
1079
+ return this.getInternals().session.executeBatchesRaw(query, options);
1070
1080
  }
1071
1081
  executeArrow(query) {
1072
- return this.session.executeArrow(query);
1082
+ return this.getInternals().session.executeArrow(query);
1073
1083
  }
1074
1084
  async transaction(transaction) {
1075
- const internals = this;
1085
+ const internals = this.getInternals();
1076
1086
  const savepoint = `drizzle_savepoint_${this.nestedIndex + 1}`;
1077
1087
  const savepointSql = sql.raw(`savepoint ${savepoint}`);
1078
1088
  const releaseSql = sql.raw(`release savepoint ${savepoint}`);
1079
1089
  const rollbackSql = sql.raw(`rollback to savepoint ${savepoint}`);
1080
1090
  const nestedTx = new DuckDBTransaction(internals.dialect, internals.session, this.schema, this.nestedIndex + 1);
1081
1091
  if (internals.dialect.areSavepointsUnsupported()) {
1082
- return this.runNestedWithoutSavepoint(transaction, nestedTx, internals);
1092
+ return this.runNestedWithoutSavepoint(transaction, nestedTx);
1083
1093
  }
1084
1094
  let createdSavepoint = false;
1085
1095
  try {
@@ -1091,7 +1101,7 @@ class DuckDBTransaction extends PgTransaction {
1091
1101
  throw error;
1092
1102
  }
1093
1103
  internals.dialect.markSavepointsUnsupported();
1094
- return this.runNestedWithoutSavepoint(transaction, nestedTx, internals);
1104
+ return this.runNestedWithoutSavepoint(transaction, nestedTx);
1095
1105
  }
1096
1106
  try {
1097
1107
  const result = await transaction(nestedTx);
@@ -1103,13 +1113,13 @@ class DuckDBTransaction extends PgTransaction {
1103
1113
  if (createdSavepoint) {
1104
1114
  await internals.session.execute(rollbackSql);
1105
1115
  }
1106
- internals.session.markRollbackOnly();
1116
+ this.markRollbackOnly();
1107
1117
  throw error;
1108
1118
  }
1109
1119
  }
1110
- runNestedWithoutSavepoint(transaction, nestedTx, internals) {
1120
+ runNestedWithoutSavepoint(transaction, nestedTx) {
1111
1121
  return transaction(nestedTx).catch((error) => {
1112
- internals.session.markRollbackOnly();
1122
+ this.markRollbackOnly();
1113
1123
  throw error;
1114
1124
  });
1115
1125
  }
@@ -2535,6 +2545,7 @@ class DuckDBDriver {
2535
2545
  return new DuckDBSession(this.client, this.dialect, schema, {
2536
2546
  logger: this.options.logger,
2537
2547
  rejectStringArrayLiterals: this.options.rejectStringArrayLiterals,
2548
+ arrayLiteralWarning: this.options.arrayLiteralWarning,
2538
2549
  prepareCache: this.options.prepareCache
2539
2550
  });
2540
2551
  }
@@ -2570,6 +2581,7 @@ function createFromClient(client, config = {}, instance) {
2570
2581
  const driver = new DuckDBDriver(finalClient, dialect, {
2571
2582
  logger,
2572
2583
  rejectStringArrayLiterals: config.rejectStringArrayLiterals,
2584
+ arrayLiteralWarning: config.arrayLiteralWarning,
2573
2585
  prepareCache
2574
2586
  });
2575
2587
  const session = driver.createSession(schema);
package/dist/session.d.ts CHANGED
@@ -43,6 +43,7 @@ export declare class DuckDBPreparedQuery<T extends PreparedQueryConfig> extends
43
43
  export interface DuckDBSessionOptions {
44
44
  logger?: Logger;
45
45
  rejectStringArrayLiterals?: boolean;
46
+ arrayLiteralWarning?: (query: string) => void;
46
47
  prepareCache?: PreparedStatementCacheConfig;
47
48
  }
48
49
  export declare class DuckDBSession<TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = Record<string, never>> extends PgSession<DuckDBQueryResultHKT, TFullSchema, TSchema> {
@@ -71,6 +72,8 @@ export declare class DuckDBSession<TFullSchema extends Record<string, unknown> =
71
72
  }
72
73
  export declare class DuckDBTransaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgTransaction<DuckDBQueryResultHKT, TFullSchema, TSchema> {
73
74
  static readonly [entityKind]: string;
75
+ private getInternals;
76
+ private markRollbackOnly;
74
77
  rollback(): never;
75
78
  getTransactionConfigSQL(config: PgTransactionConfig): SQL;
76
79
  setTransaction(config: PgTransactionConfig): Promise<void>;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "module": "./dist/index.mjs",
4
4
  "main": "./dist/index.mjs",
5
5
  "types": "./dist/index.d.ts",
6
- "version": "1.5.1-3",
6
+ "version": "1.5.2",
7
7
  "description": "A drizzle ORM client for use with DuckDB. Based on drizzle's Postgres client.",
8
8
  "type": "module",
9
9
  "scripts": {
@@ -29,12 +29,12 @@
29
29
  }
30
30
  },
31
31
  "devDependencies": {
32
- "@duckdb/node-api": "1.5.1-r.1",
33
- "@types/bun": "^1.3.11",
32
+ "@duckdb/node-api": "1.5.2-r.1",
33
+ "@types/bun": "^1.3.12",
34
34
  "@types/node": "25.6.0",
35
35
  "@vitest/ui": "4.1.4",
36
36
  "drizzle-orm": "0.45.2",
37
- "prettier": "3.8.2",
37
+ "prettier": "3.8.3",
38
38
  "tinybench": "6.0.0",
39
39
  "typescript": "6.0.2",
40
40
  "uuid": "13.0.0",
package/src/driver.ts CHANGED
@@ -53,6 +53,7 @@ import {
53
53
  export interface PgDriverOptions {
54
54
  logger?: Logger;
55
55
  rejectStringArrayLiterals?: boolean;
56
+ arrayLiteralWarning?: (query: string) => void;
56
57
  prepareCache?: PreparedStatementCacheConfig;
57
58
  }
58
59
 
@@ -71,6 +72,7 @@ export class DuckDBDriver {
71
72
  return new DuckDBSession(this.client, this.dialect, schema, {
72
73
  logger: this.options.logger,
73
74
  rejectStringArrayLiterals: this.options.rejectStringArrayLiterals,
75
+ arrayLiteralWarning: this.options.arrayLiteralWarning,
74
76
  prepareCache: this.options.prepareCache,
75
77
  });
76
78
  }
@@ -88,6 +90,7 @@ export interface DuckDBDrizzleConfig<
88
90
  TSchema extends Record<string, unknown> = Record<string, never>,
89
91
  > extends DrizzleConfig<TSchema> {
90
92
  rejectStringArrayLiterals?: boolean;
93
+ arrayLiteralWarning?: (query: string) => void;
91
94
  prepareCache?: PrepareCacheOption;
92
95
  /** Pool configuration. Use preset name, size config, or false to disable. */
93
96
  pool?: DuckDBPoolConfig | PoolPreset | false;
@@ -165,6 +168,7 @@ function createFromClient<
165
168
  const driver = new DuckDBDriver(finalClient, dialect, {
166
169
  logger,
167
170
  rejectStringArrayLiterals: config.rejectStringArrayLiterals,
171
+ arrayLiteralWarning: config.arrayLiteralWarning,
168
172
  prepareCache,
169
173
  });
170
174
  const session = driver.createSession(schema);
package/src/session.ts CHANGED
@@ -186,6 +186,7 @@ export class DuckDBPreparedQuery<
186
186
  export interface DuckDBSessionOptions {
187
187
  logger?: Logger;
188
188
  rejectStringArrayLiterals?: boolean;
189
+ arrayLiteralWarning?: (query: string) => void;
189
190
  prepareCache?: PreparedStatementCacheConfig;
190
191
  }
191
192
 
@@ -314,6 +315,10 @@ export class DuckDBSession<
314
315
  return;
315
316
  }
316
317
  this.hasWarnedArrayLiteral = true;
318
+ if (this.options.arrayLiteralWarning) {
319
+ this.options.arrayLiteralWarning(query);
320
+ return;
321
+ }
317
322
  this.logger.logQuery(
318
323
  `[duckdb] ${arrayLiteralWarning}\nquery: ${query}`,
319
324
  []
@@ -393,6 +398,19 @@ export class DuckDBTransaction<
393
398
  > extends PgTransaction<DuckDBQueryResultHKT, TFullSchema, TSchema> {
394
399
  static readonly [entityKind]: string = 'DuckDBTransaction';
395
400
 
401
+ private getInternals(): DuckDBTransactionWithInternals<TFullSchema, TSchema> {
402
+ // PgTransaction keeps dialect/session private, but DuckDB transaction
403
+ // helpers need the session for DuckDB-specific execution paths.
404
+ return this as unknown as DuckDBTransactionWithInternals<
405
+ TFullSchema,
406
+ TSchema
407
+ >;
408
+ }
409
+
410
+ private markRollbackOnly(): void {
411
+ this.getInternals().session.markRollbackOnly();
412
+ }
413
+
396
414
  rollback(): never {
397
415
  throw new TransactionRollbackError();
398
416
  }
@@ -445,9 +463,7 @@ export class DuckDBTransaction<
445
463
  }
446
464
 
447
465
  setTransaction(config: PgTransactionConfig): Promise<void> {
448
- // Cast needed: PgTransaction doesn't expose dialect/session properties in public API
449
- type Tx = DuckDBTransactionWithInternals<TFullSchema, TSchema>;
450
- return (this as unknown as Tx).session.execute(
466
+ return this.getInternals().session.execute(
451
467
  sql`set transaction ${this.getTransactionConfigSQL(config)}`
452
468
  );
453
469
  }
@@ -456,32 +472,24 @@ export class DuckDBTransaction<
456
472
  query: SQL,
457
473
  options: ExecuteInBatchesOptions = {}
458
474
  ): AsyncGenerator<GenericRowData<T>[], void, void> {
459
- // Cast needed: PgTransaction doesn't expose session property in public API
460
- type Tx = DuckDBTransactionWithInternals<TFullSchema, TSchema>;
461
- return (this as unknown as Tx).session.executeBatches<T>(query, options);
475
+ return this.getInternals().session.executeBatches<T>(query, options);
462
476
  }
463
477
 
464
478
  executeBatchesRaw(
465
479
  query: SQL,
466
480
  options: ExecuteInBatchesOptions = {}
467
481
  ): AsyncGenerator<ExecuteBatchesRawChunk, void, void> {
468
- // Cast needed: PgTransaction doesn't expose session property in public API
469
- type Tx = DuckDBTransactionWithInternals<TFullSchema, TSchema>;
470
- return (this as unknown as Tx).session.executeBatchesRaw(query, options);
482
+ return this.getInternals().session.executeBatchesRaw(query, options);
471
483
  }
472
484
 
473
485
  executeArrow(query: SQL): Promise<unknown> {
474
- // Cast needed: PgTransaction doesn't expose session property in public API
475
- type Tx = DuckDBTransactionWithInternals<TFullSchema, TSchema>;
476
- return (this as unknown as Tx).session.executeArrow(query);
486
+ return this.getInternals().session.executeArrow(query);
477
487
  }
478
488
 
479
489
  override async transaction<T>(
480
490
  transaction: (tx: DuckDBTransaction<TFullSchema, TSchema>) => Promise<T>
481
491
  ): Promise<T> {
482
- // Cast needed: PgTransaction doesn't expose dialect/session properties in public API
483
- type Tx = DuckDBTransactionWithInternals<TFullSchema, TSchema>;
484
- const internals = this as unknown as Tx;
492
+ const internals = this.getInternals();
485
493
  const savepoint = `drizzle_savepoint_${this.nestedIndex + 1}`;
486
494
  const savepointSql = sql.raw(`savepoint ${savepoint}`);
487
495
  const releaseSql = sql.raw(`release savepoint ${savepoint}`);
@@ -496,7 +504,7 @@ export class DuckDBTransaction<
496
504
 
497
505
  // Check dialect-level savepoint support (per-instance, not global)
498
506
  if (internals.dialect.areSavepointsUnsupported()) {
499
- return this.runNestedWithoutSavepoint(transaction, nestedTx, internals);
507
+ return this.runNestedWithoutSavepoint(transaction, nestedTx);
500
508
  }
501
509
 
502
510
  let createdSavepoint = false;
@@ -509,7 +517,7 @@ export class DuckDBTransaction<
509
517
  throw error;
510
518
  }
511
519
  internals.dialect.markSavepointsUnsupported();
512
- return this.runNestedWithoutSavepoint(transaction, nestedTx, internals);
520
+ return this.runNestedWithoutSavepoint(transaction, nestedTx);
513
521
  }
514
522
 
515
523
  try {
@@ -522,22 +530,17 @@ export class DuckDBTransaction<
522
530
  if (createdSavepoint) {
523
531
  await internals.session.execute(rollbackSql);
524
532
  }
525
- (
526
- internals.session as DuckDBSession<TFullSchema, TSchema>
527
- ).markRollbackOnly();
533
+ this.markRollbackOnly();
528
534
  throw error;
529
535
  }
530
536
  }
531
537
 
532
538
  private runNestedWithoutSavepoint<T>(
533
539
  transaction: (tx: DuckDBTransaction<TFullSchema, TSchema>) => Promise<T>,
534
- nestedTx: DuckDBTransaction<TFullSchema, TSchema>,
535
- internals: DuckDBTransactionWithInternals<TFullSchema, TSchema>
540
+ nestedTx: DuckDBTransaction<TFullSchema, TSchema>
536
541
  ): Promise<T> {
537
542
  return transaction(nestedTx).catch((error) => {
538
- (
539
- internals.session as DuckDBSession<TFullSchema, TSchema>
540
- ).markRollbackOnly();
543
+ this.markRollbackOnly();
541
544
  throw error;
542
545
  });
543
546
  }