@leonardovida-md/drizzle-neo-duckdb 2.3.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.
- package/README.md +6 -5
- package/dist/client.d.ts +29 -1
- package/dist/columns.d.ts +32 -32
- package/dist/driver.d.ts +27 -2
- package/dist/duckdb-introspect.mjs +276 -197
- package/dist/helpers.mjs +16 -16
- package/dist/index.mjs +415 -339
- package/dist/motherduck.d.ts +8 -3
- package/dist/prepared-statement-cache.d.ts +4 -1
- package/dist/session.d.ts +12 -3
- package/package.json +21 -8
package/dist/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
13
13
|
import { entityKind as entityKind3, is as is4 } from "drizzle-orm/entity";
|
|
14
14
|
import { NoopLogger } from "drizzle-orm/logger";
|
|
15
|
-
import { PgArray as PgArray2, PgTransaction } from "drizzle-orm/pg-core";
|
|
15
|
+
import { getTableConfig, PgArray as PgArray2, PgTransaction } from "drizzle-orm/pg-core";
|
|
16
16
|
import { PgPreparedQuery, PgSession } from "drizzle-orm/pg-core/session";
|
|
17
17
|
import {
|
|
18
18
|
fillPlaceholders,
|
|
@@ -103,7 +103,7 @@ function arrayBoundsSql(name, arr) {
|
|
|
103
103
|
if (name === "array_lower") {
|
|
104
104
|
return `CASE WHEN array_length(${arr}) > 0 THEN 1 ELSE NULL END`;
|
|
105
105
|
}
|
|
106
|
-
return arr.includes("(") ? `list_extract(list_transform(list_value(array_length(${arr})), __drizzle_array_length
|
|
106
|
+
return arr.includes("(") ? `list_extract(list_transform(list_value(array_length(${arr})), lambda __drizzle_array_length: nullif(__drizzle_array_length, 0)), 1)` : `nullif(array_length(${arr}), 0)`;
|
|
107
107
|
}
|
|
108
108
|
function rewriteArrayBoundsText(query) {
|
|
109
109
|
let output = "";
|
|
@@ -407,8 +407,8 @@ function normalizeInet(value) {
|
|
|
407
407
|
if (address < 0n || address > 0xffffffffn) {
|
|
408
408
|
return value;
|
|
409
409
|
}
|
|
410
|
-
const
|
|
411
|
-
return `${formatIpv4(address)}${
|
|
410
|
+
const suffix = value.mask !== 32 ? `/${value.mask}` : "";
|
|
411
|
+
return `${formatIpv4(address)}${suffix}`;
|
|
412
412
|
}
|
|
413
413
|
const unsigned = address + (1n << 127n);
|
|
414
414
|
if (unsigned < 0n || unsigned >= 1n << 128n) {
|
|
@@ -454,10 +454,10 @@ function normalizeTimestamp(value, withTimezone) {
|
|
|
454
454
|
}
|
|
455
455
|
function normalizeDateString(value) {
|
|
456
456
|
if (value instanceof Date) {
|
|
457
|
-
return value
|
|
457
|
+
return dateStringFromDate(value);
|
|
458
458
|
}
|
|
459
459
|
if (typeof value === "string") {
|
|
460
|
-
return value.slice(0, 10);
|
|
460
|
+
return value === "infinity" || value === "-infinity" ? value : value.slice(0, 10);
|
|
461
461
|
}
|
|
462
462
|
return value;
|
|
463
463
|
}
|
|
@@ -465,6 +465,9 @@ function normalizeDateValue(value) {
|
|
|
465
465
|
if (value instanceof Date) {
|
|
466
466
|
return value;
|
|
467
467
|
}
|
|
468
|
+
if (isInfiniteTimestamp(value)) {
|
|
469
|
+
return value;
|
|
470
|
+
}
|
|
468
471
|
if (typeof value === "string") {
|
|
469
472
|
return new Date(`${value.slice(0, 10)}T00:00:00Z`);
|
|
470
473
|
}
|
|
@@ -515,7 +518,7 @@ function compileValueNormalizer(decoder) {
|
|
|
515
518
|
}
|
|
516
519
|
function compileValueMapper(decoder) {
|
|
517
520
|
const normalize = compileValueNormalizer(decoder);
|
|
518
|
-
if (is(decoder, PgTimestamp)) {
|
|
521
|
+
if (is(decoder, PgTimestamp) || is(decoder, PgDate)) {
|
|
519
522
|
return (value) => {
|
|
520
523
|
const normalized = normalize(value);
|
|
521
524
|
return normalized === null || normalized instanceof Date || isInfiniteTimestamp(normalized) ? normalized : decoder.mapFromDriverValue(toDecoderInput(decoder, normalized));
|
|
@@ -681,8 +684,17 @@ function arrayBoundsExpr(functionName, arrayExpr) {
|
|
|
681
684
|
call("list_value", [lengthExpr]),
|
|
682
685
|
{
|
|
683
686
|
type: "binary_expr",
|
|
684
|
-
operator: "
|
|
685
|
-
left:
|
|
687
|
+
operator: ":",
|
|
688
|
+
left: {
|
|
689
|
+
type: "column_ref",
|
|
690
|
+
table: null,
|
|
691
|
+
column: {
|
|
692
|
+
expr: {
|
|
693
|
+
type: "default",
|
|
694
|
+
value: "lambda __drizzle_array_length"
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
},
|
|
686
698
|
right: nullIf(length)
|
|
687
699
|
}
|
|
688
700
|
]),
|
|
@@ -1621,20 +1633,20 @@ function scanSqlTokens(query) {
|
|
|
1621
1633
|
};
|
|
1622
1634
|
const readQuoted = (start, quote) => {
|
|
1623
1635
|
const backslashEscapes = isEscapeStringAt(query, start);
|
|
1624
|
-
let
|
|
1625
|
-
while (
|
|
1626
|
-
if (backslashEscapes && query[
|
|
1627
|
-
|
|
1636
|
+
let index = start + 1;
|
|
1637
|
+
while (index < query.length) {
|
|
1638
|
+
if (backslashEscapes && query[index] === "\\") {
|
|
1639
|
+
index += 2;
|
|
1628
1640
|
continue;
|
|
1629
1641
|
}
|
|
1630
|
-
if (query[
|
|
1631
|
-
if (query[
|
|
1632
|
-
|
|
1642
|
+
if (query[index] === quote) {
|
|
1643
|
+
if (query[index + 1] === quote) {
|
|
1644
|
+
index += 2;
|
|
1633
1645
|
continue;
|
|
1634
1646
|
}
|
|
1635
|
-
return
|
|
1647
|
+
return index;
|
|
1636
1648
|
}
|
|
1637
|
-
|
|
1649
|
+
index += 1;
|
|
1638
1650
|
}
|
|
1639
1651
|
return -1;
|
|
1640
1652
|
};
|
|
@@ -1786,8 +1798,8 @@ function transformSQL(query, options = {}) {
|
|
|
1786
1798
|
function rewriteRemainingArrayBounds(result) {
|
|
1787
1799
|
if (!ARRAY_BOUNDS_PATTERN.test(result.sql))
|
|
1788
1800
|
return result;
|
|
1789
|
-
const
|
|
1790
|
-
return
|
|
1801
|
+
const sql = rewriteArrayBoundsText(result.sql);
|
|
1802
|
+
return sql === result.sql ? result : { sql, transformed: true };
|
|
1791
1803
|
}
|
|
1792
1804
|
function transformWithAst(query, {
|
|
1793
1805
|
needsArrayTransform,
|
|
@@ -1889,6 +1901,7 @@ var RELATIONAL_JSON_CHUNKS = new Map([
|
|
|
1889
1901
|
["), '[]'::json)", ")), '[]'::json)"]
|
|
1890
1902
|
]);
|
|
1891
1903
|
var RELATIONAL_LIMIT_CHUNKS = new Set([" limit ", " offset "]);
|
|
1904
|
+
var EXACT_BIGINT_COLUMN_TYPES = new Set(["PgBigInt64", "PgBigSerial64"]);
|
|
1892
1905
|
function rewriteRelationalJsonChunks(chunks, exactDecimals = false) {
|
|
1893
1906
|
for (let index = 0;index < chunks.length; index += 1) {
|
|
1894
1907
|
const chunk = chunks[index];
|
|
@@ -1899,7 +1912,13 @@ function rewriteRelationalJsonChunks(chunks, exactDecimals = false) {
|
|
|
1899
1912
|
if (replacement) {
|
|
1900
1913
|
if (value === "json_build_array(" && is2(next, SQL2)) {
|
|
1901
1914
|
const fields = next.queryChunks.map((item) => {
|
|
1902
|
-
if (!is2(item, Column2)
|
|
1915
|
+
if (!is2(item, Column2)) {
|
|
1916
|
+
return item;
|
|
1917
|
+
}
|
|
1918
|
+
if (EXACT_BIGINT_COLUMN_TYPES.has(item.columnType)) {
|
|
1919
|
+
return sql2`cast(${item} as VARCHAR)`;
|
|
1920
|
+
}
|
|
1921
|
+
if (!exactDecimals && !item.columnType.startsWith("PgNumeric")) {
|
|
1903
1922
|
return item;
|
|
1904
1923
|
}
|
|
1905
1924
|
const originalType = item.getSQLType();
|
|
@@ -2086,6 +2105,7 @@ import {
|
|
|
2086
2105
|
JSDuckDBValueConverter,
|
|
2087
2106
|
JsonDuckDBValueConverter,
|
|
2088
2107
|
listValue as listValue2,
|
|
2108
|
+
TIMESTAMPTZ as TIMESTAMPTZ2,
|
|
2089
2109
|
timestampTZValue as timestampTZValue2,
|
|
2090
2110
|
timestampValue as timestampValue2
|
|
2091
2111
|
} from "@duckdb/node-api";
|
|
@@ -2667,105 +2687,6 @@ function parsePgArrayLiteral(value) {
|
|
|
2667
2687
|
|
|
2668
2688
|
// src/prepared-statement-cache.ts
|
|
2669
2689
|
var PREPARED_CACHE = Symbol.for("drizzle-duckdb:prepared-cache");
|
|
2670
|
-
function destroyPreparedStatement(entry) {
|
|
2671
|
-
if (!entry)
|
|
2672
|
-
return;
|
|
2673
|
-
try {
|
|
2674
|
-
entry.statement.destroySync();
|
|
2675
|
-
} catch {}
|
|
2676
|
-
}
|
|
2677
|
-
|
|
2678
|
-
class PreparedStatementCache {
|
|
2679
|
-
connection;
|
|
2680
|
-
size;
|
|
2681
|
-
entries = new Map;
|
|
2682
|
-
executionTail = Promise.resolve();
|
|
2683
|
-
hits = 0;
|
|
2684
|
-
misses = 0;
|
|
2685
|
-
evictions = 0;
|
|
2686
|
-
stats() {
|
|
2687
|
-
return {
|
|
2688
|
-
size: this.entries.size,
|
|
2689
|
-
capacity: this.size,
|
|
2690
|
-
hits: this.hits,
|
|
2691
|
-
misses: this.misses,
|
|
2692
|
-
evictions: this.evictions
|
|
2693
|
-
};
|
|
2694
|
-
}
|
|
2695
|
-
constructor(connection, size) {
|
|
2696
|
-
this.connection = connection;
|
|
2697
|
-
this.size = size;
|
|
2698
|
-
}
|
|
2699
|
-
resize(size) {
|
|
2700
|
-
this.size = size;
|
|
2701
|
-
this.trimToSize();
|
|
2702
|
-
}
|
|
2703
|
-
async getOrPrepare(query) {
|
|
2704
|
-
const cached = this.entries.get(query);
|
|
2705
|
-
if (cached) {
|
|
2706
|
-
this.hits += 1;
|
|
2707
|
-
return this.remember(query, cached.statement);
|
|
2708
|
-
}
|
|
2709
|
-
this.misses += 1;
|
|
2710
|
-
const statement = await this.connection.prepare(query);
|
|
2711
|
-
this.remember(query, statement);
|
|
2712
|
-
return statement;
|
|
2713
|
-
}
|
|
2714
|
-
async runExclusive(operation) {
|
|
2715
|
-
const previous = this.executionTail;
|
|
2716
|
-
let release = () => {};
|
|
2717
|
-
this.executionTail = new Promise((resolve) => {
|
|
2718
|
-
release = resolve;
|
|
2719
|
-
});
|
|
2720
|
-
await previous;
|
|
2721
|
-
try {
|
|
2722
|
-
return await operation();
|
|
2723
|
-
} finally {
|
|
2724
|
-
release();
|
|
2725
|
-
}
|
|
2726
|
-
}
|
|
2727
|
-
remember(query, statement) {
|
|
2728
|
-
this.entries.delete(query);
|
|
2729
|
-
this.entries.set(query, { statement });
|
|
2730
|
-
this.trimToSize();
|
|
2731
|
-
return statement;
|
|
2732
|
-
}
|
|
2733
|
-
evict(query) {
|
|
2734
|
-
const entry = this.entries.get(query);
|
|
2735
|
-
if (entry)
|
|
2736
|
-
this.evictions += 1;
|
|
2737
|
-
this.entries.delete(query);
|
|
2738
|
-
destroyPreparedStatement(entry);
|
|
2739
|
-
}
|
|
2740
|
-
clear() {
|
|
2741
|
-
for (const entry of this.entries.values()) {
|
|
2742
|
-
destroyPreparedStatement(entry);
|
|
2743
|
-
}
|
|
2744
|
-
this.entries.clear();
|
|
2745
|
-
}
|
|
2746
|
-
evictOldest() {
|
|
2747
|
-
const oldest = this.entries.keys().next();
|
|
2748
|
-
if (!oldest.done) {
|
|
2749
|
-
this.evict(oldest.value);
|
|
2750
|
-
}
|
|
2751
|
-
}
|
|
2752
|
-
trimToSize() {
|
|
2753
|
-
while (this.entries.size > this.size) {
|
|
2754
|
-
this.evictOldest();
|
|
2755
|
-
}
|
|
2756
|
-
}
|
|
2757
|
-
}
|
|
2758
|
-
function getPreparedStatementCache(connection, size) {
|
|
2759
|
-
const store = connection;
|
|
2760
|
-
const existing = store[PREPARED_CACHE];
|
|
2761
|
-
if (existing) {
|
|
2762
|
-
existing.resize(size);
|
|
2763
|
-
return existing;
|
|
2764
|
-
}
|
|
2765
|
-
const cache = new PreparedStatementCache(connection, size);
|
|
2766
|
-
store[PREPARED_CACHE] = cache;
|
|
2767
|
-
return cache;
|
|
2768
|
-
}
|
|
2769
2690
|
function clearPreparedStatementCache(connection) {
|
|
2770
2691
|
const store = connection;
|
|
2771
2692
|
store[PREPARED_CACHE]?.clear();
|
|
@@ -2774,17 +2695,6 @@ function getPreparedStatementCacheStats(connection) {
|
|
|
2774
2695
|
const store = connection;
|
|
2775
2696
|
return store[PREPARED_CACHE]?.stats();
|
|
2776
2697
|
}
|
|
2777
|
-
function bindPreparedStatement(statement, values, types) {
|
|
2778
|
-
if (values) {
|
|
2779
|
-
if (types) {
|
|
2780
|
-
statement.bind(values, types);
|
|
2781
|
-
} else {
|
|
2782
|
-
statement.bind(values);
|
|
2783
|
-
}
|
|
2784
|
-
return;
|
|
2785
|
-
}
|
|
2786
|
-
statement.clearBindings?.();
|
|
2787
|
-
}
|
|
2788
2698
|
|
|
2789
2699
|
// src/client.ts
|
|
2790
2700
|
function isPool(client) {
|
|
@@ -2950,14 +2860,16 @@ var NO_NODE_API_PARAMS = {
|
|
|
2950
2860
|
values: undefined,
|
|
2951
2861
|
types: undefined
|
|
2952
2862
|
};
|
|
2953
|
-
function toNodeApiParams(params) {
|
|
2863
|
+
function toNodeApiParams(params, dateParams) {
|
|
2954
2864
|
if (params.length === 0) {
|
|
2955
2865
|
return NO_NODE_API_PARAMS;
|
|
2956
2866
|
}
|
|
2867
|
+
const dateType = dateParams === "timestamptz" ? TIMESTAMPTZ2 : undefined;
|
|
2957
2868
|
const values = new Array(params.length);
|
|
2958
2869
|
let types;
|
|
2959
2870
|
for (let index = 0;index < params.length; index += 1) {
|
|
2960
|
-
const
|
|
2871
|
+
const param = params[index];
|
|
2872
|
+
const value = toNodeApiValue(param, dateType && param instanceof Date ? dateType : undefined);
|
|
2961
2873
|
values[index] = value;
|
|
2962
2874
|
if (value !== null && (typeof value === "object" || typeof value === "number" && Number.isInteger(value) && (value > 2147483647 || value < -2147483648))) {
|
|
2963
2875
|
const typed = typedNodeApiParam(value);
|
|
@@ -3100,11 +3012,22 @@ function wrapUnsupportedNodeApiTypeError(result, error) {
|
|
|
3100
3012
|
}
|
|
3101
3013
|
var TIMESTAMP_INFINITY_MICROS = 9223372036854775807n;
|
|
3102
3014
|
var MAX_DATE_MILLIS = 8640000000000000n;
|
|
3015
|
+
var MAX_SAFE_MICROS = BigInt(Number.MAX_SAFE_INTEGER);
|
|
3016
|
+
var DATE_INFINITY_DAYS = 2147483647;
|
|
3103
3017
|
function dateFromTimestampUnits(units, unitsPerMilli, typeName) {
|
|
3104
3018
|
if (units === TIMESTAMP_INFINITY_MICROS)
|
|
3105
3019
|
return "infinity";
|
|
3106
3020
|
if (units === -TIMESTAMP_INFINITY_MICROS)
|
|
3107
3021
|
return "-infinity";
|
|
3022
|
+
if (unitsPerMilli === 1000n && units >= -MAX_SAFE_MICROS && units <= MAX_SAFE_MICROS) {
|
|
3023
|
+
const micros = Number(units);
|
|
3024
|
+
const wholeMillis = Math.floor(micros / 1000);
|
|
3025
|
+
const date = new Date(wholeMillis);
|
|
3026
|
+
const dropped = micros - wholeMillis * 1000;
|
|
3027
|
+
if (dropped !== 0)
|
|
3028
|
+
rememberDroppedMicros(date, dropped);
|
|
3029
|
+
return date;
|
|
3030
|
+
}
|
|
3108
3031
|
let millis = units / unitsPerMilli;
|
|
3109
3032
|
if (units % unitsPerMilli < 0n)
|
|
3110
3033
|
millis -= 1n;
|
|
@@ -3127,13 +3050,20 @@ var JSValueConverter = (value, type, converter) => {
|
|
|
3127
3050
|
if (type.typeId === DuckDBTypeId2.TIMESTAMP_NS && "nanos" in value && typeof value.nanos === "bigint") {
|
|
3128
3051
|
return dateFromTimestampUnits(value.nanos, 1000000n, "TIMESTAMP_NS");
|
|
3129
3052
|
}
|
|
3053
|
+
if (type.typeId === DuckDBTypeId2.DATE && "days" in value) {
|
|
3054
|
+
if (value.days === DATE_INFINITY_DAYS)
|
|
3055
|
+
return "infinity";
|
|
3056
|
+
if (value.days === -DATE_INFINITY_DAYS)
|
|
3057
|
+
return "-infinity";
|
|
3058
|
+
}
|
|
3130
3059
|
}
|
|
3131
3060
|
return JSDuckDBValueConverter(value, type, converter);
|
|
3132
3061
|
};
|
|
3133
3062
|
var FLOORED_TIMESTAMP_TYPE_IDS = new Set([
|
|
3134
3063
|
DuckDBTypeId2.TIMESTAMP,
|
|
3135
3064
|
DuckDBTypeId2.TIMESTAMP_TZ,
|
|
3136
|
-
DuckDBTypeId2.TIMESTAMP_NS
|
|
3065
|
+
DuckDBTypeId2.TIMESTAMP_NS,
|
|
3066
|
+
DuckDBTypeId2.DATE
|
|
3137
3067
|
]);
|
|
3138
3068
|
function containsFlooredTimestamp(type) {
|
|
3139
3069
|
if (FLOORED_TIMESTAMP_TYPE_IDS.has(type.typeId))
|
|
@@ -3215,8 +3145,8 @@ function hasFetchAllChunks(result) {
|
|
|
3215
3145
|
async function materializeResultRows(result, exactDecimals = false, recursiveDecimals = false) {
|
|
3216
3146
|
if (hasFetchAllChunks(result)) {
|
|
3217
3147
|
const exactDecimalColumns = exactDecimals || recursiveDecimals ? findDecimalColumns(result) : [];
|
|
3218
|
-
const
|
|
3219
|
-
return exactDecimalColumns.length > 0 ? { columns: resolveResultColumns(result), rows
|
|
3148
|
+
const rows = await readResultChunkRows(result, exactDecimalColumns.length > 0, recursiveDecimals);
|
|
3149
|
+
return exactDecimalColumns.length > 0 ? { columns: resolveResultColumns(result), rows, exactDecimalColumns } : { columns: resolveResultColumns(result), rows };
|
|
3220
3150
|
}
|
|
3221
3151
|
const getRowsJson = typeof result.getRowsJson === "function" ? result.getRowsJson.bind(result) : undefined;
|
|
3222
3152
|
const rows = await readPreferredResult({
|
|
@@ -3227,36 +3157,6 @@ async function materializeResultRows(result, exactDecimals = false, recursiveDec
|
|
|
3227
3157
|
const columns = resolveResultColumns(result);
|
|
3228
3158
|
return { columns, rows };
|
|
3229
3159
|
}
|
|
3230
|
-
function isUnpreparableQueryError(error) {
|
|
3231
|
-
return error instanceof Error && /Cannot prepare multiple statements at once|No statement to prepare/.test(error.message);
|
|
3232
|
-
}
|
|
3233
|
-
async function executePreparedQuery(connection, query, { values, types }, cacheConfig, exactDecimals = false, recursiveDecimals = false) {
|
|
3234
|
-
const cache = getPreparedStatementCache(connection, cacheConfig.size);
|
|
3235
|
-
return await cache.runExclusive(async () => {
|
|
3236
|
-
assertConnectionAvailable(connection);
|
|
3237
|
-
let statement;
|
|
3238
|
-
try {
|
|
3239
|
-
statement = await cache.getOrPrepare(query);
|
|
3240
|
-
} catch (error) {
|
|
3241
|
-
if (!isUnpreparableQueryError(error)) {
|
|
3242
|
-
throw error;
|
|
3243
|
-
}
|
|
3244
|
-
assertConnectionAvailable(connection);
|
|
3245
|
-
const result = await connection.run(query, values, types);
|
|
3246
|
-
return await materializeResultRows(result, exactDecimals, recursiveDecimals);
|
|
3247
|
-
}
|
|
3248
|
-
assertConnectionAvailable(connection);
|
|
3249
|
-
try {
|
|
3250
|
-
bindPreparedStatement(statement, values, types);
|
|
3251
|
-
const result = await statement.run();
|
|
3252
|
-
cache.remember(query, statement);
|
|
3253
|
-
return await materializeResultRows(result, exactDecimals, recursiveDecimals);
|
|
3254
|
-
} catch (error) {
|
|
3255
|
-
cache.evict(query);
|
|
3256
|
-
throw error;
|
|
3257
|
-
}
|
|
3258
|
-
});
|
|
3259
|
-
}
|
|
3260
3160
|
async function* yieldChunkRows(fetchChunk, preferJson, exactDecimals = false) {
|
|
3261
3161
|
let useJson = preferJson;
|
|
3262
3162
|
let yieldedRows = false;
|
|
@@ -3299,10 +3199,7 @@ async function materializeRows(client, query, params, options = {}) {
|
|
|
3299
3199
|
return await materializePgDuckRows(connection, query, params);
|
|
3300
3200
|
}
|
|
3301
3201
|
return await runNodeApiOperation(connection, async () => {
|
|
3302
|
-
const nodeApiParams = toNodeApiParams(params);
|
|
3303
|
-
if (options.prepareCache && typeof connection.prepare === "function") {
|
|
3304
|
-
return await executePreparedQuery(connection, query, nodeApiParams, options.prepareCache, options.exactDecimals, options.decimalMode === "string");
|
|
3305
|
-
}
|
|
3202
|
+
const nodeApiParams = toNodeApiParams(params, options.dateParams);
|
|
3306
3203
|
const result = await connection.run(query, nodeApiParams.values, nodeApiParams.types);
|
|
3307
3204
|
return await materializeResultRows(result, options.exactDecimals, options.decimalMode === "string");
|
|
3308
3205
|
});
|
|
@@ -3447,7 +3344,7 @@ async function* streamRawBatches(client, query, params, options = {}) {
|
|
|
3447
3344
|
streamingConnections.add(connection);
|
|
3448
3345
|
let result;
|
|
3449
3346
|
try {
|
|
3450
|
-
const { values, types } = toNodeApiParams(params);
|
|
3347
|
+
const { values, types } = toNodeApiParams(params, options.dateParams);
|
|
3451
3348
|
result = await connection.stream(query, values, types);
|
|
3452
3349
|
yield* streamNodeApiResult(connection, result, rowsPerChunk, options.decimalMode === "string");
|
|
3453
3350
|
} finally {
|
|
@@ -3512,7 +3409,7 @@ async function executeArrowOnClient(client, query, params, options = {}) {
|
|
|
3512
3409
|
return mapRowsToColumnData(columns, rows);
|
|
3513
3410
|
}
|
|
3514
3411
|
return await runNodeApiOperation(connection, async () => {
|
|
3515
|
-
const { values, types } = toNodeApiParams(params);
|
|
3412
|
+
const { values, types } = toNodeApiParams(params, options.dateParams);
|
|
3516
3413
|
const result = await connection.run(query, values, types);
|
|
3517
3414
|
const maybeArrow = result.toArrow ?? result.getArrowTable;
|
|
3518
3415
|
if (typeof maybeArrow === "function") {
|
|
@@ -3525,23 +3422,23 @@ async function executeArrowOnClient(client, query, params, options = {}) {
|
|
|
3525
3422
|
const js = jsConverterFor(chunks);
|
|
3526
3423
|
const convert = (baseConverter) => {
|
|
3527
3424
|
const converter = options.decimalMode === "string" ? withExactDecimals(baseConverter, true, js) : baseConverter;
|
|
3528
|
-
const
|
|
3425
|
+
const values = columns.map(() => []);
|
|
3529
3426
|
for (const chunk of chunks) {
|
|
3530
3427
|
if (typeof chunk.convertColumns === "function") {
|
|
3531
3428
|
const converted = chunk.convertColumns(converter);
|
|
3532
3429
|
for (let index = 0;index < columns.length; index += 1) {
|
|
3533
3430
|
for (const value of converted[index] ?? [])
|
|
3534
|
-
|
|
3431
|
+
values[index].push(value);
|
|
3535
3432
|
}
|
|
3536
3433
|
} else {
|
|
3537
3434
|
for (const row of chunk.convertRows(converter)) {
|
|
3538
3435
|
for (let index = 0;index < columns.length; index += 1)
|
|
3539
|
-
|
|
3436
|
+
values[index].push(row[index]);
|
|
3540
3437
|
}
|
|
3541
3438
|
}
|
|
3542
3439
|
}
|
|
3543
3440
|
const data = {};
|
|
3544
|
-
columns.forEach((name, index) => assignOwnProperty(data, name,
|
|
3441
|
+
columns.forEach((name, index) => assignOwnProperty(data, name, values[index]));
|
|
3545
3442
|
return data;
|
|
3546
3443
|
};
|
|
3547
3444
|
try {
|
|
@@ -3565,6 +3462,96 @@ async function executeArrowOnClient(client, query, params, options = {}) {
|
|
|
3565
3462
|
});
|
|
3566
3463
|
});
|
|
3567
3464
|
}
|
|
3465
|
+
var APPEND_DEFAULT = Symbol("drizzle-duckdb:append-default");
|
|
3466
|
+
var INT64_MIN = -(2n ** 63n);
|
|
3467
|
+
var INT64_MAX = 2n ** 63n - 1n;
|
|
3468
|
+
function appendCell(appender, value, columnType) {
|
|
3469
|
+
if (value === APPEND_DEFAULT) {
|
|
3470
|
+
appender.appendDefault();
|
|
3471
|
+
return;
|
|
3472
|
+
}
|
|
3473
|
+
const nodeValue = toNodeApiValue(value, columnType);
|
|
3474
|
+
if (nodeValue === null) {
|
|
3475
|
+
appender.appendNull();
|
|
3476
|
+
return;
|
|
3477
|
+
}
|
|
3478
|
+
switch (typeof nodeValue) {
|
|
3479
|
+
case "string":
|
|
3480
|
+
appender.appendVarchar(nodeValue);
|
|
3481
|
+
return;
|
|
3482
|
+
case "number":
|
|
3483
|
+
if (!Number.isInteger(nodeValue)) {
|
|
3484
|
+
appender.appendDouble(nodeValue);
|
|
3485
|
+
} else if (nodeValue >= -2147483648 && nodeValue <= 2147483647) {
|
|
3486
|
+
appender.appendInteger(nodeValue);
|
|
3487
|
+
} else if (Number.isSafeInteger(nodeValue)) {
|
|
3488
|
+
appender.appendBigInt(BigInt(nodeValue));
|
|
3489
|
+
} else {
|
|
3490
|
+
appender.appendDouble(nodeValue);
|
|
3491
|
+
}
|
|
3492
|
+
return;
|
|
3493
|
+
case "boolean":
|
|
3494
|
+
appender.appendBoolean(nodeValue);
|
|
3495
|
+
return;
|
|
3496
|
+
case "bigint":
|
|
3497
|
+
if (nodeValue >= INT64_MIN && nodeValue <= INT64_MAX) {
|
|
3498
|
+
appender.appendBigInt(nodeValue);
|
|
3499
|
+
} else {
|
|
3500
|
+
appender.appendHugeInt(nodeValue);
|
|
3501
|
+
}
|
|
3502
|
+
return;
|
|
3503
|
+
default: {
|
|
3504
|
+
const typed = typedNodeApiParam(nodeValue);
|
|
3505
|
+
if (typed) {
|
|
3506
|
+
appender.appendValue(typed.value, typed.type);
|
|
3507
|
+
} else {
|
|
3508
|
+
appender.appendValue(nodeValue);
|
|
3509
|
+
}
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
}
|
|
3513
|
+
function quoteAppendIdentifier(name) {
|
|
3514
|
+
return `"${name.replace(/"/g, '""')}"`;
|
|
3515
|
+
}
|
|
3516
|
+
async function appendRowsOnClient(client, target, rowCount, bindRows) {
|
|
3517
|
+
return await withConnection(client, async (connection) => {
|
|
3518
|
+
if (!isNodeApiConnection(connection) || typeof connection.createAppender !== "function") {
|
|
3519
|
+
throw new Error("appendRows() needs an @duckdb/node-api connection. Use db.insert() with pg_duckdb clients.");
|
|
3520
|
+
}
|
|
3521
|
+
return await runNodeApiOperation(connection, async () => {
|
|
3522
|
+
const qualified = target.schema ? `${quoteAppendIdentifier(target.schema)}.${quoteAppendIdentifier(target.table)}` : quoteAppendIdentifier(target.table);
|
|
3523
|
+
const probe = await connection.run(`select * from ${qualified} limit 0`);
|
|
3524
|
+
const columnNames = probe.columnNames();
|
|
3525
|
+
const appender = await connection.createAppender(target.table, target.schema ?? null);
|
|
3526
|
+
let failed = true;
|
|
3527
|
+
try {
|
|
3528
|
+
if (appender.columnCount !== columnNames.length) {
|
|
3529
|
+
throw new Error(`appendRows() cannot append to ${qualified}: the table has ${columnNames.length} columns but its appender takes ${appender.columnCount}, as for tables with generated columns. Use db.insert() instead.`);
|
|
3530
|
+
}
|
|
3531
|
+
const columnTypes = columnNames.map((_, index) => appender.columnType(index));
|
|
3532
|
+
const valueAt = bindRows(columnNames);
|
|
3533
|
+
for (let rowIndex = 0;rowIndex < rowCount; rowIndex += 1) {
|
|
3534
|
+
for (let columnIndex = 0;columnIndex < columnTypes.length; columnIndex += 1) {
|
|
3535
|
+
appendCell(appender, valueAt(rowIndex, columnIndex), columnTypes[columnIndex]);
|
|
3536
|
+
}
|
|
3537
|
+
appender.endRow();
|
|
3538
|
+
}
|
|
3539
|
+
appender.flushSync();
|
|
3540
|
+
failed = false;
|
|
3541
|
+
return rowCount;
|
|
3542
|
+
} finally {
|
|
3543
|
+
try {
|
|
3544
|
+
if (failed)
|
|
3545
|
+
appender.clear?.();
|
|
3546
|
+
appender.closeSync();
|
|
3547
|
+
} catch (error) {
|
|
3548
|
+
if (!failed)
|
|
3549
|
+
throw error;
|
|
3550
|
+
}
|
|
3551
|
+
}
|
|
3552
|
+
});
|
|
3553
|
+
});
|
|
3554
|
+
}
|
|
3568
3555
|
|
|
3569
3556
|
// src/select-builder.ts
|
|
3570
3557
|
import {
|
|
@@ -3686,8 +3673,8 @@ function qualifySubqueryFields(select) {
|
|
|
3686
3673
|
const internals = select;
|
|
3687
3674
|
const baseAs = internals.as.bind(internals);
|
|
3688
3675
|
internals.as = (alias) => {
|
|
3689
|
-
const { sql
|
|
3690
|
-
return new Proxy(new Subquery3(
|
|
3676
|
+
const { sql, usedTables } = baseAs(alias)._;
|
|
3677
|
+
return new Proxy(new Subquery3(sql, exposeSubqueryFields(internals.config.fields), alias, false, usedTables), new SelectionProxyHandler({
|
|
3691
3678
|
alias,
|
|
3692
3679
|
sqlAliasedBehavior: "alias",
|
|
3693
3680
|
sqlBehavior: "error"
|
|
@@ -4003,10 +3990,11 @@ class DuckDBPreparedQuery extends PgPreparedQuery {
|
|
|
4003
3990
|
decimalMode;
|
|
4004
3991
|
waitForTransactions;
|
|
4005
3992
|
relationalSelection;
|
|
3993
|
+
dateParams;
|
|
4006
3994
|
static [entityKind3] = "DuckDBPreparedQuery";
|
|
4007
3995
|
resultMapper;
|
|
4008
3996
|
relationalRowNormalizer;
|
|
4009
|
-
constructor(client, dialect, queryString, params, logger, fields, _isResponseInArrayMode, customResultMapper, rejectStringArrayLiterals, prepareCache, queryMetadata, cacheConfig, warnOnStringArrayLiteral, scalarParamIndexes, onStatementError, decimalMode = "number", waitForTransactions = false, relationalSelection) {
|
|
3997
|
+
constructor(client, dialect, queryString, params, logger, fields, _isResponseInArrayMode, customResultMapper, rejectStringArrayLiterals, prepareCache, queryMetadata, cacheConfig, warnOnStringArrayLiteral, scalarParamIndexes, onStatementError, decimalMode = "number", waitForTransactions = false, relationalSelection, dateParams) {
|
|
4010
3998
|
super(...[
|
|
4011
3999
|
{ sql: queryString, params },
|
|
4012
4000
|
undefined,
|
|
@@ -4029,6 +4017,7 @@ class DuckDBPreparedQuery extends PgPreparedQuery {
|
|
|
4029
4017
|
this.decimalMode = decimalMode;
|
|
4030
4018
|
this.waitForTransactions = waitForTransactions;
|
|
4031
4019
|
this.relationalSelection = relationalSelection;
|
|
4020
|
+
this.dateParams = dateParams;
|
|
4032
4021
|
}
|
|
4033
4022
|
async execute(placeholderValues = {}) {
|
|
4034
4023
|
try {
|
|
@@ -4054,17 +4043,19 @@ class DuckDBPreparedQuery extends PgPreparedQuery {
|
|
|
4054
4043
|
});
|
|
4055
4044
|
const { fields, joinsNotNullableMap, customResultMapper } = this;
|
|
4056
4045
|
if (!fields && !customResultMapper) {
|
|
4057
|
-
const
|
|
4046
|
+
const rows = await executeOnClient(this.client, queryString, params, {
|
|
4058
4047
|
prepareCache: this.prepareCache,
|
|
4059
|
-
decimalMode: this.decimalMode
|
|
4048
|
+
decimalMode: this.decimalMode,
|
|
4049
|
+
dateParams: this.dateParams
|
|
4060
4050
|
});
|
|
4061
|
-
return
|
|
4051
|
+
return rows;
|
|
4062
4052
|
}
|
|
4063
4053
|
const relationalSelection = customResultMapper ? this.relationalSelection : undefined;
|
|
4064
4054
|
const { rows, exactDecimalColumns } = await executeArraysOnClient(this.client, queryString, params, {
|
|
4065
4055
|
prepareCache: this.prepareCache,
|
|
4066
4056
|
exactDecimals: !customResultMapper || relationalSelection !== undefined,
|
|
4067
|
-
decimalMode: this.decimalMode
|
|
4057
|
+
decimalMode: this.decimalMode,
|
|
4058
|
+
dateParams: this.dateParams
|
|
4068
4059
|
});
|
|
4069
4060
|
const decimalFields = relationalSelection ?? fields;
|
|
4070
4061
|
if (exactDecimalColumns && decimalFields && this.decimalMode !== "string") {
|
|
@@ -4118,7 +4109,7 @@ class DuckDBSession extends PgSession {
|
|
|
4118
4109
|
};
|
|
4119
4110
|
}
|
|
4120
4111
|
prepareQuery(query, fields, name, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig) {
|
|
4121
|
-
return new DuckDBPreparedQuery(this.client, this.dialect, query.sql, bindEmptyArrays(query.params, query.params, query.typings), this.logger, fields, isResponseInArrayMode, customResultMapper, this.rejectStringArrayLiterals, this.prepareCache, queryMetadata, cacheConfig, this.rejectStringArrayLiterals ? undefined : this.warnOnStringArrayLiteral, getScalarParamIndexes(query.params, query.typings), this.statementFailures || this.waitsForTransactions() ? this.recordStatementFailure : undefined, this.options.decimalMode, this.waitsForTransactions(), relationalSelectionOf(query));
|
|
4112
|
+
return new DuckDBPreparedQuery(this.client, this.dialect, query.sql, bindEmptyArrays(query.params, query.params, query.typings), this.logger, fields, isResponseInArrayMode, customResultMapper, this.rejectStringArrayLiterals, this.prepareCache, queryMetadata, cacheConfig, this.rejectStringArrayLiterals ? undefined : this.warnOnStringArrayLiteral, getScalarParamIndexes(query.params, query.typings), this.statementFailures || this.waitsForTransactions() ? this.recordStatementFailure : undefined, this.options.decimalMode, this.waitsForTransactions(), relationalSelectionOf(query), this.options.dateParams);
|
|
4122
4113
|
}
|
|
4123
4114
|
waitsForTransactions() {
|
|
4124
4115
|
return !this.statementFailures && !isPool(this.client);
|
|
@@ -4286,6 +4277,7 @@ query: ${query}`, []);
|
|
|
4286
4277
|
const { sql: queryString, params } = this.prepareQueryExecution(query);
|
|
4287
4278
|
return this.trackStreamFailures(this.afterOpenTransaction(executeInBatches(this.client, queryString, params, {
|
|
4288
4279
|
decimalMode: this.options.decimalMode,
|
|
4280
|
+
dateParams: this.options.dateParams,
|
|
4289
4281
|
...options
|
|
4290
4282
|
})));
|
|
4291
4283
|
}
|
|
@@ -4293,6 +4285,7 @@ query: ${query}`, []);
|
|
|
4293
4285
|
const { sql: queryString, params } = this.prepareQueryExecution(query);
|
|
4294
4286
|
return this.trackStreamFailures(this.afterOpenTransaction(executeInBatchesRaw(this.client, queryString, params, {
|
|
4295
4287
|
decimalMode: this.options.decimalMode,
|
|
4288
|
+
dateParams: this.options.dateParams,
|
|
4296
4289
|
...options
|
|
4297
4290
|
})));
|
|
4298
4291
|
}
|
|
@@ -4303,7 +4296,65 @@ query: ${query}`, []);
|
|
|
4303
4296
|
}
|
|
4304
4297
|
try {
|
|
4305
4298
|
return await executeArrowOnClient(this.client, queryString, params, {
|
|
4306
|
-
decimalMode: this.options.decimalMode
|
|
4299
|
+
decimalMode: this.options.decimalMode,
|
|
4300
|
+
dateParams: this.options.dateParams
|
|
4301
|
+
});
|
|
4302
|
+
} catch (error) {
|
|
4303
|
+
this.recordStatementFailure(error);
|
|
4304
|
+
throw error;
|
|
4305
|
+
}
|
|
4306
|
+
}
|
|
4307
|
+
async appendRows(table, rows) {
|
|
4308
|
+
if (rows.length === 0) {
|
|
4309
|
+
return 0;
|
|
4310
|
+
}
|
|
4311
|
+
const { name, schema, columns } = getTableConfig(table);
|
|
4312
|
+
const keyOf = new Map;
|
|
4313
|
+
for (const [key, column] of Object.entries(table)) {
|
|
4314
|
+
keyOf.set(column, key);
|
|
4315
|
+
}
|
|
4316
|
+
const byName = new Map(columns.map((column) => [column.name, column]));
|
|
4317
|
+
if (this.waitsForTransactions()) {
|
|
4318
|
+
await waitForOpenTransaction(this.client);
|
|
4319
|
+
}
|
|
4320
|
+
try {
|
|
4321
|
+
return await appendRowsOnClient(this.client, { table: name, schema }, rows.length, (columnNames) => {
|
|
4322
|
+
const known = new Set(columnNames);
|
|
4323
|
+
for (const column of columns) {
|
|
4324
|
+
if (!known.has(column.name)) {
|
|
4325
|
+
throw new Error(`appendRows(): column "${column.name}" is not a column of table "${name}".`);
|
|
4326
|
+
}
|
|
4327
|
+
}
|
|
4328
|
+
const plan = columnNames.map((columnName) => {
|
|
4329
|
+
const column = byName.get(columnName);
|
|
4330
|
+
return column ? { column, key: keyOf.get(column) ?? column.name } : undefined;
|
|
4331
|
+
});
|
|
4332
|
+
return (rowIndex, columnIndex) => {
|
|
4333
|
+
const entry = plan[columnIndex];
|
|
4334
|
+
if (!entry)
|
|
4335
|
+
return APPEND_DEFAULT;
|
|
4336
|
+
const { column, key } = entry;
|
|
4337
|
+
let value = rows[rowIndex][key];
|
|
4338
|
+
if (value === undefined) {
|
|
4339
|
+
if (column.defaultFn !== undefined) {
|
|
4340
|
+
value = column.defaultFn();
|
|
4341
|
+
} else if (column.onUpdateFn !== undefined) {
|
|
4342
|
+
value = column.onUpdateFn();
|
|
4343
|
+
} else {
|
|
4344
|
+
return APPEND_DEFAULT;
|
|
4345
|
+
}
|
|
4346
|
+
}
|
|
4347
|
+
if (value === null)
|
|
4348
|
+
return null;
|
|
4349
|
+
if (is4(value, SQL4)) {
|
|
4350
|
+
throw new Error(`appendRows(): column "${column.name}" got a SQL expression, which the appender cannot evaluate. Use db.insert() for such rows.`);
|
|
4351
|
+
}
|
|
4352
|
+
const driverValue = column.mapToDriverValue(value);
|
|
4353
|
+
if (is4(driverValue, SQL4)) {
|
|
4354
|
+
throw new Error(`appendRows(): column "${column.name}" encodes this value as a SQL literal (a struct, union, empty list, or a list of objects or blobs), which the appender cannot take. Use db.insert() for such rows.`);
|
|
4355
|
+
}
|
|
4356
|
+
return driverValue;
|
|
4357
|
+
};
|
|
4307
4358
|
});
|
|
4308
4359
|
} catch (error) {
|
|
4309
4360
|
this.recordStatementFailure(error);
|
|
@@ -4384,6 +4435,9 @@ class DuckDBTransaction extends PgTransaction {
|
|
|
4384
4435
|
executeArrow(query) {
|
|
4385
4436
|
return this.getInternals().session.executeArrow(query);
|
|
4386
4437
|
}
|
|
4438
|
+
appendRows(table, rows) {
|
|
4439
|
+
return this.getInternals().session.appendRows(table, rows);
|
|
4440
|
+
}
|
|
4387
4441
|
async transaction(transaction) {
|
|
4388
4442
|
const internals = this.getInternals();
|
|
4389
4443
|
const savepoint = `drizzle_savepoint_${this.nestedIndex + 1}`;
|
|
@@ -4723,9 +4777,9 @@ function createDuckDBConnectionPool(instance, options = {}) {
|
|
|
4723
4777
|
if (waiting.length >= maxWaitingRequests) {
|
|
4724
4778
|
throw new Error(`DuckDB connection pool queue is full (max ${maxWaitingRequests} waiting requests)`);
|
|
4725
4779
|
}
|
|
4726
|
-
return await new Promise((
|
|
4780
|
+
return await new Promise((resolve, reject) => {
|
|
4727
4781
|
const waiter = {
|
|
4728
|
-
resolve
|
|
4782
|
+
resolve,
|
|
4729
4783
|
reject,
|
|
4730
4784
|
timeoutId: undefined,
|
|
4731
4785
|
queuedAt: Date.now()
|
|
@@ -5174,7 +5228,8 @@ class DuckDBDriver {
|
|
|
5174
5228
|
rejectStringArrayLiterals: this.options.rejectStringArrayLiterals,
|
|
5175
5229
|
arrayLiteralWarning: this.options.arrayLiteralWarning,
|
|
5176
5230
|
prepareCache: this.options.prepareCache,
|
|
5177
|
-
decimalMode: this.options.decimalMode
|
|
5231
|
+
decimalMode: this.options.decimalMode,
|
|
5232
|
+
dateParams: this.options.dateParams
|
|
5178
5233
|
});
|
|
5179
5234
|
}
|
|
5180
5235
|
}
|
|
@@ -5236,6 +5291,15 @@ function isNodePostgresPool(value) {
|
|
|
5236
5291
|
const candidate = value;
|
|
5237
5292
|
return typeof candidate.connect === "function" && typeof candidate.query === "function" && typeof candidate.acquire !== "function" && typeof candidate.totalCount === "number" && typeof candidate.idleCount === "number";
|
|
5238
5293
|
}
|
|
5294
|
+
var PREPARE_CACHE_WARNING = "The prepareCache option is deprecated and ignored. DuckDB plans a prepared statement from the table statistics at prepare time, so a cached statement can return wrong results after the data changes. Remove the option. It will be removed in the next major version.";
|
|
5295
|
+
var hasWarnedPrepareCache = false;
|
|
5296
|
+
function warnPrepareCacheIgnored() {
|
|
5297
|
+
if (hasWarnedPrepareCache) {
|
|
5298
|
+
return;
|
|
5299
|
+
}
|
|
5300
|
+
hasWarnedPrepareCache = true;
|
|
5301
|
+
console.warn(PREPARE_CACHE_WARNING);
|
|
5302
|
+
}
|
|
5239
5303
|
function createFromClient(client, config = {}, instance) {
|
|
5240
5304
|
let finalClient = isNodePostgresPool(client) ? createPgDuckConnectionPool(client) : client;
|
|
5241
5305
|
if (config.ducklake) {
|
|
@@ -5251,6 +5315,9 @@ function createFromClient(client, config = {}, instance) {
|
|
|
5251
5315
|
decimalMode: config.decimalMode
|
|
5252
5316
|
});
|
|
5253
5317
|
const prepareCache = resolvePrepareCacheOption(config.prepareCache);
|
|
5318
|
+
if (prepareCache) {
|
|
5319
|
+
warnPrepareCacheIgnored();
|
|
5320
|
+
}
|
|
5254
5321
|
const logger = config.logger === true ? new DefaultLogger : config.logger || undefined;
|
|
5255
5322
|
let schema;
|
|
5256
5323
|
if (config.schema) {
|
|
@@ -5266,7 +5333,8 @@ function createFromClient(client, config = {}, instance) {
|
|
|
5266
5333
|
rejectStringArrayLiterals: config.rejectStringArrayLiterals,
|
|
5267
5334
|
arrayLiteralWarning: config.arrayLiteralWarning,
|
|
5268
5335
|
prepareCache,
|
|
5269
|
-
decimalMode: config.decimalMode
|
|
5336
|
+
decimalMode: config.decimalMode,
|
|
5337
|
+
dateParams: config.dateParams
|
|
5270
5338
|
});
|
|
5271
5339
|
const session = driver.createSession(schema);
|
|
5272
5340
|
const db = new DuckDBDatabase(dialect, session, schema, finalClient, instance);
|
|
@@ -5389,6 +5457,9 @@ class DuckDBDatabase extends PgDatabase {
|
|
|
5389
5457
|
executeArrow(query) {
|
|
5390
5458
|
return this.session.executeArrow(query);
|
|
5391
5459
|
}
|
|
5460
|
+
appendRows(table, rows) {
|
|
5461
|
+
return this.session.appendRows(table, rows);
|
|
5462
|
+
}
|
|
5392
5463
|
async transaction(transaction, config) {
|
|
5393
5464
|
return await this.session.transaction(transaction, config);
|
|
5394
5465
|
}
|
|
@@ -5796,8 +5867,8 @@ function timestampLiteral(value, withTimezone) {
|
|
|
5796
5867
|
const fraction = parts.fraction ? `.${parts.fraction}` : "";
|
|
5797
5868
|
const offset = parts.offset === "Z" ? "+00" : parts.offset;
|
|
5798
5869
|
if (withTimezone) {
|
|
5799
|
-
const
|
|
5800
|
-
return `${parts.date}${
|
|
5870
|
+
const time = ` ${parts.time ?? "00:00:00"}`;
|
|
5871
|
+
return `${parts.date}${time}${fraction}${offset ?? "+00"}`;
|
|
5801
5872
|
}
|
|
5802
5873
|
if (offset && !/^[+-]00(:00)?$/.test(offset)) {
|
|
5803
5874
|
const utc = utcTimestampString(parts);
|
|
@@ -6683,7 +6754,7 @@ function nestedValueType(raw) {
|
|
|
6683
6754
|
return `Array<${nestedValueType(array[1])} | null>`;
|
|
6684
6755
|
if (type.startsWith("STRUCT")) {
|
|
6685
6756
|
const fields = parseStructFields(type.replace(/^STRUCT\s*\(/i, "").replace(/\)$/, ""));
|
|
6686
|
-
return `{ ${fields.map(({ name, type
|
|
6757
|
+
return `{ ${fields.map(({ name, type }) => `${JSON.stringify(name)}: ${nestedValueType(type)} | null`).join("; ")} }`;
|
|
6687
6758
|
}
|
|
6688
6759
|
if (type.startsWith("MAP(")) {
|
|
6689
6760
|
const { keyType, valueType } = parseMapTypes(type);
|
|
@@ -6751,14 +6822,14 @@ function mapDuckDbType(column, imports, options) {
|
|
|
6751
6822
|
imports.pgCore.add("numeric");
|
|
6752
6823
|
const precision = column.numericPrecision;
|
|
6753
6824
|
const scale = column.numericScale;
|
|
6754
|
-
const
|
|
6825
|
+
const options = [];
|
|
6755
6826
|
if (precision !== null && precision !== undefined) {
|
|
6756
|
-
|
|
6827
|
+
options.push(`precision: ${precision}`);
|
|
6757
6828
|
}
|
|
6758
6829
|
if (scale !== null && scale !== undefined) {
|
|
6759
|
-
|
|
6830
|
+
options.push(`scale: ${scale}`);
|
|
6760
6831
|
}
|
|
6761
|
-
const suffix =
|
|
6832
|
+
const suffix = options.length ? `, { ${options.join(", ")} }` : "";
|
|
6762
6833
|
return {
|
|
6763
6834
|
builder: `numeric(${columnName(column.name)}${suffix})`,
|
|
6764
6835
|
defaultLiterals: STRING_DEFAULTS
|
|
@@ -7065,9 +7136,9 @@ function uniqueSchemas(tables) {
|
|
|
7065
7136
|
}
|
|
7066
7137
|
function renderImports(imports, importBasePath) {
|
|
7067
7138
|
const lines = [];
|
|
7068
|
-
const
|
|
7069
|
-
if (
|
|
7070
|
-
lines.push(`import { ${
|
|
7139
|
+
const drizzle = [...imports.drizzle];
|
|
7140
|
+
if (drizzle.length) {
|
|
7141
|
+
lines.push(`import { ${drizzle.sort().join(", ")} } from 'drizzle-orm';`);
|
|
7071
7142
|
}
|
|
7072
7143
|
const pgCore = [...imports.pgCore];
|
|
7073
7144
|
if (pgCore.length) {
|
|
@@ -7253,7 +7324,10 @@ import { sql as sql9 } from "drizzle-orm";
|
|
|
7253
7324
|
import { isSQLWrapper as isSQLWrapper4 } from "drizzle-orm/sql/sql";
|
|
7254
7325
|
var motherDuckFlightReservedConfigKeys = new Set([
|
|
7255
7326
|
"MOTHERDUCK_TOKEN",
|
|
7256
|
-
"MOTHERDUCK_FLIGHTS_RUN"
|
|
7327
|
+
"MOTHERDUCK_FLIGHTS_RUN",
|
|
7328
|
+
"MOTHERDUCK_FLIGHT_ID",
|
|
7329
|
+
"MOTHERDUCK_FLIGHT_RUN_ID",
|
|
7330
|
+
"MOTHERDUCK_HOST"
|
|
7257
7331
|
]);
|
|
7258
7332
|
var motherDuckTableFunctionNameList = [
|
|
7259
7333
|
"read_parquet",
|
|
@@ -8072,144 +8146,146 @@ function mdPrompt(input, options = {}) {
|
|
|
8072
8146
|
return sql12`prompt(${sql12.join(args, sql12`, `)})`;
|
|
8073
8147
|
}
|
|
8074
8148
|
export {
|
|
8075
|
-
|
|
8076
|
-
|
|
8077
|
-
wrapStruct,
|
|
8078
|
-
wrapMap,
|
|
8079
|
-
wrapList,
|
|
8080
|
-
wrapJson,
|
|
8081
|
-
wrapDuckLakePool,
|
|
8082
|
-
wrapBlob,
|
|
8083
|
-
wrapArray,
|
|
8084
|
-
toIdentifier,
|
|
8085
|
-
sumN,
|
|
8086
|
-
sumDistinctN,
|
|
8087
|
-
splitTopLevel,
|
|
8088
|
-
rowNumber,
|
|
8089
|
-
resolvePrepareCacheOption,
|
|
8090
|
-
resolvePoolSize,
|
|
8091
|
-
rank,
|
|
8092
|
-
prepareParams,
|
|
8093
|
-
percentileCont,
|
|
8094
|
-
parseStructFields,
|
|
8095
|
-
parseMapValue,
|
|
8096
|
-
parseMapKey,
|
|
8097
|
-
olap,
|
|
8098
|
-
normalizeTypeLiteral,
|
|
8099
|
-
normalizePositiveInteger,
|
|
8100
|
-
normalizeArrayPredicateValue,
|
|
8101
|
-
motherDuckTableFunction,
|
|
8102
|
-
motherDuckReadParquet,
|
|
8103
|
-
motherDuckReadJsonAuto,
|
|
8104
|
-
motherDuckReadCsvAuto,
|
|
8105
|
-
migrate,
|
|
8106
|
-
median,
|
|
8107
|
-
mdUpdateJob,
|
|
8108
|
-
mdUpdateFlight,
|
|
8109
|
-
mdUpdateDiveStatus,
|
|
8110
|
-
mdUpdateDiveMetadata,
|
|
8111
|
-
mdUpdateDiveContent,
|
|
8112
|
-
mdSessionRoles,
|
|
8113
|
-
mdRunJob,
|
|
8114
|
-
mdRunFlight,
|
|
8115
|
-
mdPromptJev,
|
|
8116
|
-
mdPrompt,
|
|
8117
|
-
mdListRolesGrantedToUser,
|
|
8118
|
-
mdListRolesGrantedToRole,
|
|
8119
|
-
mdListRoles,
|
|
8120
|
-
mdListRoleMembers,
|
|
8121
|
-
mdListFlights,
|
|
8122
|
-
mdListFlightVersions,
|
|
8123
|
-
mdListFlightRuns,
|
|
8124
|
-
mdListFlightGrantees,
|
|
8125
|
-
mdListFiles,
|
|
8126
|
-
mdListDives,
|
|
8127
|
-
mdListDiveVersions,
|
|
8128
|
-
mdJobs,
|
|
8129
|
-
mdJobVersions,
|
|
8130
|
-
mdJobRuns,
|
|
8131
|
-
mdJobRunLogs,
|
|
8132
|
-
mdIsRoleInSession,
|
|
8133
|
-
mdGetJobVersion,
|
|
8134
|
-
mdGetJob,
|
|
8135
|
-
mdGetFlightVersion,
|
|
8136
|
-
mdGetFlightRun,
|
|
8137
|
-
mdGetFlightLogs,
|
|
8138
|
-
mdGetFlight,
|
|
8139
|
-
mdGetDiveVersion,
|
|
8140
|
-
mdGetDive,
|
|
8141
|
-
mdFlights,
|
|
8142
|
-
mdFlightVersions,
|
|
8143
|
-
mdFlightRuns,
|
|
8144
|
-
mdFlightLogs,
|
|
8145
|
-
mdDeleteJob,
|
|
8146
|
-
mdDeleteFlight,
|
|
8147
|
-
mdDeleteDive,
|
|
8148
|
-
mdCurrentEmail,
|
|
8149
|
-
mdCreateJob,
|
|
8150
|
-
mdCreateFlight,
|
|
8151
|
-
mdCreateDive,
|
|
8152
|
-
mdCancelJobRun,
|
|
8153
|
-
mdCancelFlightRun,
|
|
8154
|
-
mdAccessTokens,
|
|
8155
|
-
lead,
|
|
8156
|
-
lanceVectorSearch,
|
|
8157
|
-
lanceHybridSearch,
|
|
8158
|
-
lanceFts,
|
|
8159
|
-
lag,
|
|
8160
|
-
isPool,
|
|
8161
|
-
isDuckDBWrapper,
|
|
8162
|
-
introspect,
|
|
8163
|
-
getPreparedStatementCacheStats,
|
|
8164
|
-
formatLiteral,
|
|
8165
|
-
executeOnClient,
|
|
8166
|
-
executeInBatchesRaw,
|
|
8167
|
-
executeInBatches,
|
|
8168
|
-
executeArrowOnClient,
|
|
8169
|
-
executeArraysOnClient,
|
|
8170
|
-
duckLakeMergeAdjacentFiles,
|
|
8171
|
-
duckDbUnion,
|
|
8172
|
-
duckDbTimestamp,
|
|
8173
|
-
duckDbTime,
|
|
8174
|
-
duckDbStruct,
|
|
8175
|
-
duckDbMap,
|
|
8176
|
-
duckDbList,
|
|
8177
|
-
duckDbJson,
|
|
8178
|
-
duckDbInterval,
|
|
8179
|
-
duckDbInet,
|
|
8180
|
-
duckDbDate,
|
|
8181
|
-
duckDbBlob,
|
|
8182
|
-
duckDbArrayOverlaps,
|
|
8183
|
-
duckDbArrayContains,
|
|
8184
|
-
duckDbArrayContained,
|
|
8185
|
-
duckDbArray,
|
|
8186
|
-
drizzle,
|
|
8187
|
-
denseRank,
|
|
8188
|
-
createPgDuckConnectionPool,
|
|
8189
|
-
createDuckDBConnectionPool,
|
|
8190
|
-
countN,
|
|
8191
|
-
configureDuckLake,
|
|
8192
|
-
coerceArrayString,
|
|
8193
|
-
closeDuckDbInstance,
|
|
8194
|
-
closeClientConnection,
|
|
8195
|
-
buildStructLiteral,
|
|
8196
|
-
buildMapLiteral,
|
|
8197
|
-
buildListLiteral,
|
|
8198
|
-
buildDefault,
|
|
8199
|
-
avgN,
|
|
8200
|
-
duckDbArrayOverlaps as arrayHasAny,
|
|
8201
|
-
duckDbArrayContains as arrayHasAll,
|
|
8202
|
-
duckDbArrayContained as arrayContainedBy,
|
|
8203
|
-
anyValue,
|
|
8204
|
-
POOL_PRESETS,
|
|
8205
|
-
OlapBuilder,
|
|
8206
|
-
DuckDBTransaction,
|
|
8207
|
-
DuckDBSession,
|
|
8208
|
-
DuckDBSelectBuilder,
|
|
8209
|
-
DuckDBPreparedQuery,
|
|
8210
|
-
DuckDBDriver,
|
|
8211
|
-
DuckDBDialect,
|
|
8212
|
-
DuckDBDatabase,
|
|
8149
|
+
APPEND_DEFAULT,
|
|
8150
|
+
DEFAULT_IMPORT_BASE,
|
|
8213
8151
|
DUCKDB_VALUE_MARKER,
|
|
8214
|
-
|
|
8152
|
+
DuckDBDatabase,
|
|
8153
|
+
DuckDBDialect,
|
|
8154
|
+
DuckDBDriver,
|
|
8155
|
+
DuckDBPreparedQuery,
|
|
8156
|
+
DuckDBSelectBuilder,
|
|
8157
|
+
DuckDBSession,
|
|
8158
|
+
DuckDBTransaction,
|
|
8159
|
+
OlapBuilder,
|
|
8160
|
+
POOL_PRESETS,
|
|
8161
|
+
anyValue,
|
|
8162
|
+
appendRowsOnClient,
|
|
8163
|
+
duckDbArrayContained as arrayContainedBy,
|
|
8164
|
+
duckDbArrayContains as arrayHasAll,
|
|
8165
|
+
duckDbArrayOverlaps as arrayHasAny,
|
|
8166
|
+
avgN,
|
|
8167
|
+
buildDefault,
|
|
8168
|
+
buildListLiteral,
|
|
8169
|
+
buildMapLiteral,
|
|
8170
|
+
buildStructLiteral,
|
|
8171
|
+
closeClientConnection,
|
|
8172
|
+
closeDuckDbInstance,
|
|
8173
|
+
coerceArrayString,
|
|
8174
|
+
configureDuckLake,
|
|
8175
|
+
countN,
|
|
8176
|
+
createDuckDBConnectionPool,
|
|
8177
|
+
createPgDuckConnectionPool,
|
|
8178
|
+
denseRank,
|
|
8179
|
+
drizzle,
|
|
8180
|
+
duckDbArray,
|
|
8181
|
+
duckDbArrayContained,
|
|
8182
|
+
duckDbArrayContains,
|
|
8183
|
+
duckDbArrayOverlaps,
|
|
8184
|
+
duckDbBlob,
|
|
8185
|
+
duckDbDate,
|
|
8186
|
+
duckDbInet,
|
|
8187
|
+
duckDbInterval,
|
|
8188
|
+
duckDbJson,
|
|
8189
|
+
duckDbList,
|
|
8190
|
+
duckDbMap,
|
|
8191
|
+
duckDbStruct,
|
|
8192
|
+
duckDbTime,
|
|
8193
|
+
duckDbTimestamp,
|
|
8194
|
+
duckDbUnion,
|
|
8195
|
+
duckLakeMergeAdjacentFiles,
|
|
8196
|
+
executeArraysOnClient,
|
|
8197
|
+
executeArrowOnClient,
|
|
8198
|
+
executeInBatches,
|
|
8199
|
+
executeInBatchesRaw,
|
|
8200
|
+
executeOnClient,
|
|
8201
|
+
formatLiteral,
|
|
8202
|
+
getPreparedStatementCacheStats,
|
|
8203
|
+
introspect,
|
|
8204
|
+
isDuckDBWrapper,
|
|
8205
|
+
isPool,
|
|
8206
|
+
lag,
|
|
8207
|
+
lanceFts,
|
|
8208
|
+
lanceHybridSearch,
|
|
8209
|
+
lanceVectorSearch,
|
|
8210
|
+
lead,
|
|
8211
|
+
mdAccessTokens,
|
|
8212
|
+
mdCancelFlightRun,
|
|
8213
|
+
mdCancelJobRun,
|
|
8214
|
+
mdCreateDive,
|
|
8215
|
+
mdCreateFlight,
|
|
8216
|
+
mdCreateJob,
|
|
8217
|
+
mdCurrentEmail,
|
|
8218
|
+
mdDeleteDive,
|
|
8219
|
+
mdDeleteFlight,
|
|
8220
|
+
mdDeleteJob,
|
|
8221
|
+
mdFlightLogs,
|
|
8222
|
+
mdFlightRuns,
|
|
8223
|
+
mdFlightVersions,
|
|
8224
|
+
mdFlights,
|
|
8225
|
+
mdGetDive,
|
|
8226
|
+
mdGetDiveVersion,
|
|
8227
|
+
mdGetFlight,
|
|
8228
|
+
mdGetFlightLogs,
|
|
8229
|
+
mdGetFlightRun,
|
|
8230
|
+
mdGetFlightVersion,
|
|
8231
|
+
mdGetJob,
|
|
8232
|
+
mdGetJobVersion,
|
|
8233
|
+
mdIsRoleInSession,
|
|
8234
|
+
mdJobRunLogs,
|
|
8235
|
+
mdJobRuns,
|
|
8236
|
+
mdJobVersions,
|
|
8237
|
+
mdJobs,
|
|
8238
|
+
mdListDiveVersions,
|
|
8239
|
+
mdListDives,
|
|
8240
|
+
mdListFiles,
|
|
8241
|
+
mdListFlightGrantees,
|
|
8242
|
+
mdListFlightRuns,
|
|
8243
|
+
mdListFlightVersions,
|
|
8244
|
+
mdListFlights,
|
|
8245
|
+
mdListRoleMembers,
|
|
8246
|
+
mdListRoles,
|
|
8247
|
+
mdListRolesGrantedToRole,
|
|
8248
|
+
mdListRolesGrantedToUser,
|
|
8249
|
+
mdPrompt,
|
|
8250
|
+
mdPromptJev,
|
|
8251
|
+
mdRunFlight,
|
|
8252
|
+
mdRunJob,
|
|
8253
|
+
mdSessionRoles,
|
|
8254
|
+
mdUpdateDiveContent,
|
|
8255
|
+
mdUpdateDiveMetadata,
|
|
8256
|
+
mdUpdateDiveStatus,
|
|
8257
|
+
mdUpdateFlight,
|
|
8258
|
+
mdUpdateJob,
|
|
8259
|
+
median,
|
|
8260
|
+
migrate,
|
|
8261
|
+
motherDuckReadCsvAuto,
|
|
8262
|
+
motherDuckReadJsonAuto,
|
|
8263
|
+
motherDuckReadParquet,
|
|
8264
|
+
motherDuckTableFunction,
|
|
8265
|
+
normalizeArrayPredicateValue,
|
|
8266
|
+
normalizePositiveInteger,
|
|
8267
|
+
normalizeTypeLiteral,
|
|
8268
|
+
olap,
|
|
8269
|
+
parseMapKey,
|
|
8270
|
+
parseMapValue,
|
|
8271
|
+
parseStructFields,
|
|
8272
|
+
percentileCont,
|
|
8273
|
+
prepareParams,
|
|
8274
|
+
rank,
|
|
8275
|
+
resolvePoolSize,
|
|
8276
|
+
resolvePrepareCacheOption,
|
|
8277
|
+
rowNumber,
|
|
8278
|
+
splitTopLevel,
|
|
8279
|
+
sumDistinctN,
|
|
8280
|
+
sumN,
|
|
8281
|
+
toIdentifier,
|
|
8282
|
+
wrapArray,
|
|
8283
|
+
wrapBlob,
|
|
8284
|
+
wrapDuckLakePool,
|
|
8285
|
+
wrapJson,
|
|
8286
|
+
wrapList,
|
|
8287
|
+
wrapMap,
|
|
8288
|
+
wrapStruct,
|
|
8289
|
+
wrapTimestamp,
|
|
8290
|
+
wrapperToNodeApiValue
|
|
8215
8291
|
};
|