@haybarn/node-api 1.5.6-rc1 → 2.0.0-rc5
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 +315 -21
- package/lib/DuckDBAppender.d.ts +8 -2
- package/lib/DuckDBAppender.js +19 -1
- package/lib/DuckDBConnection.d.ts +2 -0
- package/lib/DuckDBConnection.js +4 -1
- package/lib/DuckDBDataChunk.d.ts +30 -0
- package/lib/DuckDBDataChunk.js +94 -1
- package/lib/DuckDBDataChunkWriter.d.ts +74 -0
- package/lib/DuckDBDataChunkWriter.js +109 -0
- package/lib/DuckDBLogicalType.d.ts +5 -1
- package/lib/DuckDBLogicalType.js +18 -1
- package/lib/DuckDBMaterializedResult.d.ts +8 -1
- package/lib/DuckDBMaterializedResult.js +22 -2
- package/lib/DuckDBPendingResult.d.ts +16 -1
- package/lib/DuckDBPendingResult.js +19 -2
- package/lib/DuckDBPreparedStatement.d.ts +4 -1
- package/lib/DuckDBPreparedStatement.js +17 -4
- package/lib/DuckDBResult.d.ts +21 -1
- package/lib/DuckDBResult.js +87 -5
- package/lib/DuckDBResultReader.d.ts +5 -0
- package/lib/DuckDBResultReader.js +9 -2
- package/lib/DuckDBScalarFunction.d.ts +9 -5
- package/lib/DuckDBScalarFunction.js +14 -5
- package/lib/DuckDBScalarFunctionBindInfo.d.ts +16 -0
- package/lib/{DuckDBBindInfo.js → DuckDBScalarFunctionBindInfo.js} +5 -3
- package/lib/DuckDBScalarFunctionInfo.d.ts +16 -0
- package/lib/{DuckDBFunctionInfo.js → DuckDBScalarFunctionInfo.js} +11 -3
- package/lib/{DuckDBBindInfo.d.ts → DuckDBScalarFunctionInitInfo.d.ts} +6 -4
- package/lib/DuckDBScalarFunctionInitInfo.js +39 -0
- package/lib/DuckDBTableFunction.d.ts +41 -0
- package/lib/DuckDBTableFunction.js +83 -0
- package/lib/DuckDBTableFunctionBindInfo.d.ts +21 -0
- package/lib/DuckDBTableFunctionBindInfo.js +54 -0
- package/lib/DuckDBTableFunctionInfo.d.ts +15 -0
- package/lib/DuckDBTableFunctionInfo.js +42 -0
- package/lib/DuckDBTableFunctionInitInfo.d.ts +22 -0
- package/lib/DuckDBTableFunctionInitInfo.js +58 -0
- package/lib/DuckDBType.d.ts +1 -373
- package/lib/DuckDBType.js +14 -927
- package/lib/DuckDBTypeId.d.ts +4 -1
- package/lib/DuckDBTypeId.js +3 -0
- package/lib/DuckDBValueConverter.d.ts +10 -0
- package/lib/DuckDBValueConverters.d.ts +27 -0
- package/lib/DuckDBValueConverters.js +128 -1
- package/lib/DuckDBVector.d.ts +1 -596
- package/lib/DuckDBVector.js +14 -2522
- package/lib/JSDuckDBValueConverter.d.ts +1 -2
- package/lib/JSDuckDBValueConverter.js +5 -2
- package/lib/JSInputTypeForTypeId.d.ts +104 -0
- package/lib/JSInputTypeForTypeId.js +3 -0
- package/lib/JSToDuckDBValueConverter.d.ts +30 -0
- package/lib/JSToDuckDBValueConverter.js +83 -0
- package/lib/JSTypeForTypeId.d.ts +91 -0
- package/lib/JSTypeForTypeId.js +3 -0
- package/lib/JsonDuckDBValueConverter.d.ts +1 -2
- package/lib/JsonDuckDBValueConverter.js +4 -1
- package/lib/JsonTypeForTypeId.d.ts +96 -0
- package/lib/JsonTypeForTypeId.js +3 -0
- package/lib/ToDuckDBValueConverter.d.ts +41 -0
- package/lib/ToDuckDBValueConverter.js +27 -0
- package/lib/ToDuckDBValueConverters.d.ts +54 -0
- package/lib/ToDuckDBValueConverters.js +199 -0
- package/lib/conversion/dateTimeStringConversion.d.ts +2 -2
- package/lib/conversion/dateTimeStringConversion.js +20 -7
- package/lib/conversion/varintDecode.d.ts +18 -0
- package/lib/conversion/varintDecode.js +42 -0
- package/lib/convertColumnsFromChunks.d.ts +1 -1
- package/lib/convertColumnsFromChunks.js +2 -2
- package/lib/createResult.d.ts +2 -1
- package/lib/createResult.js +3 -3
- package/lib/createValue.js +63 -5
- package/lib/duckdb.d.ts +15 -2
- package/lib/duckdb.js +15 -2
- package/lib/getColumnsFromChunks.d.ts +1 -1
- package/lib/getColumnsFromChunks.js +2 -2
- package/lib/getColumnsObjectFromChunks.js +3 -0
- package/lib/readValue.d.ts +22 -0
- package/lib/readValue.js +35 -0
- package/lib/typeForValue.js +21 -2
- package/lib/types/BaseDuckDBType.d.ts +11 -0
- package/lib/types/BaseDuckDBType.js +34 -0
- package/lib/types/DuckDBAnyType.d.ts +8 -0
- package/lib/types/DuckDBAnyType.js +16 -0
- package/lib/types/DuckDBArrayType.d.ts +14 -0
- package/lib/types/DuckDBArrayType.js +38 -0
- package/lib/types/DuckDBBigIntType.d.ts +12 -0
- package/lib/types/DuckDBBigIntType.js +24 -0
- package/lib/types/DuckDBBigNumType.d.ts +12 -0
- package/lib/types/DuckDBBigNumType.js +24 -0
- package/lib/types/DuckDBBitType.d.ts +8 -0
- package/lib/types/DuckDBBitType.js +16 -0
- package/lib/types/DuckDBBlobType.d.ts +8 -0
- package/lib/types/DuckDBBlobType.js +16 -0
- package/lib/types/DuckDBBooleanType.d.ts +8 -0
- package/lib/types/DuckDBBooleanType.js +16 -0
- package/lib/types/DuckDBDateType.d.ts +14 -0
- package/lib/types/DuckDBDateType.js +32 -0
- package/lib/types/DuckDBDecimalType.d.ts +14 -0
- package/lib/types/DuckDBDecimalType.js +45 -0
- package/lib/types/DuckDBDoubleType.d.ts +12 -0
- package/lib/types/DuckDBDoubleType.js +24 -0
- package/lib/types/DuckDBEnumType.d.ts +29 -0
- package/lib/types/DuckDBEnumType.js +100 -0
- package/lib/types/DuckDBFloatType.d.ts +12 -0
- package/lib/types/DuckDBFloatType.js +24 -0
- package/lib/types/DuckDBGeometryType.d.ts +19 -0
- package/lib/types/DuckDBGeometryType.js +38 -0
- package/lib/types/DuckDBHugeIntType.d.ts +12 -0
- package/lib/types/DuckDBHugeIntType.js +24 -0
- package/lib/types/DuckDBIntegerLiteralType.d.ts +8 -0
- package/lib/types/DuckDBIntegerLiteralType.js +16 -0
- package/lib/types/DuckDBIntegerType.d.ts +12 -0
- package/lib/types/DuckDBIntegerType.js +24 -0
- package/lib/types/DuckDBIntervalType.d.ts +8 -0
- package/lib/types/DuckDBIntervalType.js +16 -0
- package/lib/types/DuckDBListType.d.ts +13 -0
- package/lib/types/DuckDBListType.js +35 -0
- package/lib/types/DuckDBMapType.d.ts +14 -0
- package/lib/types/DuckDBMapType.js +38 -0
- package/lib/types/DuckDBSQLNullType.d.ts +10 -0
- package/lib/types/DuckDBSQLNullType.js +20 -0
- package/lib/types/DuckDBSmallIntType.d.ts +12 -0
- package/lib/types/DuckDBSmallIntType.js +24 -0
- package/lib/types/DuckDBStringLiteralType.d.ts +8 -0
- package/lib/types/DuckDBStringLiteralType.js +16 -0
- package/lib/types/DuckDBStructType.d.ts +29 -0
- package/lib/types/DuckDBStructType.js +86 -0
- package/lib/types/DuckDBTimeNSType.d.ts +11 -0
- package/lib/types/DuckDBTimeNSType.js +23 -0
- package/lib/types/DuckDBTimeTZType.d.ts +12 -0
- package/lib/types/DuckDBTimeTZType.js +26 -0
- package/lib/types/DuckDBTimeType.d.ts +11 -0
- package/lib/types/DuckDBTimeType.js +23 -0
- package/lib/types/DuckDBTimestampMillisecondsType.d.ts +14 -0
- package/lib/types/DuckDBTimestampMillisecondsType.js +32 -0
- package/lib/types/DuckDBTimestampNanosecondsType.d.ts +14 -0
- package/lib/types/DuckDBTimestampNanosecondsType.js +32 -0
- package/lib/types/DuckDBTimestampSecondsType.d.ts +14 -0
- package/lib/types/DuckDBTimestampSecondsType.js +32 -0
- package/lib/types/DuckDBTimestampTZNanosecondsType.d.ts +15 -0
- package/lib/types/DuckDBTimestampTZNanosecondsType.js +35 -0
- package/lib/types/DuckDBTimestampTZType.d.ts +15 -0
- package/lib/types/DuckDBTimestampTZType.js +35 -0
- package/lib/types/DuckDBTimestampType.d.ts +16 -0
- package/lib/types/DuckDBTimestampType.js +33 -0
- package/lib/types/DuckDBTinyIntType.d.ts +12 -0
- package/lib/types/DuckDBTinyIntType.js +24 -0
- package/lib/types/DuckDBType.d.ts +43 -0
- package/lib/types/DuckDBType.js +2 -0
- package/lib/types/DuckDBUBigIntType.d.ts +12 -0
- package/lib/types/DuckDBUBigIntType.js +24 -0
- package/lib/types/DuckDBUHugeIntType.d.ts +12 -0
- package/lib/types/DuckDBUHugeIntType.js +24 -0
- package/lib/types/DuckDBUIntegerType.d.ts +12 -0
- package/lib/types/DuckDBUIntegerType.js +24 -0
- package/lib/types/DuckDBUSmallIntType.d.ts +12 -0
- package/lib/types/DuckDBUSmallIntType.js +24 -0
- package/lib/types/DuckDBUTinyIntType.d.ts +12 -0
- package/lib/types/DuckDBUTinyIntType.js +24 -0
- package/lib/types/DuckDBUUIDType.d.ts +11 -0
- package/lib/types/DuckDBUUIDType.js +23 -0
- package/lib/types/DuckDBUnionType.d.ts +18 -0
- package/lib/types/DuckDBUnionType.js +64 -0
- package/lib/types/DuckDBVarCharType.d.ts +8 -0
- package/lib/types/DuckDBVarCharType.js +16 -0
- package/lib/types/DuckDBVariantType.d.ts +8 -0
- package/lib/types/DuckDBVariantType.js +16 -0
- package/lib/types/index.d.ts +44 -0
- package/lib/types/index.js +60 -0
- package/lib/values/DuckDBGeometryValue.d.ts +12 -0
- package/lib/values/DuckDBGeometryValue.js +30 -0
- package/lib/values/DuckDBTimestampTZNanosecondsValue.d.ts +14 -0
- package/lib/values/DuckDBTimestampTZNanosecondsValue.js +33 -0
- package/lib/values/DuckDBTupleValue.d.ts +11 -0
- package/lib/values/DuckDBTupleValue.js +22 -0
- package/lib/values/DuckDBUUIDValue.js +5 -1
- package/lib/values/DuckDBValue.d.ts +5 -1
- package/lib/values/DuckDBVariantValue.d.ts +19 -0
- package/lib/values/DuckDBVariantValue.js +30 -0
- package/lib/values/index.d.ts +4 -0
- package/lib/values/index.js +4 -0
- package/lib/vectors/DuckDBArrayVector.d.ts +21 -0
- package/lib/vectors/DuckDBArrayVector.js +79 -0
- package/lib/vectors/DuckDBBigIntVector.d.ts +17 -0
- package/lib/vectors/DuckDBBigIntVector.js +58 -0
- package/lib/vectors/DuckDBBigNumVector.d.ts +21 -0
- package/lib/vectors/DuckDBBigNumVector.js +70 -0
- package/lib/vectors/DuckDBBitVector.d.ts +22 -0
- package/lib/vectors/DuckDBBitVector.js +74 -0
- package/lib/vectors/DuckDBBlobVector.d.ts +32 -0
- package/lib/vectors/DuckDBBlobVector.js +83 -0
- package/lib/vectors/DuckDBBooleanVector.d.ts +18 -0
- package/lib/vectors/DuckDBBooleanVector.js +58 -0
- package/lib/vectors/DuckDBDateVector.d.ts +18 -0
- package/lib/vectors/DuckDBDateVector.js +64 -0
- package/lib/vectors/DuckDBDecimal128Vector.d.ts +21 -0
- package/lib/vectors/DuckDBDecimal128Vector.js +64 -0
- package/lib/vectors/DuckDBDecimal16Vector.d.ts +21 -0
- package/lib/vectors/DuckDBDecimal16Vector.js +64 -0
- package/lib/vectors/DuckDBDecimal32Vector.d.ts +21 -0
- package/lib/vectors/DuckDBDecimal32Vector.js +64 -0
- package/lib/vectors/DuckDBDecimal64Vector.d.ts +21 -0
- package/lib/vectors/DuckDBDecimal64Vector.js +64 -0
- package/lib/vectors/DuckDBDoubleVector.d.ts +17 -0
- package/lib/vectors/DuckDBDoubleVector.js +54 -0
- package/lib/vectors/DuckDBEnum16Vector.d.ts +18 -0
- package/lib/vectors/DuckDBEnum16Vector.js +57 -0
- package/lib/vectors/DuckDBEnum32Vector.d.ts +18 -0
- package/lib/vectors/DuckDBEnum32Vector.js +57 -0
- package/lib/vectors/DuckDBEnum8Vector.d.ts +18 -0
- package/lib/vectors/DuckDBEnum8Vector.js +57 -0
- package/lib/vectors/DuckDBFloatVector.d.ts +17 -0
- package/lib/vectors/DuckDBFloatVector.js +54 -0
- package/lib/vectors/DuckDBGeometryVector.d.ts +22 -0
- package/lib/vectors/DuckDBGeometryVector.js +69 -0
- package/lib/vectors/DuckDBHugeIntVector.d.ts +19 -0
- package/lib/vectors/DuckDBHugeIntVector.js +63 -0
- package/lib/vectors/DuckDBIntegerVector.d.ts +17 -0
- package/lib/vectors/DuckDBIntegerVector.js +61 -0
- package/lib/vectors/DuckDBIntervalVector.d.ts +19 -0
- package/lib/vectors/DuckDBIntervalVector.js +67 -0
- package/lib/vectors/DuckDBListVector.d.ts +35 -0
- package/lib/vectors/DuckDBListVector.js +151 -0
- package/lib/vectors/DuckDBMapVector.d.ts +17 -0
- package/lib/vectors/DuckDBMapVector.js +60 -0
- package/lib/vectors/DuckDBSQLNullVector.d.ts +18 -0
- package/lib/vectors/DuckDBSQLNullVector.js +44 -0
- package/lib/vectors/DuckDBSmallIntVector.d.ts +17 -0
- package/lib/vectors/DuckDBSmallIntVector.js +61 -0
- package/lib/vectors/DuckDBStructVector.d.ts +35 -0
- package/lib/vectors/DuckDBStructVector.js +105 -0
- package/lib/vectors/DuckDBTimeNSVector.d.ts +18 -0
- package/lib/vectors/DuckDBTimeNSVector.js +61 -0
- package/lib/vectors/DuckDBTimeTZVector.d.ts +18 -0
- package/lib/vectors/DuckDBTimeTZVector.js +61 -0
- package/lib/vectors/DuckDBTimeVector.d.ts +18 -0
- package/lib/vectors/DuckDBTimeVector.js +61 -0
- package/lib/vectors/DuckDBTimestampMillisecondsVector.d.ts +18 -0
- package/lib/vectors/DuckDBTimestampMillisecondsVector.js +61 -0
- package/lib/vectors/DuckDBTimestampNanosecondsVector.d.ts +18 -0
- package/lib/vectors/DuckDBTimestampNanosecondsVector.js +61 -0
- package/lib/vectors/DuckDBTimestampSecondsVector.d.ts +18 -0
- package/lib/vectors/DuckDBTimestampSecondsVector.js +61 -0
- package/lib/vectors/DuckDBTimestampTZNanosecondsVector.d.ts +18 -0
- package/lib/vectors/DuckDBTimestampTZNanosecondsVector.js +61 -0
- package/lib/vectors/DuckDBTimestampTZVector.d.ts +18 -0
- package/lib/vectors/DuckDBTimestampTZVector.js +61 -0
- package/lib/vectors/DuckDBTimestampVector.d.ts +18 -0
- package/lib/vectors/DuckDBTimestampVector.js +61 -0
- package/lib/vectors/DuckDBTinyIntVector.d.ts +17 -0
- package/lib/vectors/DuckDBTinyIntVector.js +61 -0
- package/lib/vectors/DuckDBTupleVector.d.ts +26 -0
- package/lib/vectors/DuckDBTupleVector.js +91 -0
- package/lib/vectors/DuckDBUBigIntVector.d.ts +17 -0
- package/lib/vectors/DuckDBUBigIntVector.js +58 -0
- package/lib/vectors/DuckDBUHugeIntVector.d.ts +19 -0
- package/lib/vectors/DuckDBUHugeIntVector.js +63 -0
- package/lib/vectors/DuckDBUIntegerVector.d.ts +17 -0
- package/lib/vectors/DuckDBUIntegerVector.js +61 -0
- package/lib/vectors/DuckDBUSmallIntVector.d.ts +17 -0
- package/lib/vectors/DuckDBUSmallIntVector.js +61 -0
- package/lib/vectors/DuckDBUTinyIntVector.d.ts +17 -0
- package/lib/vectors/DuckDBUTinyIntVector.js +61 -0
- package/lib/vectors/DuckDBUUIDVector.d.ts +19 -0
- package/lib/vectors/DuckDBUUIDVector.js +59 -0
- package/lib/vectors/DuckDBUnionVector.d.ts +17 -0
- package/lib/vectors/DuckDBUnionVector.js +70 -0
- package/lib/vectors/DuckDBValidity.d.ts +12 -0
- package/lib/vectors/DuckDBValidity.js +91 -0
- package/lib/vectors/DuckDBVarCharVector.d.ts +21 -0
- package/lib/vectors/DuckDBVarCharVector.js +74 -0
- package/lib/vectors/DuckDBVariantVector.d.ts +42 -0
- package/lib/vectors/DuckDBVariantVector.js +461 -0
- package/lib/vectors/DuckDBVector.d.ts +14 -0
- package/lib/vectors/DuckDBVector.js +27 -0
- package/lib/vectors/createVector.d.ts +1 -0
- package/lib/vectors/createVector.js +201 -0
- package/lib/vectors/dataAccessors.d.ts +45 -0
- package/lib/vectors/dataAccessors.js +344 -0
- package/lib/vectors/index.d.ts +47 -0
- package/lib/vectors/index.js +65 -0
- package/lib/vectors/vectorRegistry.d.ts +20 -0
- package/lib/vectors/vectorRegistry.js +16 -0
- package/package.json +3 -2
- package/lib/DuckDBFunctionInfo.d.ts +0 -10
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unwritableConverter = unwritableConverter;
|
|
4
|
+
exports.nullFromNull = nullFromNull;
|
|
5
|
+
exports.valueFromBoolean = valueFromBoolean;
|
|
6
|
+
exports.valueFromNumber = valueFromNumber;
|
|
7
|
+
exports.bigintFromNumeric = bigintFromNumeric;
|
|
8
|
+
exports.valueFromString = valueFromString;
|
|
9
|
+
exports.blobValueFromBytes = blobValueFromBytes;
|
|
10
|
+
exports.bitValueFromBytes = bitValueFromBytes;
|
|
11
|
+
exports.geometryValueFromBytes = geometryValueFromBytes;
|
|
12
|
+
exports.dateValueFromDate = dateValueFromDate;
|
|
13
|
+
exports.timeValueFromMicros = timeValueFromMicros;
|
|
14
|
+
exports.timeNSValueFromNanos = timeNSValueFromNanos;
|
|
15
|
+
exports.timeTZValueFromObject = timeTZValueFromObject;
|
|
16
|
+
exports.timestampValueFromDate = timestampValueFromDate;
|
|
17
|
+
exports.timestampTZValueFromDate = timestampTZValueFromDate;
|
|
18
|
+
exports.timestampTZNanosValueFromDate = timestampTZNanosValueFromDate;
|
|
19
|
+
exports.timestampSecondsValueFromDate = timestampSecondsValueFromDate;
|
|
20
|
+
exports.timestampMillisValueFromDate = timestampMillisValueFromDate;
|
|
21
|
+
exports.timestampNanosValueFromDate = timestampNanosValueFromDate;
|
|
22
|
+
exports.intervalValueFromObject = intervalValueFromObject;
|
|
23
|
+
exports.decimalValueFromNumeric = decimalValueFromNumeric;
|
|
24
|
+
exports.uuidValueFromString = uuidValueFromString;
|
|
25
|
+
exports.listValueFromArray = listValueFromArray;
|
|
26
|
+
exports.arrayValueFromArray = arrayValueFromArray;
|
|
27
|
+
exports.structValueFromObject = structValueFromObject;
|
|
28
|
+
exports.mapValueFromEntries = mapValueFromEntries;
|
|
29
|
+
exports.unionValueFromObject = unionValueFromObject;
|
|
30
|
+
exports.variantValueFromJS = variantValueFromJS;
|
|
31
|
+
const DuckDBType_1 = require("./DuckDBType");
|
|
32
|
+
const values_1 = require("./values");
|
|
33
|
+
const MILLIS_PER_DAY = 24 * 60 * 60 * 1000;
|
|
34
|
+
/**
|
|
35
|
+
* The epoch milliseconds of `value`, refusing an Invalid Date.
|
|
36
|
+
*
|
|
37
|
+
* Without this, DATE turns NaN into a `DuckDBDateValue(NaN)` and hands it back,
|
|
38
|
+
* while the timestamps reach `BigInt(NaN)` and throw "The number NaN cannot be
|
|
39
|
+
* converted to a BigInt" — neither of which names the real problem.
|
|
40
|
+
*/
|
|
41
|
+
function millisFromDate(value) {
|
|
42
|
+
const millis = value.getTime();
|
|
43
|
+
if (Number.isNaN(millis)) {
|
|
44
|
+
throw new Error(`Cannot convert an Invalid Date`);
|
|
45
|
+
}
|
|
46
|
+
return millis;
|
|
47
|
+
}
|
|
48
|
+
function unwritableConverter(_, type) {
|
|
49
|
+
throw new Error(`Cannot write values of type: ${type}`);
|
|
50
|
+
}
|
|
51
|
+
function nullFromNull() {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
function valueFromBoolean(value) {
|
|
55
|
+
return Boolean(value);
|
|
56
|
+
}
|
|
57
|
+
function valueFromNumber(value) {
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
function bigintFromNumeric(value) {
|
|
61
|
+
return typeof value === 'bigint' ? value : BigInt(value);
|
|
62
|
+
}
|
|
63
|
+
function valueFromString(value) {
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
function blobValueFromBytes(value) {
|
|
67
|
+
return new values_1.DuckDBBlobValue(value);
|
|
68
|
+
}
|
|
69
|
+
function bitValueFromBytes(value) {
|
|
70
|
+
return new values_1.DuckDBBitValue(value);
|
|
71
|
+
}
|
|
72
|
+
function geometryValueFromBytes(value) {
|
|
73
|
+
return new values_1.DuckDBGeometryValue(value);
|
|
74
|
+
}
|
|
75
|
+
function dateValueFromDate(value) {
|
|
76
|
+
// A DATE has no time component; the reader produces midnight UTC, so this is
|
|
77
|
+
// exact for a round trip and truncates toward the earlier day otherwise.
|
|
78
|
+
return new values_1.DuckDBDateValue(Math.floor(millisFromDate(value) / MILLIS_PER_DAY));
|
|
79
|
+
}
|
|
80
|
+
function timeValueFromMicros(value) {
|
|
81
|
+
return new values_1.DuckDBTimeValue(value);
|
|
82
|
+
}
|
|
83
|
+
function timeNSValueFromNanos(value) {
|
|
84
|
+
return new values_1.DuckDBTimeNSValue(value);
|
|
85
|
+
}
|
|
86
|
+
function timeTZValueFromObject(value) {
|
|
87
|
+
return values_1.DuckDBTimeTZValue.fromMicrosAndOffset(value.micros, value.offset);
|
|
88
|
+
}
|
|
89
|
+
function timestampValueFromDate(value) {
|
|
90
|
+
return new values_1.DuckDBTimestampValue(BigInt(millisFromDate(value)) * 1000n);
|
|
91
|
+
}
|
|
92
|
+
function timestampTZValueFromDate(value) {
|
|
93
|
+
return new values_1.DuckDBTimestampTZValue(BigInt(millisFromDate(value)) * 1000n);
|
|
94
|
+
}
|
|
95
|
+
function timestampTZNanosValueFromDate(value) {
|
|
96
|
+
return new values_1.DuckDBTimestampTZNanosecondsValue(BigInt(millisFromDate(value)) * 1000000n);
|
|
97
|
+
}
|
|
98
|
+
function timestampSecondsValueFromDate(value) {
|
|
99
|
+
return new values_1.DuckDBTimestampSecondsValue(BigInt(Math.floor(millisFromDate(value) / 1000)));
|
|
100
|
+
}
|
|
101
|
+
function timestampMillisValueFromDate(value) {
|
|
102
|
+
return new values_1.DuckDBTimestampMillisecondsValue(BigInt(millisFromDate(value)));
|
|
103
|
+
}
|
|
104
|
+
function timestampNanosValueFromDate(value) {
|
|
105
|
+
return new values_1.DuckDBTimestampNanosecondsValue(BigInt(millisFromDate(value)) * 1000000n);
|
|
106
|
+
}
|
|
107
|
+
function intervalValueFromObject(value) {
|
|
108
|
+
return new values_1.DuckDBIntervalValue(value.months, value.days, value.micros);
|
|
109
|
+
}
|
|
110
|
+
function decimalValueFromNumeric(value, type) {
|
|
111
|
+
if (!(type instanceof DuckDBType_1.DuckDBDecimalType)) {
|
|
112
|
+
throw new Error(`Expected DuckDBDecimalType`);
|
|
113
|
+
}
|
|
114
|
+
return typeof value === 'bigint'
|
|
115
|
+
? new values_1.DuckDBDecimalValue(value, type.width, type.scale)
|
|
116
|
+
: values_1.DuckDBDecimalValue.fromDouble(value, type.width, type.scale);
|
|
117
|
+
}
|
|
118
|
+
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
119
|
+
function uuidValueFromString(value) {
|
|
120
|
+
if (!UUID_PATTERN.test(value)) {
|
|
121
|
+
throw new Error(`Not a UUID string: ${value}`);
|
|
122
|
+
}
|
|
123
|
+
return values_1.DuckDBUUIDValue.fromUint128(BigInt(`0x${value.replace(/-/g, '')}`));
|
|
124
|
+
}
|
|
125
|
+
function listValueFromArray(value, type, converter) {
|
|
126
|
+
if (!(type instanceof DuckDBType_1.DuckDBListType)) {
|
|
127
|
+
throw new Error(`Expected DuckDBListType`);
|
|
128
|
+
}
|
|
129
|
+
return (0, values_1.listValue)(value.map((item) => converter(item, type.valueType, converter)));
|
|
130
|
+
}
|
|
131
|
+
function arrayValueFromArray(value, type, converter) {
|
|
132
|
+
if (!(type instanceof DuckDBType_1.DuckDBArrayType)) {
|
|
133
|
+
throw new Error(`Expected DuckDBArrayType`);
|
|
134
|
+
}
|
|
135
|
+
if (value.length !== type.length) {
|
|
136
|
+
throw new Error(`Expected ${type.length} items for ${type}, got ${value.length}`);
|
|
137
|
+
}
|
|
138
|
+
return (0, values_1.arrayValue)(value.map((item) => converter(item, type.valueType, converter)));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Converts an object keyed by entry name to a named STRUCT value, or an array
|
|
142
|
+
* of items to a tuple value (see `DuckDBStructType.isTuple`).
|
|
143
|
+
*/
|
|
144
|
+
function structValueFromObject(value, type, converter) {
|
|
145
|
+
if (!(type instanceof DuckDBType_1.DuckDBStructType)) {
|
|
146
|
+
throw new Error(`Expected DuckDBStructType`);
|
|
147
|
+
}
|
|
148
|
+
if (type.isTuple) {
|
|
149
|
+
if (!Array.isArray(value)) {
|
|
150
|
+
throw new Error(`Expected an array for ${type}`);
|
|
151
|
+
}
|
|
152
|
+
if (value.length !== type.entryCount) {
|
|
153
|
+
throw new Error(`Expected ${type.entryCount} items for ${type}, got ${value.length}`);
|
|
154
|
+
}
|
|
155
|
+
return (0, values_1.tupleValue)(value.map((item, i) => converter(item, type.entryTypes[i], converter)));
|
|
156
|
+
}
|
|
157
|
+
if (Array.isArray(value)) {
|
|
158
|
+
throw new Error(`Expected an object for ${type}`);
|
|
159
|
+
}
|
|
160
|
+
const entryValues = value;
|
|
161
|
+
const entries = {};
|
|
162
|
+
for (const key of type.entryNames) {
|
|
163
|
+
if (!(key in entryValues)) {
|
|
164
|
+
throw new Error(`Missing entry for struct key: ${key}`);
|
|
165
|
+
}
|
|
166
|
+
entries[key] = converter(entryValues[key], type.typeForEntry(key), converter);
|
|
167
|
+
}
|
|
168
|
+
return (0, values_1.structValue)(entries);
|
|
169
|
+
}
|
|
170
|
+
function mapValueFromEntries(value, type, converter) {
|
|
171
|
+
if (!(type instanceof DuckDBType_1.DuckDBMapType)) {
|
|
172
|
+
throw new Error(`Expected DuckDBMapType`);
|
|
173
|
+
}
|
|
174
|
+
return (0, values_1.mapValue)(value.map((entry) => ({
|
|
175
|
+
key: converter(entry.key, type.keyType, converter),
|
|
176
|
+
value: converter(entry.value, type.valueType, converter),
|
|
177
|
+
})));
|
|
178
|
+
}
|
|
179
|
+
function unionValueFromObject(value, type, converter) {
|
|
180
|
+
if (!(type instanceof DuckDBType_1.DuckDBUnionType)) {
|
|
181
|
+
throw new Error(`Expected DuckDBUnionType`);
|
|
182
|
+
}
|
|
183
|
+
// memberTypeForTag indexes by tag and returns undefined for one it does not
|
|
184
|
+
// have, which would reach the dispatch as an undefined type. Unlike the read
|
|
185
|
+
// path, where the tag comes from a decoded value, here it is caller input.
|
|
186
|
+
if (!(value.tag in type.tagMemberIndexes)) {
|
|
187
|
+
throw new Error(`Tag ${JSON.stringify(value.tag)} is not a member of ${type}`);
|
|
188
|
+
}
|
|
189
|
+
return (0, values_1.unionValue)(value.tag, converter(value.value, type.memberTypeForTag(value.tag), converter));
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* A VARIANT carries the type of the value inside it, so writing one means
|
|
193
|
+
* saying what that type is. A `DuckDBVariantValue` already does — pass it
|
|
194
|
+
* through. A bare scalar does not, but is unambiguous enough for
|
|
195
|
+
* `typeForValue` to infer downstream, so wrap it.
|
|
196
|
+
*/
|
|
197
|
+
function variantValueFromJS(value) {
|
|
198
|
+
return value instanceof values_1.DuckDBVariantValue ? value : (0, values_1.variantValue)(value);
|
|
199
|
+
}
|
|
@@ -12,9 +12,9 @@ export declare function getDuckDBTimeStringFromMicrosecondsInDay(microsecondsInD
|
|
|
12
12
|
export declare function getDuckDBTimeStringFromNanosecondsInDay(nanosecondsInDay: bigint): string;
|
|
13
13
|
export declare function getDuckDBTimeStringFromMicroseconds(microseconds: bigint): string;
|
|
14
14
|
export declare function getDuckDBTimestampStringFromDaysAndMicroseconds(days: bigint, microsecondsInDay: bigint, timezonePart?: string): string;
|
|
15
|
-
export declare function getDuckDBTimestampStringFromDaysAndNanoseconds(days: bigint, nanosecondsInDay: bigint): string;
|
|
15
|
+
export declare function getDuckDBTimestampStringFromDaysAndNanoseconds(days: bigint, nanosecondsInDay: bigint, timezonePart?: string): string;
|
|
16
16
|
export declare function getDuckDBTimestampStringFromMicroseconds(microseconds: bigint, timezoneOffsetInMinutes?: number): string;
|
|
17
17
|
export declare function getDuckDBTimestampStringFromSeconds(seconds: bigint): string;
|
|
18
18
|
export declare function getDuckDBTimestampStringFromMilliseconds(milliseconds: bigint): string;
|
|
19
|
-
export declare function getDuckDBTimestampStringFromNanoseconds(nanoseconds: bigint): string;
|
|
19
|
+
export declare function getDuckDBTimestampStringFromNanoseconds(nanoseconds: bigint, timezoneOffsetInMinutes?: number): string;
|
|
20
20
|
export declare function getDuckDBIntervalString(months: number, days: number, microseconds: bigint): string;
|
|
@@ -53,7 +53,7 @@ function getDuckDBDateStringFromDays(days) {
|
|
|
53
53
|
const millisecondsFromRemainingInterval = sign * absDaysFromRemainingInterval * MILLISECONDS_PER_DAY_NUM;
|
|
54
54
|
const date = new Date(millisecondsFromRemainingInterval);
|
|
55
55
|
let year = yearsFrom400YearIntervals + date.getUTCFullYear();
|
|
56
|
-
if (year
|
|
56
|
+
if (year <= 0) {
|
|
57
57
|
year--; // correct for non-existence of year zero
|
|
58
58
|
}
|
|
59
59
|
const month = date.getUTCMonth() + 1; // getUTCMonth returns zero-indexed month, but we want a one-index month for display
|
|
@@ -161,12 +161,12 @@ function getDuckDBTimestampStringFromDaysAndMicroseconds(days, microsecondsInDay
|
|
|
161
161
|
const timeStr = getDuckDBTimeStringFromMicrosecondsInDay(microsecondsInDay);
|
|
162
162
|
return `${dateStr} ${timeStr}${timezonePart ?? ''}`;
|
|
163
163
|
}
|
|
164
|
-
function getDuckDBTimestampStringFromDaysAndNanoseconds(days, nanosecondsInDay) {
|
|
164
|
+
function getDuckDBTimestampStringFromDaysAndNanoseconds(days, nanosecondsInDay, timezonePart) {
|
|
165
165
|
// This conversion of BigInt to Number is safe, because the largest absolute value that `days` can has is 106751
|
|
166
166
|
// which fits without loss of precision in a JS Number. (106751 = (2^63-1) / NANOSECONDS_PER_DAY)
|
|
167
167
|
const dateStr = getDuckDBDateStringFromDays(Number(days));
|
|
168
168
|
const timeStr = getDuckDBTimeStringFromNanosecondsInDay(nanosecondsInDay);
|
|
169
|
-
return `${dateStr} ${timeStr}`;
|
|
169
|
+
return `${dateStr} ${timeStr}${timezonePart ?? ''}`;
|
|
170
170
|
}
|
|
171
171
|
function getDuckDBTimestampStringFromMicroseconds(microseconds, timezoneOffsetInMinutes) {
|
|
172
172
|
// Note that -infinity and infinity are only representable in TIMESTAMP (and TIMESTAMPTZ), not the other timestamp
|
|
@@ -197,14 +197,27 @@ function getDuckDBTimestampStringFromSeconds(seconds) {
|
|
|
197
197
|
function getDuckDBTimestampStringFromMilliseconds(milliseconds) {
|
|
198
198
|
return getDuckDBTimestampStringFromMicroseconds(milliseconds * MICROSECONDS_PER_MILLISECOND);
|
|
199
199
|
}
|
|
200
|
-
function getDuckDBTimestampStringFromNanoseconds(nanoseconds) {
|
|
201
|
-
|
|
202
|
-
|
|
200
|
+
function getDuckDBTimestampStringFromNanoseconds(nanoseconds, timezoneOffsetInMinutes) {
|
|
201
|
+
// TIMESTAMP_NS and TIMESTAMPTZ_NS use the same infinity values as TIMESTAMP.
|
|
202
|
+
if (nanoseconds === NEGATIVE_INFINITY_TIMESTAMP) {
|
|
203
|
+
return '-infinity';
|
|
204
|
+
}
|
|
205
|
+
if (nanoseconds === POSITIVE_INFINITY_TIMESTAMP) {
|
|
206
|
+
return 'infinity';
|
|
207
|
+
}
|
|
208
|
+
const offsetNanoseconds = timezoneOffsetInMinutes !== undefined
|
|
209
|
+
? nanoseconds +
|
|
210
|
+
BigInt(timezoneOffsetInMinutes) *
|
|
211
|
+
NANOSECONDS_PER_SECOND *
|
|
212
|
+
SECONDS_PER_MINUTE
|
|
213
|
+
: nanoseconds;
|
|
214
|
+
let days = offsetNanoseconds / NANOSECONDS_PER_DAY;
|
|
215
|
+
let nanosecondsPart = offsetNanoseconds % NANOSECONDS_PER_DAY;
|
|
203
216
|
if (nanosecondsPart < 0) {
|
|
204
217
|
days--;
|
|
205
218
|
nanosecondsPart += NANOSECONDS_PER_DAY;
|
|
206
219
|
}
|
|
207
|
-
return getDuckDBTimestampStringFromDaysAndNanoseconds(days, nanosecondsPart);
|
|
220
|
+
return getDuckDBTimestampStringFromDaysAndNanoseconds(days, nanosecondsPart, getTimezoneOffsetString(timezoneOffsetInMinutes));
|
|
208
221
|
}
|
|
209
222
|
// Assumes baseUnit can be pluralized by adding an 's'.
|
|
210
223
|
function numberAndUnit(value, baseUnit) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes an unsigned LEB128 (little-endian base-128) varint at
|
|
3
|
+
* `view[offset]`. Each byte contributes 7 bits of payload; the high bit is
|
|
4
|
+
* a continuation flag.
|
|
5
|
+
*
|
|
6
|
+
* Returns the decoded `value` and the byte position `nextOffset` immediately
|
|
7
|
+
* after the varint. Throws if the varint:
|
|
8
|
+
* - reads past the end of `view` (truncated),
|
|
9
|
+
* - exceeds 2**32-1 (overflow).
|
|
10
|
+
*
|
|
11
|
+
* Uses arithmetic (not bitwise) accumulation so values up to 2**32-1
|
|
12
|
+
* round-trip correctly — JS bitwise operators coerce to signed int32 and
|
|
13
|
+
* would turn 0xffffffff into -1.
|
|
14
|
+
*/
|
|
15
|
+
export declare function varintDecode(view: DataView, offset: number): {
|
|
16
|
+
value: number;
|
|
17
|
+
nextOffset: number;
|
|
18
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.varintDecode = varintDecode;
|
|
4
|
+
/**
|
|
5
|
+
* Decodes an unsigned LEB128 (little-endian base-128) varint at
|
|
6
|
+
* `view[offset]`. Each byte contributes 7 bits of payload; the high bit is
|
|
7
|
+
* a continuation flag.
|
|
8
|
+
*
|
|
9
|
+
* Returns the decoded `value` and the byte position `nextOffset` immediately
|
|
10
|
+
* after the varint. Throws if the varint:
|
|
11
|
+
* - reads past the end of `view` (truncated),
|
|
12
|
+
* - exceeds 2**32-1 (overflow).
|
|
13
|
+
*
|
|
14
|
+
* Uses arithmetic (not bitwise) accumulation so values up to 2**32-1
|
|
15
|
+
* round-trip correctly — JS bitwise operators coerce to signed int32 and
|
|
16
|
+
* would turn 0xffffffff into -1.
|
|
17
|
+
*/
|
|
18
|
+
function varintDecode(view, offset) {
|
|
19
|
+
let value = 0;
|
|
20
|
+
let multiplier = 1;
|
|
21
|
+
let cur = offset;
|
|
22
|
+
while (true) {
|
|
23
|
+
if (cur >= view.byteLength) {
|
|
24
|
+
throw new Error('varint truncated');
|
|
25
|
+
}
|
|
26
|
+
const byte = view.getUint8(cur++);
|
|
27
|
+
value += (byte & 0x7f) * multiplier;
|
|
28
|
+
if ((byte & 0x80) === 0) {
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
multiplier *= 128;
|
|
32
|
+
if (multiplier > 0x80000000) {
|
|
33
|
+
// multiplier == 128**5 means we're about to process a 6th byte —
|
|
34
|
+
// even a single payload bit beyond would push past 2**32-1.
|
|
35
|
+
throw new Error('varint overflow');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (value > 0xffffffff) {
|
|
39
|
+
throw new Error('varint overflow');
|
|
40
|
+
}
|
|
41
|
+
return { value, nextOffset: cur };
|
|
42
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { DuckDBDataChunk } from './DuckDBDataChunk';
|
|
2
2
|
import { DuckDBValueConverter } from './DuckDBValueConverter';
|
|
3
|
-
export declare function convertColumnsFromChunks<T>(chunks: readonly DuckDBDataChunk[], converter: DuckDBValueConverter<T>): (T | null)[][];
|
|
3
|
+
export declare function convertColumnsFromChunks<T>(chunks: readonly DuckDBDataChunk[], columnCount: number, converter: DuckDBValueConverter<T>): (T | null)[][];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertColumnsFromChunks = convertColumnsFromChunks;
|
|
4
|
-
function convertColumnsFromChunks(chunks, converter) {
|
|
4
|
+
function convertColumnsFromChunks(chunks, columnCount, converter) {
|
|
5
5
|
if (chunks.length === 0) {
|
|
6
|
-
return [];
|
|
6
|
+
return Array.from({ length: columnCount }, () => []);
|
|
7
7
|
}
|
|
8
8
|
const convertedColumns = chunks[0].convertColumns(converter);
|
|
9
9
|
for (let chunkIndex = 1; chunkIndex < chunks.length; chunkIndex++) {
|
package/lib/createResult.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import duckdb from '@haybarn/node-bindings';
|
|
2
2
|
import { DuckDBResult } from './DuckDBResult';
|
|
3
|
-
|
|
3
|
+
import { StatementType } from './enums';
|
|
4
|
+
export declare function createResult(result: duckdb.Result, preparedStatementType?: StatementType): DuckDBResult;
|
package/lib/createResult.js
CHANGED
|
@@ -7,11 +7,11 @@ exports.createResult = createResult;
|
|
|
7
7
|
const node_bindings_1 = __importDefault(require("@haybarn/node-bindings"));
|
|
8
8
|
const DuckDBMaterializedResult_1 = require("./DuckDBMaterializedResult");
|
|
9
9
|
const DuckDBResult_1 = require("./DuckDBResult");
|
|
10
|
-
function createResult(result) {
|
|
10
|
+
function createResult(result, preparedStatementType) {
|
|
11
11
|
if (node_bindings_1.default.result_is_streaming(result)) {
|
|
12
|
-
return new DuckDBResult_1.DuckDBResult(result);
|
|
12
|
+
return new DuckDBResult_1.DuckDBResult(result, preparedStatementType);
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
|
-
return new DuckDBMaterializedResult_1.DuckDBMaterializedResult(result);
|
|
15
|
+
return new DuckDBMaterializedResult_1.DuckDBMaterializedResult(result, preparedStatementType);
|
|
16
16
|
}
|
|
17
17
|
}
|
package/lib/createValue.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createValue = createValue;
|
|
7
7
|
const node_bindings_1 = __importDefault(require("@haybarn/node-bindings"));
|
|
8
8
|
const DuckDBTypeId_1 = require("./DuckDBTypeId");
|
|
9
|
+
const typeForValue_1 = require("./typeForValue");
|
|
9
10
|
const values_1 = require("./values");
|
|
10
11
|
function createValue(type, input) {
|
|
11
12
|
if (input === null) {
|
|
@@ -34,8 +35,8 @@ function createValue(type, input) {
|
|
|
34
35
|
}
|
|
35
36
|
throw new Error(`input is not a number`);
|
|
36
37
|
case DuckDBTypeId_1.DuckDBTypeId.BIGINT:
|
|
37
|
-
if (typeof input === 'bigint') {
|
|
38
|
-
return node_bindings_1.default.create_int64(input);
|
|
38
|
+
if (typeof input === 'bigint' || typeof input === 'number') {
|
|
39
|
+
return node_bindings_1.default.create_int64(BigInt(input));
|
|
39
40
|
}
|
|
40
41
|
throw new Error(`input is not a bigint`);
|
|
41
42
|
case DuckDBTypeId_1.DuckDBTypeId.UTINYINT:
|
|
@@ -54,8 +55,8 @@ function createValue(type, input) {
|
|
|
54
55
|
}
|
|
55
56
|
throw new Error(`input is not a number`);
|
|
56
57
|
case DuckDBTypeId_1.DuckDBTypeId.UBIGINT:
|
|
57
|
-
if (typeof input === 'bigint') {
|
|
58
|
-
return node_bindings_1.default.create_uint64(input);
|
|
58
|
+
if (typeof input === 'bigint' || typeof input === 'number') {
|
|
59
|
+
return node_bindings_1.default.create_uint64(BigInt(input));
|
|
59
60
|
}
|
|
60
61
|
throw new Error(`input is not a bigint`);
|
|
61
62
|
case DuckDBTypeId_1.DuckDBTypeId.FLOAT:
|
|
@@ -142,11 +143,32 @@ function createValue(type, input) {
|
|
|
142
143
|
}
|
|
143
144
|
throw new Error(`input is not a DuckDBListValue`);
|
|
144
145
|
case DuckDBTypeId_1.DuckDBTypeId.STRUCT:
|
|
146
|
+
if (type.isTuple) {
|
|
147
|
+
if (input instanceof values_1.DuckDBTupleValue) {
|
|
148
|
+
if (type.entryTypes.find((entryType) => entryType.typeId === DuckDBTypeId_1.DuckDBTypeId.ANY)) {
|
|
149
|
+
throw new Error('Cannot create tuples with an entry type of ANY. Specify a specific type.');
|
|
150
|
+
}
|
|
151
|
+
if (input.items.length !== type.entryCount) {
|
|
152
|
+
throw new Error(`Expected ${type.entryCount} items for ${type}, got ${input.items.length}`);
|
|
153
|
+
}
|
|
154
|
+
return node_bindings_1.default.create_struct_value(type.toLogicalType().logical_type, input.items.map((item, i) => createValue(type.entryTypes[i], item)));
|
|
155
|
+
}
|
|
156
|
+
throw new Error(`input is not a DuckDBTupleValue`);
|
|
157
|
+
}
|
|
145
158
|
if (input instanceof values_1.DuckDBStructValue) {
|
|
146
159
|
if (type.entryTypes.find((entryType) => entryType.typeId === DuckDBTypeId_1.DuckDBTypeId.ANY)) {
|
|
147
160
|
throw new Error('Cannot create structs with an entry type of ANY. Specify a specific type.');
|
|
148
161
|
}
|
|
149
|
-
|
|
162
|
+
// Pair entries by name rather than positionally so that
|
|
163
|
+
// `structValue({b: 'x', a: 1})` against `STRUCT({a: INTEGER, b:
|
|
164
|
+
// VARCHAR})` doesn't silently mispair when the value's insertion
|
|
165
|
+
// order differs from the type's declared field order.
|
|
166
|
+
return node_bindings_1.default.create_struct_value(type.toLogicalType().logical_type, type.entryNames.map((name, i) => {
|
|
167
|
+
if (!(name in input.entries)) {
|
|
168
|
+
throw new Error(`STRUCT entry '${name}' is missing from input`);
|
|
169
|
+
}
|
|
170
|
+
return createValue(type.entryTypes[i], input.entries[name]);
|
|
171
|
+
}));
|
|
150
172
|
}
|
|
151
173
|
throw new Error(`input is not a DuckDBStructValue`);
|
|
152
174
|
case DuckDBTypeId_1.DuckDBTypeId.MAP:
|
|
@@ -198,6 +220,11 @@ function createValue(type, input) {
|
|
|
198
220
|
return node_bindings_1.default.create_timestamp_tz(input);
|
|
199
221
|
}
|
|
200
222
|
throw new Error(`input is not a DuckDBTimestampTZValue`);
|
|
223
|
+
case DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_TZ_NS:
|
|
224
|
+
if (input instanceof values_1.DuckDBTimestampTZNanosecondsValue) {
|
|
225
|
+
return node_bindings_1.default.create_timestamp_tz_ns(input);
|
|
226
|
+
}
|
|
227
|
+
throw new Error(`input is not a DuckDBTimestampTZNanosecondsValue`);
|
|
201
228
|
case DuckDBTypeId_1.DuckDBTypeId.ANY:
|
|
202
229
|
throw new Error(`Cannot create values of type ANY. Specify a specific type.`);
|
|
203
230
|
case DuckDBTypeId_1.DuckDBTypeId.BIGNUM:
|
|
@@ -216,6 +243,37 @@ function createValue(type, input) {
|
|
|
216
243
|
return node_bindings_1.default.create_time_ns(input);
|
|
217
244
|
}
|
|
218
245
|
throw new Error(`input is not a DuckDBTimeNSValue`);
|
|
246
|
+
case DuckDBTypeId_1.DuckDBTypeId.GEOMETRY:
|
|
247
|
+
if (input instanceof values_1.DuckDBGeometryValue) {
|
|
248
|
+
throw new Error(`Creating values of type GEOMETRY is not yet supported.`);
|
|
249
|
+
// TODO: create_geometry doesn't exist; create_blob results in Failed to cast value: Unimplemented type for cast (BLOB -> GEOMETRY)
|
|
250
|
+
// return duckdb.create_blob(input.bytes);
|
|
251
|
+
}
|
|
252
|
+
throw new Error(`input is not a DuckDBGeometryValue`);
|
|
253
|
+
case DuckDBTypeId_1.DuckDBTypeId.VARIANT: {
|
|
254
|
+
// VARIANT has no direct create primitive in the C API; DuckDB
|
|
255
|
+
// implicitly casts from any compatible type when the target column
|
|
256
|
+
// or parameter is VARIANT. Recurse on the input's natural type so
|
|
257
|
+
// we hand DuckDB a Value it can cast.
|
|
258
|
+
//
|
|
259
|
+
// If the input is a DuckDBVariantValue, prefer its embedded `.type`
|
|
260
|
+
// (set by the decoder from the on-disk variant tag) so heterogeneous
|
|
261
|
+
// content round-trips faithfully. Fall back to `typeForValue` when
|
|
262
|
+
// no type hint is attached. The recursion is wrapped so a
|
|
263
|
+
// mismatched wrapper (e.g. `variantValue('hello', INTEGER)`)
|
|
264
|
+
// surfaces a VARIANT-flavored error rather than a confusing
|
|
265
|
+
// `input is not a number` from a sibling case.
|
|
266
|
+
const inner = input instanceof values_1.DuckDBVariantValue ? input.value : input;
|
|
267
|
+
const innerType = input instanceof values_1.DuckDBVariantValue && input.type
|
|
268
|
+
? input.type
|
|
269
|
+
: (0, typeForValue_1.typeForValue)(inner);
|
|
270
|
+
try {
|
|
271
|
+
return createValue(innerType, inner);
|
|
272
|
+
}
|
|
273
|
+
catch (err) {
|
|
274
|
+
throw new Error(`Failed to create VARIANT value (inner type ${innerType}): ${err.message}`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
219
277
|
default:
|
|
220
278
|
throw new Error(`unrecognized type id ${typeId}`);
|
|
221
279
|
}
|
package/lib/duckdb.d.ts
CHANGED
|
@@ -2,12 +2,11 @@ export { double_to_hugeint, double_to_uhugeint, hugeint_to_double, uhugeint_to_d
|
|
|
2
2
|
export * from './configurationOptionDescriptions';
|
|
3
3
|
export * from './createDuckDBValueConverter';
|
|
4
4
|
export * from './DuckDBAppender';
|
|
5
|
-
export * from './DuckDBBindInfo';
|
|
6
5
|
export * from './DuckDBClientContext';
|
|
7
6
|
export * from './DuckDBConnection';
|
|
8
7
|
export * from './DuckDBDataChunk';
|
|
8
|
+
export * from './DuckDBDataChunkWriter';
|
|
9
9
|
export * from './DuckDBExtractedStatements';
|
|
10
|
-
export * from './DuckDBFunctionInfo';
|
|
11
10
|
export * from './DuckDBInstance';
|
|
12
11
|
export * from './DuckDBInstanceCache';
|
|
13
12
|
export * from './DuckDBLogicalType';
|
|
@@ -18,16 +17,30 @@ export * from './DuckDBPreparedStatementCollection';
|
|
|
18
17
|
export * from './DuckDBResult';
|
|
19
18
|
export * from './DuckDBResultReader';
|
|
20
19
|
export * from './DuckDBScalarFunction';
|
|
20
|
+
export * from './DuckDBScalarFunctionBindInfo';
|
|
21
|
+
export * from './DuckDBScalarFunctionInfo';
|
|
22
|
+
export * from './DuckDBScalarFunctionInitInfo';
|
|
23
|
+
export * from './DuckDBTableFunction';
|
|
24
|
+
export * from './DuckDBTableFunctionBindInfo';
|
|
25
|
+
export * from './DuckDBTableFunctionInfo';
|
|
26
|
+
export * from './DuckDBTableFunctionInitInfo';
|
|
21
27
|
export * from './DuckDBType';
|
|
22
28
|
export * from './DuckDBTypeId';
|
|
23
29
|
export * from './DuckDBValueConverter';
|
|
24
30
|
export * from './DuckDBValueConverters';
|
|
25
31
|
export * from './DuckDBVector';
|
|
32
|
+
export * from './ToDuckDBValueConverter';
|
|
33
|
+
export * from './ToDuckDBValueConverters';
|
|
26
34
|
export * from './enums';
|
|
27
35
|
export * from './JS';
|
|
28
36
|
export * from './JSDuckDBValueConverter';
|
|
37
|
+
export * from './JSInputTypeForTypeId';
|
|
38
|
+
export * from './JSToDuckDBValueConverter';
|
|
39
|
+
export * from './JSTypeForTypeId';
|
|
29
40
|
export * from './Json';
|
|
30
41
|
export * from './JsonDuckDBValueConverter';
|
|
42
|
+
export * from './JsonTypeForTypeId';
|
|
43
|
+
export * from './readValue';
|
|
31
44
|
export * from './sql';
|
|
32
45
|
export * from './values';
|
|
33
46
|
export * from './version';
|
package/lib/duckdb.js
CHANGED
|
@@ -23,12 +23,11 @@ Object.defineProperty(exports, "uhugeint_to_double", { enumerable: true, get: fu
|
|
|
23
23
|
__exportStar(require("./configurationOptionDescriptions"), exports);
|
|
24
24
|
__exportStar(require("./createDuckDBValueConverter"), exports);
|
|
25
25
|
__exportStar(require("./DuckDBAppender"), exports);
|
|
26
|
-
__exportStar(require("./DuckDBBindInfo"), exports);
|
|
27
26
|
__exportStar(require("./DuckDBClientContext"), exports);
|
|
28
27
|
__exportStar(require("./DuckDBConnection"), exports);
|
|
29
28
|
__exportStar(require("./DuckDBDataChunk"), exports);
|
|
29
|
+
__exportStar(require("./DuckDBDataChunkWriter"), exports);
|
|
30
30
|
__exportStar(require("./DuckDBExtractedStatements"), exports);
|
|
31
|
-
__exportStar(require("./DuckDBFunctionInfo"), exports);
|
|
32
31
|
__exportStar(require("./DuckDBInstance"), exports);
|
|
33
32
|
__exportStar(require("./DuckDBInstanceCache"), exports);
|
|
34
33
|
__exportStar(require("./DuckDBLogicalType"), exports);
|
|
@@ -39,16 +38,30 @@ __exportStar(require("./DuckDBPreparedStatementCollection"), exports);
|
|
|
39
38
|
__exportStar(require("./DuckDBResult"), exports);
|
|
40
39
|
__exportStar(require("./DuckDBResultReader"), exports);
|
|
41
40
|
__exportStar(require("./DuckDBScalarFunction"), exports);
|
|
41
|
+
__exportStar(require("./DuckDBScalarFunctionBindInfo"), exports);
|
|
42
|
+
__exportStar(require("./DuckDBScalarFunctionInfo"), exports);
|
|
43
|
+
__exportStar(require("./DuckDBScalarFunctionInitInfo"), exports);
|
|
44
|
+
__exportStar(require("./DuckDBTableFunction"), exports);
|
|
45
|
+
__exportStar(require("./DuckDBTableFunctionBindInfo"), exports);
|
|
46
|
+
__exportStar(require("./DuckDBTableFunctionInfo"), exports);
|
|
47
|
+
__exportStar(require("./DuckDBTableFunctionInitInfo"), exports);
|
|
42
48
|
__exportStar(require("./DuckDBType"), exports);
|
|
43
49
|
__exportStar(require("./DuckDBTypeId"), exports);
|
|
44
50
|
__exportStar(require("./DuckDBValueConverter"), exports);
|
|
45
51
|
__exportStar(require("./DuckDBValueConverters"), exports);
|
|
46
52
|
__exportStar(require("./DuckDBVector"), exports);
|
|
53
|
+
__exportStar(require("./ToDuckDBValueConverter"), exports);
|
|
54
|
+
__exportStar(require("./ToDuckDBValueConverters"), exports);
|
|
47
55
|
__exportStar(require("./enums"), exports);
|
|
48
56
|
__exportStar(require("./JS"), exports);
|
|
49
57
|
__exportStar(require("./JSDuckDBValueConverter"), exports);
|
|
58
|
+
__exportStar(require("./JSInputTypeForTypeId"), exports);
|
|
59
|
+
__exportStar(require("./JSToDuckDBValueConverter"), exports);
|
|
60
|
+
__exportStar(require("./JSTypeForTypeId"), exports);
|
|
50
61
|
__exportStar(require("./Json"), exports);
|
|
51
62
|
__exportStar(require("./JsonDuckDBValueConverter"), exports);
|
|
63
|
+
__exportStar(require("./JsonTypeForTypeId"), exports);
|
|
64
|
+
__exportStar(require("./readValue"), exports);
|
|
52
65
|
__exportStar(require("./sql"), exports);
|
|
53
66
|
__exportStar(require("./values"), exports);
|
|
54
67
|
__exportStar(require("./version"), exports);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { DuckDBDataChunk } from './DuckDBDataChunk';
|
|
2
2
|
import { DuckDBValue } from './values';
|
|
3
|
-
export declare function getColumnsFromChunks(chunks: readonly DuckDBDataChunk[]): DuckDBValue[][];
|
|
3
|
+
export declare function getColumnsFromChunks(chunks: readonly DuckDBDataChunk[], columnCount: number): DuckDBValue[][];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getColumnsFromChunks = getColumnsFromChunks;
|
|
4
|
-
function getColumnsFromChunks(chunks) {
|
|
5
|
-
const columns = [];
|
|
4
|
+
function getColumnsFromChunks(chunks, columnCount) {
|
|
5
|
+
const columns = Array.from({ length: columnCount }, () => []);
|
|
6
6
|
for (const chunk of chunks) {
|
|
7
7
|
chunk.appendToColumns(columns);
|
|
8
8
|
}
|
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getColumnsObjectFromChunks = getColumnsObjectFromChunks;
|
|
4
4
|
function getColumnsObjectFromChunks(chunks, columnNames) {
|
|
5
5
|
const columnsObject = {};
|
|
6
|
+
for (const columnName of columnNames) {
|
|
7
|
+
columnsObject[columnName] = [];
|
|
8
|
+
}
|
|
6
9
|
for (const chunk of chunks) {
|
|
7
10
|
chunk.appendToColumnsObject(columnNames, columnsObject);
|
|
8
11
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Value } from '@haybarn/node-bindings';
|
|
2
|
+
import { DuckDBValue } from './values';
|
|
3
|
+
/**
|
|
4
|
+
* Converts a `duckdb.Value` into a `DuckDBValue`.
|
|
5
|
+
*
|
|
6
|
+
* Results normally arrive as vectors rather than values, so this is for the
|
|
7
|
+
* places that hand back a value instead: table function parameters, and
|
|
8
|
+
* `duckdb_get_table_names`.
|
|
9
|
+
*
|
|
10
|
+
* It works by referencing the value into a vector of its own and reading the one
|
|
11
|
+
* element back, which reuses the vector reading path rather than duplicating it.
|
|
12
|
+
* That matters for more than tidiness: the value accessors cannot reach inside an
|
|
13
|
+
* ARRAY or a UNION at all, because `duckdb_get_list_child` and
|
|
14
|
+
* `duckdb_get_struct_child` guard on the exact logical type id and return null
|
|
15
|
+
* for both. Going through a vector covers every type, and leaves one
|
|
16
|
+
* implementation of how each type is represented rather than two that can drift.
|
|
17
|
+
*
|
|
18
|
+
* The cost is roughly an extra microsecond per scalar value, which is fine here
|
|
19
|
+
* and would not be in a per-row path. Per-row data already arrives as vectors and
|
|
20
|
+
* never comes through here.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readValue(value: Value): DuckDBValue;
|