@leonardovida-md/drizzle-neo-duckdb 2.2.0 → 2.6.0

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.
@@ -157,7 +157,8 @@ export type MotherDuckFlightGranteeRow = {
157
157
  export type MotherDuckFlightMetadata = {
158
158
  /**
159
159
  * A chart of the Flight, such as Mermaid flowchart source. On update, an
160
- * empty string clears the chart and NULL leaves it unchanged.
160
+ * empty string clears the chart and NULL leaves it unchanged. An update
161
+ * needs another field when the chart is NULL.
161
162
  */
162
163
  chart?: string | null;
163
164
  };
@@ -307,7 +308,11 @@ export interface MotherDuckUpdateFlightOptions {
307
308
  maxRuntimeSec?: number | SQLWrapper;
308
309
  /** A different size creates a new Flight version. */
309
310
  instanceType?: MotherDuckFlightInstanceType | SQLWrapper;
310
- /** Keys left out or set to NULL keep their current value. */
311
+ /**
312
+ * Keys left out or set to NULL keep their current value. Metadata that
313
+ * changes nothing does not count as an update, so MotherDuck rejects a call
314
+ * whose only field is `{}` or `{ chart: null }`.
315
+ */
311
316
  metadata?: MotherDuckFlightMetadata | SQLWrapper | null;
312
317
  }
313
318
  export interface MotherDuckRunFlightOptions {
@@ -342,7 +347,7 @@ export interface MotherDuckTableFunctionOptions {
342
347
  mdRun?: MotherDuckRunMode;
343
348
  named?: Record<string, MotherDuckSqlArgument | undefined>;
344
349
  }
345
- declare const motherDuckTableFunctionNameList: readonly ["read_parquet", "parquet_scan", "parquet_schema", "parquet_metadata", "parquet_file_metadata", "parquet_kv_metadata", "parquet_bloom_probe", "parquet_full_metadata", "read_csv", "read_csv_auto", "sniff_csv", "read_json", "read_json_auto", "read_ndjson", "read_ndjson_auto", "read_json_objects", "read_json_objects_auto", "read_ndjson_objects", "read_text", "read_blob", "read_duckdb", "read_avro", "glob", "dbgen", "dsdgen", "delta_scan", "delta_list_files", "iceberg_snapshots", "iceberg_metadata", "iceberg_scan", "iceberg_partition_stats", "iceberg_column_stats", "st_read", "st_readosm", "ducklake_snapshots", "ducklake_list_files", "ducklake_table_info", "ducklake_table_insertions", "ducklake_table_deletions", "ducklake_current_snapshot", "ducklake_last_committed_snapshot", "ducklake_merge_adjacent_files", "ducklake_cleanup_old_files", "ducklake_expire_snapshots", "ducklake_set_option", "ducklake_options", "ducklake_add_data_files", "ducklake_delete_orphaned_files", "ducklake_set_commit_message", "ducklake_rewrite_data_files", "ducklake_flush_inlined_data", "ducklake_settings"];
350
+ declare const motherDuckTableFunctionNameList: readonly ['read_parquet', 'parquet_scan', 'parquet_schema', 'parquet_metadata', 'parquet_file_metadata', 'parquet_kv_metadata', 'parquet_bloom_probe', 'parquet_full_metadata', 'read_csv', 'read_csv_auto', 'sniff_csv', 'read_json', 'read_json_auto', 'read_ndjson', 'read_ndjson_auto', 'read_json_objects', 'read_json_objects_auto', 'read_ndjson_objects', 'read_text', 'read_blob', 'read_duckdb', 'read_avro', 'glob', 'dbgen', 'dsdgen', 'delta_scan', 'delta_list_files', 'iceberg_snapshots', 'iceberg_metadata', 'iceberg_scan', 'iceberg_partition_stats', 'iceberg_column_stats', 'st_read', 'st_readosm', 'ducklake_snapshots', 'ducklake_list_files', 'ducklake_table_info', 'ducklake_table_insertions', 'ducklake_table_deletions', 'ducklake_current_snapshot', 'ducklake_last_committed_snapshot', 'ducklake_merge_adjacent_files', 'ducklake_cleanup_old_files', 'ducklake_expire_snapshots', 'ducklake_set_option', 'ducklake_options', 'ducklake_add_data_files', 'ducklake_delete_orphaned_files', 'ducklake_set_commit_message', 'ducklake_rewrite_data_files', 'ducklake_flush_inlined_data', 'ducklake_settings'];
346
351
  export type MotherDuckTableFunction = (typeof motherDuckTableFunctionNameList)[number];
347
352
  export declare function mdAccessTokens(options?: MotherDuckAccessTokenOptions): SQL;
348
353
  /** List one level of an `s3://` or `azure://` path with MotherDuck secrets. */
@@ -26,7 +26,10 @@ export declare class PreparedStatementCache {
26
26
  }
27
27
  export declare function getPreparedStatementCache(connection: DuckDBConnection, size: number): PreparedStatementCache;
28
28
  export declare function clearPreparedStatementCache(connection: DuckDBConnection): void;
29
- /** Read cache counters without creating or resizing the native cache. */
29
+ /**
30
+ * @deprecated The driver no longer caches prepared statements, so this
31
+ * returns undefined. It will be removed in the next major version.
32
+ */
30
33
  export declare function getPreparedStatementCacheStats(connection: DuckDBConnection): {
31
34
  size: number;
32
35
  capacity: number;
package/dist/session.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { entityKind } from 'drizzle-orm/entity';
2
2
  import type { Logger } from 'drizzle-orm/logger';
3
3
  import { PgTransaction } from 'drizzle-orm/pg-core';
4
- import type { PgColumn } from 'drizzle-orm/pg-core';
4
+ import type { PgColumn, PgTable } from 'drizzle-orm/pg-core';
5
5
  import type { PgSelectBuilder, SelectedFields } from 'drizzle-orm/pg-core/query-builders';
6
6
  import type { SelectedFieldsOrdered } from 'drizzle-orm/pg-core/query-builders/select.types';
7
7
  import type { PgTransactionConfig, PreparedQueryConfig, PgQueryResultHKT } from 'drizzle-orm/pg-core/session';
@@ -10,9 +10,10 @@ import type { RelationalSchemaConfig, TablesRelationalConfig } from 'drizzle-orm
10
10
  import { type Query, SQL, type SQLWrapper } from 'drizzle-orm/sql/sql';
11
11
  import type { WithSubquery } from 'drizzle-orm/subquery';
12
12
  import type { Assume } from 'drizzle-orm/utils';
13
+ import { type RelationalSelectionItem } from './sql/result-mapper.ts';
13
14
  import type { DuckDBDialect } from './dialect.ts';
14
15
  import type { DuckDBClientLike, RowData } from './client.ts';
15
- import { type ExecuteBatchesRawChunk, type ExecuteInBatchesOptions } from './client.ts';
16
+ import { type DateParamType, type ExecuteBatchesRawChunk, type ExecuteInBatchesOptions } from './client.ts';
16
17
  import type { PreparedStatementCacheConfig } from './options.ts';
17
18
  import { type DuckDBSelectBuilder } from './select-builder.ts';
18
19
  export type { DuckDBClientLike, RowData } from './client.ts';
@@ -42,9 +43,12 @@ export declare class DuckDBPreparedQuery<T extends PreparedQueryConfig> extends
42
43
  private onStatementError?;
43
44
  private decimalMode;
44
45
  private waitForTransactions;
46
+ private relationalSelection?;
47
+ private dateParams?;
45
48
  static readonly [entityKind]: string;
46
49
  private resultMapper?;
47
- constructor(client: DuckDBClientLike, dialect: DuckDBDialect, queryString: string, params: unknown[], logger: Logger, fields: SelectedFieldsOrdered | undefined, _isResponseInArrayMode: boolean, customResultMapper: ((rows: unknown[][]) => T['execute']) | undefined, rejectStringArrayLiterals: boolean, prepareCache: PreparedStatementCacheConfig | undefined, queryMetadata?: QueryMetadata, cacheConfig?: CacheConfig, warnOnStringArrayLiteral?: ((sql: string) => void) | undefined, scalarParamIndexes?: ReadonlySet<number> | undefined, onStatementError?: ((error: unknown) => void) | undefined, decimalMode?: 'number' | 'string', waitForTransactions?: boolean);
50
+ private relationalRowNormalizer?;
51
+ constructor(client: DuckDBClientLike, dialect: DuckDBDialect, queryString: string, params: unknown[], logger: Logger, fields: SelectedFieldsOrdered | undefined, _isResponseInArrayMode: boolean, customResultMapper: ((rows: unknown[][]) => T['execute']) | undefined, rejectStringArrayLiterals: boolean, prepareCache: PreparedStatementCacheConfig | undefined, queryMetadata?: QueryMetadata, cacheConfig?: CacheConfig, warnOnStringArrayLiteral?: ((sql: string) => void) | undefined, scalarParamIndexes?: ReadonlySet<number> | undefined, onStatementError?: ((error: unknown) => void) | undefined, decimalMode?: 'number' | 'string', waitForTransactions?: boolean, relationalSelection?: readonly RelationalSelectionItem[] | undefined, dateParams?: DateParamType | undefined);
48
52
  execute(placeholderValues?: Record<string, unknown> | undefined): Promise<T['execute']>;
49
53
  private executeQuery;
50
54
  all(placeholderValues?: Record<string, unknown> | undefined): Promise<T['all']>;
@@ -52,6 +56,7 @@ export declare class DuckDBPreparedQuery<T extends PreparedQueryConfig> extends
52
56
  }
53
57
  export interface DuckDBSessionOptions {
54
58
  decimalMode?: 'number' | 'string';
59
+ dateParams?: DateParamType;
55
60
  logger?: Logger;
56
61
  rejectStringArrayLiterals?: boolean;
57
62
  arrayLiteralWarning?: (query: string) => void;
@@ -104,6 +109,11 @@ export declare class DuckDBSession<TFullSchema extends Record<string, unknown> =
104
109
  executeBatches<T extends RowData = RowData>(query: SQL, options?: ExecuteInBatchesOptions): AsyncGenerator<GenericRowData<T>[], void, void>;
105
110
  executeBatchesRaw(query: SQL, options?: ExecuteInBatchesOptions): AsyncGenerator<ExecuteBatchesRawChunk, void, void>;
106
111
  executeArrow(query: SQL): Promise<unknown>;
112
+ /**
113
+ * Append rows with DuckDB's appender, which is much faster than a
114
+ * multi-row INSERT. Returns the number of rows appended.
115
+ */
116
+ appendRows(table: PgTable, rows: readonly Record<string, unknown>[]): Promise<number>;
107
117
  markRollbackOnly(cause?: unknown): void;
108
118
  isRollbackOnly(): boolean;
109
119
  }
@@ -135,6 +145,8 @@ export declare class DuckDBTransaction<TFullSchema extends Record<string, unknow
135
145
  executeBatches<T extends RowData = RowData>(query: SQL, options?: ExecuteInBatchesOptions): AsyncGenerator<GenericRowData<T>[], void, void>;
136
146
  executeBatchesRaw(query: SQL, options?: ExecuteInBatchesOptions): AsyncGenerator<ExecuteBatchesRawChunk, void, void>;
137
147
  executeArrow(query: SQL): Promise<unknown>;
148
+ /** Append rows inside this transaction. See `db.appendRows()`. */
149
+ appendRows<TTable extends PgTable>(table: TTable, rows: readonly TTable['$inferInsert'][]): Promise<number>;
138
150
  transaction<T>(transaction: (tx: DuckDBTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T>;
139
151
  private runNestedWithoutSavepoint;
140
152
  }
@@ -11,7 +11,24 @@ export declare function normalizeTimestamp(value: unknown, withTimezone: boolean
11
11
  export declare function normalizeDateString(value: unknown): string | unknown;
12
12
  export declare function normalizeDateValue(value: unknown): Date | unknown;
13
13
  export declare function normalizeTime(value: unknown): string | unknown;
14
+ /**
15
+ * DuckDB returns INTERVAL values as `{ months, days, micros }`. Format them
16
+ * the way DuckDB casts an INTERVAL to VARCHAR, for example
17
+ * `1 year 2 months 3 days 04:05:06`, which DuckDB and Postgres parse back.
18
+ */
14
19
  export declare function normalizeInterval(value: unknown): string | unknown;
20
+ /**
21
+ * Normalize the top-level values of relational query rows (`db.query`) in
22
+ * place. Drizzle decodes them afterwards with each field's decoder, so they
23
+ * must arrive the way flat selects see them. JSON relation fields are left
24
+ * alone.
25
+ */
26
+ export declare function compileRelationalRowNormalizer(selection: readonly RelationalSelectionItem[]): (row: unknown[]) => void;
27
+ /** The part of Drizzle's relational query selection the driver reads. */
28
+ export interface RelationalSelectionItem {
29
+ isJson: boolean;
30
+ field: unknown;
31
+ }
15
32
  export declare function mapResultRow<TResult>(columns: SelectedFieldsOrdered<AnyColumn>, row: unknown[], joinsNotNullableMap: Record<string, boolean> | undefined): TResult;
16
33
  /** Resolve stable field metadata once, before mapping any result rows. */
17
34
  export declare function compileResultMapper<TResult>(columns: SelectedFieldsOrdered<AnyColumn>, joinsNotNullableMap?: Record<string, boolean>): (row: unknown[]) => TResult;
package/dist/time.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ export declare function rememberDroppedMicros(date: Date, micros: number): void;
2
+ /** Microseconds below the Date's millisecond, as read from DuckDB. */
3
+ export declare function dateSubMillisecondMicros(date: Date): number;
4
+ /** Microseconds since the Unix epoch, including digits a Date drops. */
5
+ export declare function dateToMicros(date: Date): bigint;
1
6
  /**
2
7
  * Format bigint TIME microseconds as HH:MM:SS.mmm, adding the microsecond
3
8
  * digits only when the value has sub-millisecond precision.
package/package.json CHANGED
@@ -2,15 +2,17 @@
2
2
  "name": "@leonardovida-md/drizzle-neo-duckdb",
3
3
  "main": "./dist/index.mjs",
4
4
  "types": "./dist/index.d.ts",
5
- "version": "2.2.0",
5
+ "version": "2.6.0",
6
6
  "description": "A drizzle ORM client for use with DuckDB. Based on drizzle's Postgres client.",
7
7
  "type": "module",
8
8
  "scripts": {
9
9
  "build": "bun build --target=node ./src/index.ts --outfile=./dist/index.mjs --packages=external && bun build --target=node ./src/helpers.ts --outfile=./dist/helpers.mjs --packages=external && bun build --target=node ./src/bin/duckdb-introspect.ts --outfile=./dist/duckdb-introspect.mjs --packages=external && bun run build:declarations",
10
10
  "build:declarations": "bun x tsc --emitDeclarationOnly --project tsconfig.types.json",
11
11
  "test": "bun x vitest run",
12
+ "test:coverage": "bun x vitest run --coverage",
12
13
  "typecheck": "bun x tsc --noEmit --project tsconfig.check.json && bun x tsc --noEmit --project tsconfig.workspace.json",
13
14
  "check:package": "bun run scripts/check-package.ts",
15
+ "check:peer-range": "bun run scripts/check-peer-range.ts",
14
16
  "t": "bun x vitest --watch --ui",
15
17
  "bench": "bun x vitest bench --run test/perf --pool=threads --maxWorkers=1 --no-file-parallelism",
16
18
  "perf:run": "bun run scripts/run-perf.ts",
@@ -24,15 +26,18 @@
24
26
  "drizzle-orm": ">=0.40.1 <0.46.0"
25
27
  },
26
28
  "devDependencies": {
27
- "@duckdb/node-api": "1.5.6-r.1",
29
+ "@duckdb/node-api": "1.5.6-r.2",
28
30
  "@types/bun": "1.4.0",
29
31
  "@types/node": "26.4.1",
30
- "@vitest/ui": "4.1.11",
31
- "drizzle-orm": "0.45.2",
32
+ "@types/semver": "7.8.0",
33
+ "@vitest/coverage-v8": "4.1.12",
34
+ "@vitest/ui": "4.1.12",
35
+ "drizzle-orm": "0.45.4",
32
36
  "prettier": "3.8.4",
33
- "typescript": "6.0.3",
37
+ "semver": "7.8.6",
38
+ "typescript": "7.0.2",
34
39
  "uuid": "14.0.2",
35
- "vitest": "4.1.11"
40
+ "vitest": "4.1.12"
36
41
  },
37
42
  "repository": {
38
43
  "type": "git",
@@ -59,10 +64,18 @@
59
64
  "engines": {
60
65
  "node": ">=18.17"
61
66
  },
62
- "packageManager": "bun@1.3.9",
67
+ "packageManager": "bun@1.4.4",
63
68
  "keywords": [
64
69
  "drizzle",
65
- "duckdb"
70
+ "drizzle-orm",
71
+ "duckdb",
72
+ "motherduck",
73
+ "ducklake",
74
+ "orm",
75
+ "sql",
76
+ "typescript",
77
+ "analytics",
78
+ "olap"
66
79
  ],
67
80
  "author": "M L",
68
81
  "license": "Apache-2.0",