@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
|
@@ -31,7 +31,7 @@ const JSConvertersByTypeId = {
|
|
|
31
31
|
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_NS]: DuckDBValueConverters_1.dateFromTimestampNanosecondsValue,
|
|
32
32
|
[DuckDBTypeId_1.DuckDBTypeId.ENUM]: DuckDBValueConverters_1.stringFromValue,
|
|
33
33
|
[DuckDBTypeId_1.DuckDBTypeId.LIST]: DuckDBValueConverters_1.arrayFromListValue,
|
|
34
|
-
[DuckDBTypeId_1.DuckDBTypeId.STRUCT]: DuckDBValueConverters_1.
|
|
34
|
+
[DuckDBTypeId_1.DuckDBTypeId.STRUCT]: DuckDBValueConverters_1.objectOrArrayFromStructValue,
|
|
35
35
|
[DuckDBTypeId_1.DuckDBTypeId.MAP]: DuckDBValueConverters_1.objectArrayFromMapValue,
|
|
36
36
|
[DuckDBTypeId_1.DuckDBTypeId.ARRAY]: DuckDBValueConverters_1.arrayFromArrayValue,
|
|
37
37
|
[DuckDBTypeId_1.DuckDBTypeId.UUID]: DuckDBValueConverters_1.stringFromValue,
|
|
@@ -44,6 +44,9 @@ const JSConvertersByTypeId = {
|
|
|
44
44
|
[DuckDBTypeId_1.DuckDBTypeId.SQLNULL]: DuckDBValueConverters_1.nullConverter,
|
|
45
45
|
[DuckDBTypeId_1.DuckDBTypeId.STRING_LITERAL]: DuckDBValueConverters_1.unsupportedConverter,
|
|
46
46
|
[DuckDBTypeId_1.DuckDBTypeId.INTEGER_LITERAL]: DuckDBValueConverters_1.unsupportedConverter,
|
|
47
|
-
[DuckDBTypeId_1.DuckDBTypeId.TIME_NS]: DuckDBValueConverters_1.
|
|
47
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIME_NS]: DuckDBValueConverters_1.bigintFromTimeNSValue,
|
|
48
|
+
[DuckDBTypeId_1.DuckDBTypeId.GEOMETRY]: DuckDBValueConverters_1.bytesFromGeometryValue,
|
|
49
|
+
[DuckDBTypeId_1.DuckDBTypeId.VARIANT]: DuckDBValueConverters_1.fromVariantValue,
|
|
50
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_TZ_NS]: DuckDBValueConverters_1.dateFromTimestampTZNanosecondsValue,
|
|
48
51
|
};
|
|
49
52
|
exports.JSDuckDBValueConverter = (0, createDuckDBValueConverter_1.createDuckDBValueConverter)(JSConvertersByTypeId);
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { DuckDBType } from './DuckDBType';
|
|
2
|
+
import { DuckDBTypeId } from './DuckDBTypeId';
|
|
3
|
+
import type { JS } from './JS';
|
|
4
|
+
import type { DuckDBVariantValue } from './values';
|
|
5
|
+
/**
|
|
6
|
+
* The JS type accepted by `jsToDuckDBValue` for each DuckDB type id: the write
|
|
7
|
+
* counterpart of `JSTypeForTypeId`.
|
|
8
|
+
*
|
|
9
|
+
* Everything `JSTypeForTypeId` produces, this table accepts — see the
|
|
10
|
+
* round-trip assertion in `test/js-writes.test.ts` — but not the reverse.
|
|
11
|
+
* Writes are deliberately wider where a second spelling is unambiguous: the
|
|
12
|
+
* 64-bit and wider integers take `number` as well as `bigint`, and DECIMAL
|
|
13
|
+
* takes either a double or a raw scaled `bigint`. VARIANT is the one
|
|
14
|
+
* exception in the other direction; see below.
|
|
15
|
+
*
|
|
16
|
+
* NULL is not in the table: `createToDuckDBValueConverter` maps `null` to
|
|
17
|
+
* `null` for every type, so a nullable value is `JSInputTypeForTypeId[Id] |
|
|
18
|
+
* null`.
|
|
19
|
+
*
|
|
20
|
+
* Type ids that cannot be written map to `never`: `INVALID`, `ANY`,
|
|
21
|
+
* `STRING_LITERAL` and `INTEGER_LITERAL`, none of which can appear in a result
|
|
22
|
+
* either.
|
|
23
|
+
*
|
|
24
|
+
* VARIANT is the one place the write side is *narrower* than the read side. A
|
|
25
|
+
* VARIANT holds its own type, so writing one means saying what that type is.
|
|
26
|
+
* A `DuckDBVariantValue` carries it — either explicitly, as
|
|
27
|
+
* `variantValue(structValue({k: 'n'}), STRUCT({k: VARCHAR}))`, or inferred by
|
|
28
|
+
* `typeForValue` from a wrapped inner value — and a bare boolean, number,
|
|
29
|
+
* bigint or string is unambiguous enough to infer on its own. A bare `Date`,
|
|
30
|
+
* `Uint8Array`, array or object is not: each maps to several DuckDB types, so
|
|
31
|
+
* `typeForValue` yields ANY and the write fails. Wrap those to say which.
|
|
32
|
+
*
|
|
33
|
+
* Reading a VARIANT discards that type, which is why the round-trip
|
|
34
|
+
* containment the other ids satisfy does not hold here: the read table gives
|
|
35
|
+
* `JS | null`, and JS alone is not enough to write back.
|
|
36
|
+
*
|
|
37
|
+
* This interface is exhaustive over `DuckDBTypeId`, and is the annotation
|
|
38
|
+
* source for the converter map in `jsToDuckDBValue`; adding a type id without
|
|
39
|
+
* adding it here is a compile error.
|
|
40
|
+
*/
|
|
41
|
+
export interface JSInputTypeForTypeId {
|
|
42
|
+
[DuckDBTypeId.INVALID]: never;
|
|
43
|
+
[DuckDBTypeId.BOOLEAN]: boolean;
|
|
44
|
+
[DuckDBTypeId.TINYINT]: number;
|
|
45
|
+
[DuckDBTypeId.SMALLINT]: number;
|
|
46
|
+
[DuckDBTypeId.INTEGER]: number;
|
|
47
|
+
[DuckDBTypeId.BIGINT]: bigint | number;
|
|
48
|
+
[DuckDBTypeId.UTINYINT]: number;
|
|
49
|
+
[DuckDBTypeId.USMALLINT]: number;
|
|
50
|
+
[DuckDBTypeId.UINTEGER]: number;
|
|
51
|
+
[DuckDBTypeId.UBIGINT]: bigint | number;
|
|
52
|
+
[DuckDBTypeId.FLOAT]: number;
|
|
53
|
+
[DuckDBTypeId.DOUBLE]: number;
|
|
54
|
+
[DuckDBTypeId.TIMESTAMP]: Date;
|
|
55
|
+
[DuckDBTypeId.DATE]: Date;
|
|
56
|
+
[DuckDBTypeId.TIME]: bigint;
|
|
57
|
+
[DuckDBTypeId.INTERVAL]: {
|
|
58
|
+
months: number;
|
|
59
|
+
days: number;
|
|
60
|
+
micros: bigint;
|
|
61
|
+
};
|
|
62
|
+
[DuckDBTypeId.HUGEINT]: bigint | number;
|
|
63
|
+
[DuckDBTypeId.UHUGEINT]: bigint | number;
|
|
64
|
+
[DuckDBTypeId.VARCHAR]: string;
|
|
65
|
+
[DuckDBTypeId.BLOB]: Uint8Array;
|
|
66
|
+
[DuckDBTypeId.DECIMAL]: number | bigint;
|
|
67
|
+
[DuckDBTypeId.TIMESTAMP_S]: Date;
|
|
68
|
+
[DuckDBTypeId.TIMESTAMP_MS]: Date;
|
|
69
|
+
[DuckDBTypeId.TIMESTAMP_NS]: Date;
|
|
70
|
+
[DuckDBTypeId.ENUM]: string;
|
|
71
|
+
[DuckDBTypeId.LIST]: readonly (JS | null)[];
|
|
72
|
+
[DuckDBTypeId.STRUCT]: Readonly<Record<string, JS | null>> | readonly (JS | null)[];
|
|
73
|
+
[DuckDBTypeId.MAP]: readonly {
|
|
74
|
+
key: JS | null;
|
|
75
|
+
value: JS | null;
|
|
76
|
+
}[];
|
|
77
|
+
[DuckDBTypeId.ARRAY]: readonly (JS | null)[];
|
|
78
|
+
[DuckDBTypeId.UUID]: string;
|
|
79
|
+
[DuckDBTypeId.UNION]: {
|
|
80
|
+
tag: string;
|
|
81
|
+
value: JS | null;
|
|
82
|
+
};
|
|
83
|
+
[DuckDBTypeId.BIT]: Uint8Array;
|
|
84
|
+
[DuckDBTypeId.TIME_TZ]: {
|
|
85
|
+
micros: bigint;
|
|
86
|
+
offset: number;
|
|
87
|
+
};
|
|
88
|
+
[DuckDBTypeId.TIMESTAMP_TZ]: Date;
|
|
89
|
+
[DuckDBTypeId.ANY]: never;
|
|
90
|
+
[DuckDBTypeId.BIGNUM]: bigint | number;
|
|
91
|
+
[DuckDBTypeId.SQLNULL]: null;
|
|
92
|
+
[DuckDBTypeId.STRING_LITERAL]: never;
|
|
93
|
+
[DuckDBTypeId.INTEGER_LITERAL]: never;
|
|
94
|
+
[DuckDBTypeId.TIME_NS]: bigint;
|
|
95
|
+
[DuckDBTypeId.GEOMETRY]: Uint8Array;
|
|
96
|
+
[DuckDBTypeId.VARIANT]: DuckDBVariantValue | boolean | number | bigint | string;
|
|
97
|
+
[DuckDBTypeId.TIMESTAMP_TZ_NS]: Date;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The JS type accepted by `jsToDuckDBValue` for a given `DuckDBType`.
|
|
101
|
+
*
|
|
102
|
+
* Excludes NULL; use `JSInputTypeFor<T> | null` for a nullable value.
|
|
103
|
+
*/
|
|
104
|
+
export type JSInputTypeFor<T extends DuckDBType> = JSInputTypeForTypeId[T['typeId']];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DuckDBType } from './DuckDBType';
|
|
2
|
+
import { JS } from './JS';
|
|
3
|
+
import { JSInputTypeFor } from './JSInputTypeForTypeId';
|
|
4
|
+
import { DuckDBValue } from './values';
|
|
5
|
+
/**
|
|
6
|
+
* Converts a JS value into the `DuckDBValue` representation for a DuckDB type:
|
|
7
|
+
* the inverse of `JSDuckDBValueConverter`.
|
|
8
|
+
*
|
|
9
|
+
* Pass this to `DuckDBDataChunk.setRowsConverted` and friends to fill a chunk
|
|
10
|
+
* from JS values. `jsToDuckDBValue` below is the single-value form, and checks
|
|
11
|
+
* its input against a statically known type.
|
|
12
|
+
*/
|
|
13
|
+
export declare const JSToDuckDBValueConverter: import("./ToDuckDBValueConverter").ToDuckDBValueConverter<JS>;
|
|
14
|
+
/**
|
|
15
|
+
* Converts a JS value into the `DuckDBValue` representation for `type`.
|
|
16
|
+
*
|
|
17
|
+
* The inverse of `JSDuckDBValueConverter`. Accepts what
|
|
18
|
+
* `JSInputTypeForTypeId` declares for the type's id, plus `null` for any type.
|
|
19
|
+
* Generic over the type, so a statically known one checks its input exactly:
|
|
20
|
+
* `jsToDuckDBValue(new Date(), TIMESTAMP)` is accepted and
|
|
21
|
+
* `jsToDuckDBValue(new Date(), INTEGER)` is not. Passing a `DuckDBType` that
|
|
22
|
+
* is only known as the union widens the input to the union of every entry,
|
|
23
|
+
* which is as precise as the type information allows.
|
|
24
|
+
*
|
|
25
|
+
* Pure TypeScript: it constructs no `duckdb_value` and needs no connection, so
|
|
26
|
+
* it composes with every write entry point — `DuckDBAppender.appendValue`,
|
|
27
|
+
* `DuckDBPreparedStatement.bindValue`, and `DuckDBDataChunk.setRows` all take
|
|
28
|
+
* a `DuckDBValue`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function jsToDuckDBValue<T extends DuckDBType>(value: JSInputTypeFor<T> | null, type: T): DuckDBValue;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JSToDuckDBValueConverter = void 0;
|
|
4
|
+
exports.jsToDuckDBValue = jsToDuckDBValue;
|
|
5
|
+
const DuckDBTypeId_1 = require("./DuckDBTypeId");
|
|
6
|
+
const ToDuckDBValueConverter_1 = require("./ToDuckDBValueConverter");
|
|
7
|
+
const ToDuckDBValueConverters_1 = require("./ToDuckDBValueConverters");
|
|
8
|
+
const JSInputConvertersByTypeId = {
|
|
9
|
+
[DuckDBTypeId_1.DuckDBTypeId.INVALID]: ToDuckDBValueConverters_1.unwritableConverter,
|
|
10
|
+
[DuckDBTypeId_1.DuckDBTypeId.BOOLEAN]: ToDuckDBValueConverters_1.valueFromBoolean,
|
|
11
|
+
[DuckDBTypeId_1.DuckDBTypeId.TINYINT]: ToDuckDBValueConverters_1.valueFromNumber,
|
|
12
|
+
[DuckDBTypeId_1.DuckDBTypeId.SMALLINT]: ToDuckDBValueConverters_1.valueFromNumber,
|
|
13
|
+
[DuckDBTypeId_1.DuckDBTypeId.INTEGER]: ToDuckDBValueConverters_1.valueFromNumber,
|
|
14
|
+
[DuckDBTypeId_1.DuckDBTypeId.BIGINT]: ToDuckDBValueConverters_1.bigintFromNumeric,
|
|
15
|
+
[DuckDBTypeId_1.DuckDBTypeId.UTINYINT]: ToDuckDBValueConverters_1.valueFromNumber,
|
|
16
|
+
[DuckDBTypeId_1.DuckDBTypeId.USMALLINT]: ToDuckDBValueConverters_1.valueFromNumber,
|
|
17
|
+
[DuckDBTypeId_1.DuckDBTypeId.UINTEGER]: ToDuckDBValueConverters_1.valueFromNumber,
|
|
18
|
+
[DuckDBTypeId_1.DuckDBTypeId.UBIGINT]: ToDuckDBValueConverters_1.bigintFromNumeric,
|
|
19
|
+
[DuckDBTypeId_1.DuckDBTypeId.FLOAT]: ToDuckDBValueConverters_1.valueFromNumber,
|
|
20
|
+
[DuckDBTypeId_1.DuckDBTypeId.DOUBLE]: ToDuckDBValueConverters_1.valueFromNumber,
|
|
21
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP]: ToDuckDBValueConverters_1.timestampValueFromDate,
|
|
22
|
+
[DuckDBTypeId_1.DuckDBTypeId.DATE]: ToDuckDBValueConverters_1.dateValueFromDate,
|
|
23
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIME]: ToDuckDBValueConverters_1.timeValueFromMicros,
|
|
24
|
+
[DuckDBTypeId_1.DuckDBTypeId.INTERVAL]: ToDuckDBValueConverters_1.intervalValueFromObject,
|
|
25
|
+
[DuckDBTypeId_1.DuckDBTypeId.HUGEINT]: ToDuckDBValueConverters_1.bigintFromNumeric,
|
|
26
|
+
[DuckDBTypeId_1.DuckDBTypeId.UHUGEINT]: ToDuckDBValueConverters_1.bigintFromNumeric,
|
|
27
|
+
[DuckDBTypeId_1.DuckDBTypeId.VARCHAR]: ToDuckDBValueConverters_1.valueFromString,
|
|
28
|
+
[DuckDBTypeId_1.DuckDBTypeId.BLOB]: ToDuckDBValueConverters_1.blobValueFromBytes,
|
|
29
|
+
[DuckDBTypeId_1.DuckDBTypeId.DECIMAL]: ToDuckDBValueConverters_1.decimalValueFromNumeric,
|
|
30
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_S]: ToDuckDBValueConverters_1.timestampSecondsValueFromDate,
|
|
31
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_MS]: ToDuckDBValueConverters_1.timestampMillisValueFromDate,
|
|
32
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_NS]: ToDuckDBValueConverters_1.timestampNanosValueFromDate,
|
|
33
|
+
[DuckDBTypeId_1.DuckDBTypeId.ENUM]: ToDuckDBValueConverters_1.valueFromString,
|
|
34
|
+
[DuckDBTypeId_1.DuckDBTypeId.LIST]: ToDuckDBValueConverters_1.listValueFromArray,
|
|
35
|
+
[DuckDBTypeId_1.DuckDBTypeId.STRUCT]: ToDuckDBValueConverters_1.structValueFromObject,
|
|
36
|
+
[DuckDBTypeId_1.DuckDBTypeId.MAP]: ToDuckDBValueConverters_1.mapValueFromEntries,
|
|
37
|
+
[DuckDBTypeId_1.DuckDBTypeId.ARRAY]: ToDuckDBValueConverters_1.arrayValueFromArray,
|
|
38
|
+
[DuckDBTypeId_1.DuckDBTypeId.UUID]: ToDuckDBValueConverters_1.uuidValueFromString,
|
|
39
|
+
[DuckDBTypeId_1.DuckDBTypeId.UNION]: ToDuckDBValueConverters_1.unionValueFromObject,
|
|
40
|
+
[DuckDBTypeId_1.DuckDBTypeId.BIT]: ToDuckDBValueConverters_1.bitValueFromBytes,
|
|
41
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIME_TZ]: ToDuckDBValueConverters_1.timeTZValueFromObject,
|
|
42
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_TZ]: ToDuckDBValueConverters_1.timestampTZValueFromDate,
|
|
43
|
+
[DuckDBTypeId_1.DuckDBTypeId.ANY]: ToDuckDBValueConverters_1.unwritableConverter,
|
|
44
|
+
[DuckDBTypeId_1.DuckDBTypeId.BIGNUM]: ToDuckDBValueConverters_1.bigintFromNumeric,
|
|
45
|
+
[DuckDBTypeId_1.DuckDBTypeId.SQLNULL]: ToDuckDBValueConverters_1.nullFromNull,
|
|
46
|
+
[DuckDBTypeId_1.DuckDBTypeId.STRING_LITERAL]: ToDuckDBValueConverters_1.unwritableConverter,
|
|
47
|
+
[DuckDBTypeId_1.DuckDBTypeId.INTEGER_LITERAL]: ToDuckDBValueConverters_1.unwritableConverter,
|
|
48
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIME_NS]: ToDuckDBValueConverters_1.timeNSValueFromNanos,
|
|
49
|
+
[DuckDBTypeId_1.DuckDBTypeId.GEOMETRY]: ToDuckDBValueConverters_1.geometryValueFromBytes,
|
|
50
|
+
[DuckDBTypeId_1.DuckDBTypeId.VARIANT]: ToDuckDBValueConverters_1.variantValueFromJS,
|
|
51
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_TZ_NS]: ToDuckDBValueConverters_1.timestampTZNanosValueFromDate,
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Converts a JS value into the `DuckDBValue` representation for a DuckDB type:
|
|
55
|
+
* the inverse of `JSDuckDBValueConverter`.
|
|
56
|
+
*
|
|
57
|
+
* Pass this to `DuckDBDataChunk.setRowsConverted` and friends to fill a chunk
|
|
58
|
+
* from JS values. `jsToDuckDBValue` below is the single-value form, and checks
|
|
59
|
+
* its input against a statically known type.
|
|
60
|
+
*/
|
|
61
|
+
exports.JSToDuckDBValueConverter = (0, ToDuckDBValueConverter_1.createToDuckDBValueConverter)(JSInputConvertersByTypeId);
|
|
62
|
+
/**
|
|
63
|
+
* Converts a JS value into the `DuckDBValue` representation for `type`.
|
|
64
|
+
*
|
|
65
|
+
* The inverse of `JSDuckDBValueConverter`. Accepts what
|
|
66
|
+
* `JSInputTypeForTypeId` declares for the type's id, plus `null` for any type.
|
|
67
|
+
* Generic over the type, so a statically known one checks its input exactly:
|
|
68
|
+
* `jsToDuckDBValue(new Date(), TIMESTAMP)` is accepted and
|
|
69
|
+
* `jsToDuckDBValue(new Date(), INTEGER)` is not. Passing a `DuckDBType` that
|
|
70
|
+
* is only known as the union widens the input to the union of every entry,
|
|
71
|
+
* which is as precise as the type information allows.
|
|
72
|
+
*
|
|
73
|
+
* Pure TypeScript: it constructs no `duckdb_value` and needs no connection, so
|
|
74
|
+
* it composes with every write entry point — `DuckDBAppender.appendValue`,
|
|
75
|
+
* `DuckDBPreparedStatement.bindValue`, and `DuckDBDataChunk.setRows` all take
|
|
76
|
+
* a `DuckDBValue`.
|
|
77
|
+
*/
|
|
78
|
+
function jsToDuckDBValue(value, type) {
|
|
79
|
+
// The converter chain is typed against JS, which the input table exceeds for
|
|
80
|
+
// VARIANT alone (a DuckDBVariantValue is not a JS value). Narrowed back at
|
|
81
|
+
// the same boundary the factory documents.
|
|
82
|
+
return (0, exports.JSToDuckDBValueConverter)(value, type, exports.JSToDuckDBValueConverter);
|
|
83
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { DuckDBType } from './DuckDBType';
|
|
2
|
+
import { DuckDBTypeId } from './DuckDBTypeId';
|
|
3
|
+
import type { JS } from './JS';
|
|
4
|
+
/**
|
|
5
|
+
* The JS type produced by `JSDuckDBValueConverter` for each DuckDB type id.
|
|
6
|
+
*
|
|
7
|
+
* Values are non-NULL results only: SQL NULL is handled by
|
|
8
|
+
* `createDuckDBValueConverter`, which yields `null` for any type. Callers
|
|
9
|
+
* representing a nullable value should use `JSTypeForTypeId[Id] | null`.
|
|
10
|
+
*
|
|
11
|
+
* Type ids that cannot appear in a result (`INVALID`, `ANY`,
|
|
12
|
+
* `STRING_LITERAL`, `INTEGER_LITERAL`) map to `never`, since their
|
|
13
|
+
* converters throw.
|
|
14
|
+
*
|
|
15
|
+
* Nested types bottom out at `JS`, because `DuckDBListType`,
|
|
16
|
+
* `DuckDBArrayType`, `DuckDBStructType`, `DuckDBMapType`, and
|
|
17
|
+
* `DuckDBUnionType` do not carry their child types at the type level.
|
|
18
|
+
*
|
|
19
|
+
* STRUCT is an object keyed by entry name, except for a tuple (see
|
|
20
|
+
* `DuckDBStructType.isTuple`), which is an array of its items.
|
|
21
|
+
*
|
|
22
|
+
* This interface is exhaustive over `DuckDBTypeId`, and is the annotation
|
|
23
|
+
* source for the converter map in `JSDuckDBValueConverter`; adding a type id
|
|
24
|
+
* without adding it here is a compile error.
|
|
25
|
+
*/
|
|
26
|
+
export interface JSTypeForTypeId {
|
|
27
|
+
[DuckDBTypeId.INVALID]: never;
|
|
28
|
+
[DuckDBTypeId.BOOLEAN]: boolean;
|
|
29
|
+
[DuckDBTypeId.TINYINT]: number;
|
|
30
|
+
[DuckDBTypeId.SMALLINT]: number;
|
|
31
|
+
[DuckDBTypeId.INTEGER]: number;
|
|
32
|
+
[DuckDBTypeId.BIGINT]: bigint;
|
|
33
|
+
[DuckDBTypeId.UTINYINT]: number;
|
|
34
|
+
[DuckDBTypeId.USMALLINT]: number;
|
|
35
|
+
[DuckDBTypeId.UINTEGER]: number;
|
|
36
|
+
[DuckDBTypeId.UBIGINT]: bigint;
|
|
37
|
+
[DuckDBTypeId.FLOAT]: number;
|
|
38
|
+
[DuckDBTypeId.DOUBLE]: number;
|
|
39
|
+
[DuckDBTypeId.TIMESTAMP]: Date;
|
|
40
|
+
[DuckDBTypeId.DATE]: Date;
|
|
41
|
+
[DuckDBTypeId.TIME]: bigint;
|
|
42
|
+
[DuckDBTypeId.INTERVAL]: {
|
|
43
|
+
months: number;
|
|
44
|
+
days: number;
|
|
45
|
+
micros: bigint;
|
|
46
|
+
};
|
|
47
|
+
[DuckDBTypeId.HUGEINT]: bigint;
|
|
48
|
+
[DuckDBTypeId.UHUGEINT]: bigint;
|
|
49
|
+
[DuckDBTypeId.VARCHAR]: string;
|
|
50
|
+
[DuckDBTypeId.BLOB]: Uint8Array;
|
|
51
|
+
[DuckDBTypeId.DECIMAL]: number;
|
|
52
|
+
[DuckDBTypeId.TIMESTAMP_S]: Date;
|
|
53
|
+
[DuckDBTypeId.TIMESTAMP_MS]: Date;
|
|
54
|
+
[DuckDBTypeId.TIMESTAMP_NS]: Date;
|
|
55
|
+
[DuckDBTypeId.ENUM]: string;
|
|
56
|
+
[DuckDBTypeId.LIST]: (JS | null)[];
|
|
57
|
+
[DuckDBTypeId.STRUCT]: {
|
|
58
|
+
[key: string]: JS | null;
|
|
59
|
+
} | (JS | null)[];
|
|
60
|
+
[DuckDBTypeId.MAP]: {
|
|
61
|
+
key: JS | null;
|
|
62
|
+
value: JS | null;
|
|
63
|
+
}[];
|
|
64
|
+
[DuckDBTypeId.ARRAY]: (JS | null)[];
|
|
65
|
+
[DuckDBTypeId.UUID]: string;
|
|
66
|
+
[DuckDBTypeId.UNION]: {
|
|
67
|
+
tag: string;
|
|
68
|
+
value: JS | null;
|
|
69
|
+
};
|
|
70
|
+
[DuckDBTypeId.BIT]: Uint8Array;
|
|
71
|
+
[DuckDBTypeId.TIME_TZ]: {
|
|
72
|
+
micros: bigint;
|
|
73
|
+
offset: number;
|
|
74
|
+
};
|
|
75
|
+
[DuckDBTypeId.TIMESTAMP_TZ]: Date;
|
|
76
|
+
[DuckDBTypeId.ANY]: never;
|
|
77
|
+
[DuckDBTypeId.BIGNUM]: bigint;
|
|
78
|
+
[DuckDBTypeId.SQLNULL]: null;
|
|
79
|
+
[DuckDBTypeId.STRING_LITERAL]: never;
|
|
80
|
+
[DuckDBTypeId.INTEGER_LITERAL]: never;
|
|
81
|
+
[DuckDBTypeId.TIME_NS]: bigint;
|
|
82
|
+
[DuckDBTypeId.GEOMETRY]: Uint8Array;
|
|
83
|
+
[DuckDBTypeId.VARIANT]: JS | null;
|
|
84
|
+
[DuckDBTypeId.TIMESTAMP_TZ_NS]: Date;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The JS type produced by `JSDuckDBValueConverter` for a given `DuckDBType`.
|
|
88
|
+
*
|
|
89
|
+
* Excludes NULL; use `JSTypeFor<T> | null` for a nullable value.
|
|
90
|
+
*/
|
|
91
|
+
export type JSTypeFor<T extends DuckDBType> = JSTypeForTypeId[T['typeId']];
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { DuckDBValueConverter } from './DuckDBValueConverter';
|
|
2
1
|
import { Json } from './Json';
|
|
3
|
-
export declare const JsonDuckDBValueConverter: DuckDBValueConverter<Json>;
|
|
2
|
+
export declare const JsonDuckDBValueConverter: import("./DuckDBValueConverter").DuckDBValueConverter<Json>;
|
|
@@ -31,7 +31,7 @@ const JsonConvertersByTypeId = {
|
|
|
31
31
|
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_NS]: DuckDBValueConverters_1.stringFromValue,
|
|
32
32
|
[DuckDBTypeId_1.DuckDBTypeId.ENUM]: DuckDBValueConverters_1.stringFromValue,
|
|
33
33
|
[DuckDBTypeId_1.DuckDBTypeId.LIST]: DuckDBValueConverters_1.arrayFromListValue,
|
|
34
|
-
[DuckDBTypeId_1.DuckDBTypeId.STRUCT]: DuckDBValueConverters_1.
|
|
34
|
+
[DuckDBTypeId_1.DuckDBTypeId.STRUCT]: DuckDBValueConverters_1.objectOrArrayFromStructValue,
|
|
35
35
|
[DuckDBTypeId_1.DuckDBTypeId.MAP]: DuckDBValueConverters_1.objectArrayFromMapValue,
|
|
36
36
|
[DuckDBTypeId_1.DuckDBTypeId.ARRAY]: DuckDBValueConverters_1.arrayFromArrayValue,
|
|
37
37
|
[DuckDBTypeId_1.DuckDBTypeId.UUID]: DuckDBValueConverters_1.stringFromValue,
|
|
@@ -45,5 +45,8 @@ const JsonConvertersByTypeId = {
|
|
|
45
45
|
[DuckDBTypeId_1.DuckDBTypeId.STRING_LITERAL]: DuckDBValueConverters_1.unsupportedConverter,
|
|
46
46
|
[DuckDBTypeId_1.DuckDBTypeId.INTEGER_LITERAL]: DuckDBValueConverters_1.unsupportedConverter,
|
|
47
47
|
[DuckDBTypeId_1.DuckDBTypeId.TIME_NS]: DuckDBValueConverters_1.stringFromValue,
|
|
48
|
+
[DuckDBTypeId_1.DuckDBTypeId.GEOMETRY]: DuckDBValueConverters_1.stringFromValue,
|
|
49
|
+
[DuckDBTypeId_1.DuckDBTypeId.VARIANT]: DuckDBValueConverters_1.fromVariantValue,
|
|
50
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_TZ_NS]: DuckDBValueConverters_1.stringFromValue,
|
|
48
51
|
};
|
|
49
52
|
exports.JsonDuckDBValueConverter = (0, createDuckDBValueConverter_1.createDuckDBValueConverter)(JsonConvertersByTypeId);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { DuckDBType } from './DuckDBType';
|
|
2
|
+
import { DuckDBTypeId } from './DuckDBTypeId';
|
|
3
|
+
import type { Json } from './Json';
|
|
4
|
+
/**
|
|
5
|
+
* The JSON-compatible type produced by `JsonDuckDBValueConverter` for each
|
|
6
|
+
* DuckDB type id.
|
|
7
|
+
*
|
|
8
|
+
* Values are non-NULL results only: SQL NULL is handled by
|
|
9
|
+
* `createDuckDBValueConverter`, which yields `null` for any type. Callers
|
|
10
|
+
* representing a nullable value should use `JsonTypeForTypeId[Id] | null`.
|
|
11
|
+
*
|
|
12
|
+
* This differs from `JSTypeForTypeId` wherever a DuckDB value has no lossless
|
|
13
|
+
* JSON representation: 64-bit and wider integers, temporal types, DECIMAL,
|
|
14
|
+
* BLOB, BIT, and GEOMETRY are rendered as strings rather than as `bigint`,
|
|
15
|
+
* `Date`, or `Uint8Array`, and FLOAT and DOUBLE widen to `number | string` so
|
|
16
|
+
* that Infinity and NaN survive as strings.
|
|
17
|
+
*
|
|
18
|
+
* Type ids that cannot appear in a result (`INVALID`, `ANY`,
|
|
19
|
+
* `STRING_LITERAL`, `INTEGER_LITERAL`) map to `never`, since their
|
|
20
|
+
* converters throw.
|
|
21
|
+
*
|
|
22
|
+
* Nested types bottom out at `Json`, because `DuckDBListType`,
|
|
23
|
+
* `DuckDBArrayType`, `DuckDBStructType`, `DuckDBMapType`, and
|
|
24
|
+
* `DuckDBUnionType` do not carry their child types at the type level.
|
|
25
|
+
*
|
|
26
|
+
* STRUCT is an object keyed by entry name, except for a tuple (see
|
|
27
|
+
* `DuckDBStructType.isTuple`), which is an array of its items.
|
|
28
|
+
*
|
|
29
|
+
* This interface is exhaustive over `DuckDBTypeId`, and is the annotation
|
|
30
|
+
* source for the converter map in `JsonDuckDBValueConverter`; adding a type id
|
|
31
|
+
* without adding it here is a compile error.
|
|
32
|
+
*/
|
|
33
|
+
export interface JsonTypeForTypeId {
|
|
34
|
+
[DuckDBTypeId.INVALID]: never;
|
|
35
|
+
[DuckDBTypeId.BOOLEAN]: boolean;
|
|
36
|
+
[DuckDBTypeId.TINYINT]: number;
|
|
37
|
+
[DuckDBTypeId.SMALLINT]: number;
|
|
38
|
+
[DuckDBTypeId.INTEGER]: number;
|
|
39
|
+
[DuckDBTypeId.BIGINT]: string;
|
|
40
|
+
[DuckDBTypeId.UTINYINT]: number;
|
|
41
|
+
[DuckDBTypeId.USMALLINT]: number;
|
|
42
|
+
[DuckDBTypeId.UINTEGER]: number;
|
|
43
|
+
[DuckDBTypeId.UBIGINT]: string;
|
|
44
|
+
[DuckDBTypeId.FLOAT]: number | string;
|
|
45
|
+
[DuckDBTypeId.DOUBLE]: number | string;
|
|
46
|
+
[DuckDBTypeId.TIMESTAMP]: string;
|
|
47
|
+
[DuckDBTypeId.DATE]: string;
|
|
48
|
+
[DuckDBTypeId.TIME]: string;
|
|
49
|
+
[DuckDBTypeId.INTERVAL]: {
|
|
50
|
+
months: number;
|
|
51
|
+
days: number;
|
|
52
|
+
micros: string;
|
|
53
|
+
};
|
|
54
|
+
[DuckDBTypeId.HUGEINT]: string;
|
|
55
|
+
[DuckDBTypeId.UHUGEINT]: string;
|
|
56
|
+
[DuckDBTypeId.VARCHAR]: string;
|
|
57
|
+
[DuckDBTypeId.BLOB]: string;
|
|
58
|
+
[DuckDBTypeId.DECIMAL]: string;
|
|
59
|
+
[DuckDBTypeId.TIMESTAMP_S]: string;
|
|
60
|
+
[DuckDBTypeId.TIMESTAMP_MS]: string;
|
|
61
|
+
[DuckDBTypeId.TIMESTAMP_NS]: string;
|
|
62
|
+
[DuckDBTypeId.ENUM]: string;
|
|
63
|
+
[DuckDBTypeId.LIST]: (Json | null)[];
|
|
64
|
+
[DuckDBTypeId.STRUCT]: {
|
|
65
|
+
[key: string]: Json | null;
|
|
66
|
+
} | (Json | null)[];
|
|
67
|
+
[DuckDBTypeId.MAP]: {
|
|
68
|
+
key: Json | null;
|
|
69
|
+
value: Json | null;
|
|
70
|
+
}[];
|
|
71
|
+
[DuckDBTypeId.ARRAY]: (Json | null)[];
|
|
72
|
+
[DuckDBTypeId.UUID]: string;
|
|
73
|
+
[DuckDBTypeId.UNION]: {
|
|
74
|
+
tag: string;
|
|
75
|
+
value: Json | null;
|
|
76
|
+
};
|
|
77
|
+
[DuckDBTypeId.BIT]: string;
|
|
78
|
+
[DuckDBTypeId.TIME_TZ]: string;
|
|
79
|
+
[DuckDBTypeId.TIMESTAMP_TZ]: string;
|
|
80
|
+
[DuckDBTypeId.ANY]: never;
|
|
81
|
+
[DuckDBTypeId.BIGNUM]: string;
|
|
82
|
+
[DuckDBTypeId.SQLNULL]: null;
|
|
83
|
+
[DuckDBTypeId.STRING_LITERAL]: never;
|
|
84
|
+
[DuckDBTypeId.INTEGER_LITERAL]: never;
|
|
85
|
+
[DuckDBTypeId.TIME_NS]: string;
|
|
86
|
+
[DuckDBTypeId.GEOMETRY]: string;
|
|
87
|
+
[DuckDBTypeId.VARIANT]: Json | null;
|
|
88
|
+
[DuckDBTypeId.TIMESTAMP_TZ_NS]: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The JSON-compatible type produced by `JsonDuckDBValueConverter` for a given
|
|
92
|
+
* `DuckDBType`.
|
|
93
|
+
*
|
|
94
|
+
* Excludes NULL; use `JsonTypeFor<T> | null` for a nullable value.
|
|
95
|
+
*/
|
|
96
|
+
export type JsonTypeFor<T extends DuckDBType> = JsonTypeForTypeId[T['typeId']];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { DuckDBType } from './DuckDBType';
|
|
2
|
+
import { DuckDBTypeId } from './DuckDBTypeId';
|
|
3
|
+
import { DuckDBValue } from './values';
|
|
4
|
+
/**
|
|
5
|
+
* Converts a `T` into the `DuckDBValue` representation for a DuckDB type: the
|
|
6
|
+
* inverse of `DuckDBValueConverter<T>`, which converts the other way.
|
|
7
|
+
*
|
|
8
|
+
* `T` is whatever representation a given converter accepts — see
|
|
9
|
+
* `JSToDuckDBValueConverter` for the JS one. `DuckDBValue` is itself a
|
|
10
|
+
* TypeScript representation, plain JS for the scalars and the value wrapper
|
|
11
|
+
* classes, which hold nothing but data, for the rest. So a conversion of this
|
|
12
|
+
* shape touches no C API, which is what lets it survive the move to the V2 C
|
|
13
|
+
* API, where constructing a `duckdb_value` requires a connection or context.
|
|
14
|
+
* Nothing here constructs one.
|
|
15
|
+
*/
|
|
16
|
+
export type ToDuckDBValueConverter<T> = (value: T, type: DuckDBType, converter: ToDuckDBValueConverter<T>) => DuckDBValue;
|
|
17
|
+
/**
|
|
18
|
+
* A converter for a single DuckDB type id, whose accepted input `In` is
|
|
19
|
+
* narrower than the `Nested` the top-level converter it recurses through
|
|
20
|
+
* accepts.
|
|
21
|
+
*
|
|
22
|
+
* The write-side counterpart of `DuckDBValueConverterFor`, and narrowing for
|
|
23
|
+
* the same reason: in a per-type-id map only the accepted input varies by id,
|
|
24
|
+
* while the `converter` argument is always the map's top-level converter.
|
|
25
|
+
*/
|
|
26
|
+
export type ToDuckDBValueConverterFor<In, Nested> = (value: In, type: DuckDBType, converter: ToDuckDBValueConverter<Nested>) => DuckDBValue;
|
|
27
|
+
/**
|
|
28
|
+
* Assembles a per-type-id converter map into a single converter.
|
|
29
|
+
*
|
|
30
|
+
* `InputTable` is the type table the map was annotated from — one entry per
|
|
31
|
+
* type id — so each entry may accept a type narrower than `T`. That narrowing
|
|
32
|
+
* is contravariant, so unlike the read direction it cannot be checked through
|
|
33
|
+
* to the dispatch: the type id is only known at runtime, and the compiler
|
|
34
|
+
* cannot relate `type.typeId` to the static type of `value`. The one unchecked
|
|
35
|
+
* cast that closes the gap lives here rather than at each call site — callers
|
|
36
|
+
* get a checked signature, and the mismatch surfaces as the converter's own
|
|
37
|
+
* `Expected ...` error.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createToDuckDBValueConverter<T, InputTable extends Record<DuckDBTypeId, unknown>>(convertersByTypeId: {
|
|
40
|
+
[Id in DuckDBTypeId]: ToDuckDBValueConverterFor<InputTable[Id], T>;
|
|
41
|
+
}): ToDuckDBValueConverter<T>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createToDuckDBValueConverter = createToDuckDBValueConverter;
|
|
4
|
+
/**
|
|
5
|
+
* Assembles a per-type-id converter map into a single converter.
|
|
6
|
+
*
|
|
7
|
+
* `InputTable` is the type table the map was annotated from — one entry per
|
|
8
|
+
* type id — so each entry may accept a type narrower than `T`. That narrowing
|
|
9
|
+
* is contravariant, so unlike the read direction it cannot be checked through
|
|
10
|
+
* to the dispatch: the type id is only known at runtime, and the compiler
|
|
11
|
+
* cannot relate `type.typeId` to the static type of `value`. The one unchecked
|
|
12
|
+
* cast that closes the gap lives here rather than at each call site — callers
|
|
13
|
+
* get a checked signature, and the mismatch surfaces as the converter's own
|
|
14
|
+
* `Expected ...` error.
|
|
15
|
+
*/
|
|
16
|
+
function createToDuckDBValueConverter(convertersByTypeId) {
|
|
17
|
+
return (value, type, converter) => {
|
|
18
|
+
if (value == null) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const converterForTypeId = convertersByTypeId[type.typeId];
|
|
22
|
+
if (!converterForTypeId) {
|
|
23
|
+
throw new Error(`No converter for typeId: ${type.typeId}`);
|
|
24
|
+
}
|
|
25
|
+
return converterForTypeId(value, type, converter);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { DuckDBType } from './DuckDBType';
|
|
2
|
+
import { ToDuckDBValueConverter } from './ToDuckDBValueConverter';
|
|
3
|
+
import { DuckDBBitValue, DuckDBBlobValue, DuckDBDateValue, DuckDBDecimalValue, DuckDBGeometryValue, DuckDBIntervalValue, DuckDBTimeNSValue, DuckDBTimeTZValue, DuckDBTimeValue, DuckDBTimestampMillisecondsValue, DuckDBTimestampNanosecondsValue, DuckDBTimestampSecondsValue, DuckDBTimestampTZValue, DuckDBTimestampTZNanosecondsValue, DuckDBTimestampValue, DuckDBUUIDValue, DuckDBValue, DuckDBVariantValue } from './values';
|
|
4
|
+
export declare function unwritableConverter(_: unknown, type: DuckDBType): never;
|
|
5
|
+
export declare function nullFromNull(): null;
|
|
6
|
+
export declare function valueFromBoolean(value: boolean): boolean;
|
|
7
|
+
export declare function valueFromNumber(value: number): number;
|
|
8
|
+
export declare function bigintFromNumeric(value: bigint | number): bigint;
|
|
9
|
+
export declare function valueFromString(value: string): string;
|
|
10
|
+
export declare function blobValueFromBytes(value: Uint8Array): DuckDBBlobValue;
|
|
11
|
+
export declare function bitValueFromBytes(value: Uint8Array): DuckDBBitValue;
|
|
12
|
+
export declare function geometryValueFromBytes(value: Uint8Array): DuckDBGeometryValue;
|
|
13
|
+
export declare function dateValueFromDate(value: Date): DuckDBDateValue;
|
|
14
|
+
export declare function timeValueFromMicros(value: bigint): DuckDBTimeValue;
|
|
15
|
+
export declare function timeNSValueFromNanos(value: bigint): DuckDBTimeNSValue;
|
|
16
|
+
export declare function timeTZValueFromObject(value: {
|
|
17
|
+
micros: bigint;
|
|
18
|
+
offset: number;
|
|
19
|
+
}): DuckDBTimeTZValue;
|
|
20
|
+
export declare function timestampValueFromDate(value: Date): DuckDBTimestampValue;
|
|
21
|
+
export declare function timestampTZValueFromDate(value: Date): DuckDBTimestampTZValue;
|
|
22
|
+
export declare function timestampTZNanosValueFromDate(value: Date): DuckDBTimestampTZNanosecondsValue;
|
|
23
|
+
export declare function timestampSecondsValueFromDate(value: Date): DuckDBTimestampSecondsValue;
|
|
24
|
+
export declare function timestampMillisValueFromDate(value: Date): DuckDBTimestampMillisecondsValue;
|
|
25
|
+
export declare function timestampNanosValueFromDate(value: Date): DuckDBTimestampNanosecondsValue;
|
|
26
|
+
export declare function intervalValueFromObject(value: {
|
|
27
|
+
months: number;
|
|
28
|
+
days: number;
|
|
29
|
+
micros: bigint;
|
|
30
|
+
}): DuckDBIntervalValue;
|
|
31
|
+
export declare function decimalValueFromNumeric(value: number | bigint, type: DuckDBType): DuckDBDecimalValue;
|
|
32
|
+
export declare function uuidValueFromString(value: string): DuckDBUUIDValue;
|
|
33
|
+
export declare function listValueFromArray<T>(value: readonly T[], type: DuckDBType, converter: ToDuckDBValueConverter<T>): DuckDBValue;
|
|
34
|
+
export declare function arrayValueFromArray<T>(value: readonly T[], type: DuckDBType, converter: ToDuckDBValueConverter<T>): DuckDBValue;
|
|
35
|
+
/**
|
|
36
|
+
* Converts an object keyed by entry name to a named STRUCT value, or an array
|
|
37
|
+
* of items to a tuple value (see `DuckDBStructType.isTuple`).
|
|
38
|
+
*/
|
|
39
|
+
export declare function structValueFromObject<T>(value: Readonly<Record<string, T>> | readonly T[], type: DuckDBType, converter: ToDuckDBValueConverter<T>): DuckDBValue;
|
|
40
|
+
export declare function mapValueFromEntries<T>(value: readonly {
|
|
41
|
+
key: T;
|
|
42
|
+
value: T;
|
|
43
|
+
}[], type: DuckDBType, converter: ToDuckDBValueConverter<T>): DuckDBValue;
|
|
44
|
+
export declare function unionValueFromObject<T>(value: {
|
|
45
|
+
tag: string;
|
|
46
|
+
value: T;
|
|
47
|
+
}, type: DuckDBType, converter: ToDuckDBValueConverter<T>): DuckDBValue;
|
|
48
|
+
/**
|
|
49
|
+
* A VARIANT carries the type of the value inside it, so writing one means
|
|
50
|
+
* saying what that type is. A `DuckDBVariantValue` already does — pass it
|
|
51
|
+
* through. A bare scalar does not, but is unambiguous enough for
|
|
52
|
+
* `typeForValue` to infer downstream, so wrap it.
|
|
53
|
+
*/
|
|
54
|
+
export declare function variantValueFromJS(value: DuckDBVariantValue | boolean | number | bigint | string): DuckDBVariantValue;
|