@avidian/duckdb-bun 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +284 -2
- package/package.json +95 -4
- package/src/bindings/api/appender.ts +288 -0
- package/src/bindings/api/data-chunk.ts +58 -0
- package/src/bindings/api/database.ts +232 -0
- package/src/bindings/api/datetime.ts +158 -0
- package/src/bindings/api/index.ts +13 -0
- package/src/bindings/api/logical-types.ts +227 -0
- package/src/bindings/api/query.ts +616 -0
- package/src/bindings/api/scalar-function.ts +274 -0
- package/src/bindings/api/table-function.ts +339 -0
- package/src/bindings/api/values.ts +546 -0
- package/src/bindings/api/vector.ts +266 -0
- package/src/bindings/generated/capi.ts +695 -0
- package/src/bindings/generated/contract.ts +162 -0
- package/src/bindings/index.ts +10 -0
- package/src/bindings/runtime/convert.ts +307 -0
- package/src/bindings/runtime/diagnostics.ts +45 -0
- package/src/bindings/runtime/dispatch.ts +200 -0
- package/src/bindings/runtime/exception.ts +103 -0
- package/src/bindings/runtime/flags.ts +19 -0
- package/src/bindings/runtime/handle.ts +217 -0
- package/src/bindings/runtime/kinds.ts +53 -0
- package/src/bindings/runtime/marshal.ts +190 -0
- package/src/bindings/runtime/native.ts +150 -0
- package/src/bindings/runtime/ring.ts +54 -0
- package/src/bindings/runtime/scope.ts +133 -0
- package/src/bindings/runtime/trace.ts +65 -0
- package/src/connection.ts +35 -0
- package/src/database.ts +27 -0
- package/src/errors.ts +30 -0
- package/src/file-assets.d.ts +10 -0
- package/src/index.ts +17 -0
- package/src/library.ts +83 -0
- package/src/neo.ts +16 -0
- package/src/reader.ts +47 -0
- package/src/statement.ts +61 -0
- package/src/types.ts +52 -0
- package/src/version.ts +6 -0
- package/vendor/node-api/LICENSE +7 -0
- package/vendor/node-api/PROVENANCE.md +54 -0
- package/vendor/node-api/node-bindings.d.ts +1669 -0
- package/vendor/node-api/src/DuckDBAppender.ts +237 -0
- package/vendor/node-api/src/DuckDBClientContext.ts +13 -0
- package/vendor/node-api/src/DuckDBConnection.ts +315 -0
- package/vendor/node-api/src/DuckDBDataChunk.ts +412 -0
- package/vendor/node-api/src/DuckDBDataChunkWriter.ts +144 -0
- package/vendor/node-api/src/DuckDBExtractedStatements.ts +37 -0
- package/vendor/node-api/src/DuckDBInstance.ts +35 -0
- package/vendor/node-api/src/DuckDBInstanceCache.ts +29 -0
- package/vendor/node-api/src/DuckDBLogicalType.ts +446 -0
- package/vendor/node-api/src/DuckDBMaterializedResult.ts +39 -0
- package/vendor/node-api/src/DuckDBPendingResult.ts +83 -0
- package/vendor/node-api/src/DuckDBPreparedStatement.ts +376 -0
- package/vendor/node-api/src/DuckDBPreparedStatementCollection.ts +5 -0
- package/vendor/node-api/src/DuckDBPreparedStatementWeakRefCollection.ts +31 -0
- package/vendor/node-api/src/DuckDBResult.ts +403 -0
- package/vendor/node-api/src/DuckDBResultReader.ts +283 -0
- package/vendor/node-api/src/DuckDBScalarFunction.ts +149 -0
- package/vendor/node-api/src/DuckDBScalarFunctionBindInfo.ts +34 -0
- package/vendor/node-api/src/DuckDBScalarFunctionInfo.ts +34 -0
- package/vendor/node-api/src/DuckDBScalarFunctionInitInfo.ts +35 -0
- package/vendor/node-api/src/DuckDBTableFunction.ts +149 -0
- package/vendor/node-api/src/DuckDBTableFunctionBindInfo.ts +56 -0
- package/vendor/node-api/src/DuckDBTableFunctionInfo.ts +36 -0
- package/vendor/node-api/src/DuckDBTableFunctionInitInfo.ts +52 -0
- package/vendor/node-api/src/DuckDBType.ts +1 -0
- package/vendor/node-api/src/DuckDBTypeId.ts +46 -0
- package/vendor/node-api/src/DuckDBValueConverter.ts +23 -0
- package/vendor/node-api/src/DuckDBValueConverters.ts +461 -0
- package/vendor/node-api/src/DuckDBVector.ts +1 -0
- package/vendor/node-api/src/JS.ts +11 -0
- package/vendor/node-api/src/JSDuckDBValueConverter.ts +85 -0
- package/vendor/node-api/src/JSInputTypeForTypeId.ts +101 -0
- package/vendor/node-api/src/JSToDuckDBValueConverter.ts +136 -0
- package/vendor/node-api/src/JSTypeForTypeId.ts +78 -0
- package/vendor/node-api/src/Json.ts +7 -0
- package/vendor/node-api/src/JsonDuckDBValueConverter.ts +72 -0
- package/vendor/node-api/src/JsonTypeForTypeId.ts +86 -0
- package/vendor/node-api/src/ToDuckDBValueConverter.ts +68 -0
- package/vendor/node-api/src/ToDuckDBValueConverters.ts +303 -0
- package/vendor/node-api/src/configurationOptionDescriptions.ts +13 -0
- package/vendor/node-api/src/conversion/bytesFromString.ts +5 -0
- package/vendor/node-api/src/conversion/dateTimeStringConversion.ts +343 -0
- package/vendor/node-api/src/conversion/displayStringForDuckDBValue.ts +12 -0
- package/vendor/node-api/src/conversion/stringFromBlob.ts +48 -0
- package/vendor/node-api/src/conversion/stringFromDecimal.ts +129 -0
- package/vendor/node-api/src/conversion/varintDecode.ts +42 -0
- package/vendor/node-api/src/convertColumnsFromChunks.ts +28 -0
- package/vendor/node-api/src/convertColumnsObjectFromChunks.ts +29 -0
- package/vendor/node-api/src/convertRowObjectsFromChunks.ts +21 -0
- package/vendor/node-api/src/convertRowsFromChunks.ts +16 -0
- package/vendor/node-api/src/createConfig.ts +14 -0
- package/vendor/node-api/src/createDuckDBValueConverter.ts +17 -0
- package/vendor/node-api/src/createResult.ts +15 -0
- package/vendor/node-api/src/createValue.ts +355 -0
- package/vendor/node-api/src/duckdb.ts +51 -0
- package/vendor/node-api/src/enums.ts +7 -0
- package/vendor/node-api/src/getColumnsFromChunks.ts +13 -0
- package/vendor/node-api/src/getColumnsObjectFromChunks.ts +16 -0
- package/vendor/node-api/src/getRowObjectsFromChunks.ts +13 -0
- package/vendor/node-api/src/getRowsFromChunks.ts +12 -0
- package/vendor/node-api/src/index.ts +3 -0
- package/vendor/node-api/src/readValue.ts +31 -0
- package/vendor/node-api/src/sleep.ts +5 -0
- package/vendor/node-api/src/sql.ts +7 -0
- package/vendor/node-api/src/tsconfig.json +7 -0
- package/vendor/node-api/src/typeForValue.ts +144 -0
- package/vendor/node-api/src/types/BaseDuckDBType.ts +31 -0
- package/vendor/node-api/src/types/DuckDBAnyType.ts +13 -0
- package/vendor/node-api/src/types/DuckDBArrayType.ts +43 -0
- package/vendor/node-api/src/types/DuckDBBigIntType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBBigNumType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBBitType.ts +13 -0
- package/vendor/node-api/src/types/DuckDBBlobType.ts +13 -0
- package/vendor/node-api/src/types/DuckDBBooleanType.ts +13 -0
- package/vendor/node-api/src/types/DuckDBDateType.ts +29 -0
- package/vendor/node-api/src/types/DuckDBDecimalType.ts +46 -0
- package/vendor/node-api/src/types/DuckDBDoubleType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBEnumType.ts +111 -0
- package/vendor/node-api/src/types/DuckDBFloatType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBGeometryType.ts +36 -0
- package/vendor/node-api/src/types/DuckDBHugeIntType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBIntegerLiteralType.ts +13 -0
- package/vendor/node-api/src/types/DuckDBIntegerType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBIntervalType.ts +13 -0
- package/vendor/node-api/src/types/DuckDBListType.ts +35 -0
- package/vendor/node-api/src/types/DuckDBMapType.ts +47 -0
- package/vendor/node-api/src/types/DuckDBSQLNullType.ts +17 -0
- package/vendor/node-api/src/types/DuckDBSmallIntType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBStringLiteralType.ts +13 -0
- package/vendor/node-api/src/types/DuckDBStructType.ts +104 -0
- package/vendor/node-api/src/types/DuckDBTimeNSType.ts +20 -0
- package/vendor/node-api/src/types/DuckDBTimeTZType.ts +23 -0
- package/vendor/node-api/src/types/DuckDBTimeType.ts +20 -0
- package/vendor/node-api/src/types/DuckDBTimestampMillisecondsType.ts +29 -0
- package/vendor/node-api/src/types/DuckDBTimestampNanosecondsType.ts +29 -0
- package/vendor/node-api/src/types/DuckDBTimestampSecondsType.ts +29 -0
- package/vendor/node-api/src/types/DuckDBTimestampTZNanosecondsType.ts +32 -0
- package/vendor/node-api/src/types/DuckDBTimestampTZType.ts +32 -0
- package/vendor/node-api/src/types/DuckDBTimestampType.ts +32 -0
- package/vendor/node-api/src/types/DuckDBTinyIntType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBType.ts +86 -0
- package/vendor/node-api/src/types/DuckDBUBigIntType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBUHugeIntType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBUIntegerType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBUSmallIntType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBUTinyIntType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBUUIDType.ts +20 -0
- package/vendor/node-api/src/types/DuckDBUnionType.ts +74 -0
- package/vendor/node-api/src/types/DuckDBVarCharType.ts +13 -0
- package/vendor/node-api/src/types/DuckDBVariantType.ts +13 -0
- package/vendor/node-api/src/types/index.ts +44 -0
- package/vendor/node-api/src/values/DuckDBArrayValue.ts +18 -0
- package/vendor/node-api/src/values/DuckDBBitValue.ts +117 -0
- package/vendor/node-api/src/values/DuckDBBlobValue.ts +26 -0
- package/vendor/node-api/src/values/DuckDBDateValue.ts +43 -0
- package/vendor/node-api/src/values/DuckDBDecimalValue.ts +44 -0
- package/vendor/node-api/src/values/DuckDBGeometryValue.ts +30 -0
- package/vendor/node-api/src/values/DuckDBIntervalValue.ts +22 -0
- package/vendor/node-api/src/values/DuckDBListValue.ts +18 -0
- package/vendor/node-api/src/values/DuckDBMapValue.ts +25 -0
- package/vendor/node-api/src/values/DuckDBStructValue.ts +22 -0
- package/vendor/node-api/src/values/DuckDBTimeNSValue.ts +23 -0
- package/vendor/node-api/src/values/DuckDBTimeTZValue.ts +96 -0
- package/vendor/node-api/src/values/DuckDBTimeValue.ts +34 -0
- package/vendor/node-api/src/values/DuckDBTimestampMillisecondsValue.ts +29 -0
- package/vendor/node-api/src/values/DuckDBTimestampNanosecondsValue.ts +28 -0
- package/vendor/node-api/src/values/DuckDBTimestampSecondsValue.ts +28 -0
- package/vendor/node-api/src/values/DuckDBTimestampTZNanosecondsValue.ts +44 -0
- package/vendor/node-api/src/values/DuckDBTimestampTZValue.ts +54 -0
- package/vendor/node-api/src/values/DuckDBTimestampValue.ts +45 -0
- package/vendor/node-api/src/values/DuckDBTupleValue.ts +22 -0
- package/vendor/node-api/src/values/DuckDBUUIDValue.ts +48 -0
- package/vendor/node-api/src/values/DuckDBUnionValue.ts +22 -0
- package/vendor/node-api/src/values/DuckDBValue.ts +53 -0
- package/vendor/node-api/src/values/DuckDBVariantValue.ts +34 -0
- package/vendor/node-api/src/values/index.ts +24 -0
- package/vendor/node-api/src/vectors/DuckDBArrayVector.ts +107 -0
- package/vendor/node-api/src/vectors/DuckDBBigIntVector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBBigNumVector.ts +98 -0
- package/vendor/node-api/src/vectors/DuckDBBitVector.ts +102 -0
- package/vendor/node-api/src/vectors/DuckDBBlobVector.ts +112 -0
- package/vendor/node-api/src/vectors/DuckDBBooleanVector.ts +84 -0
- package/vendor/node-api/src/vectors/DuckDBDateVector.ts +80 -0
- package/vendor/node-api/src/vectors/DuckDBDecimal128Vector.ts +107 -0
- package/vendor/node-api/src/vectors/DuckDBDecimal16Vector.ts +104 -0
- package/vendor/node-api/src/vectors/DuckDBDecimal32Vector.ts +104 -0
- package/vendor/node-api/src/vectors/DuckDBDecimal64Vector.ts +104 -0
- package/vendor/node-api/src/vectors/DuckDBDoubleVector.ts +68 -0
- package/vendor/node-api/src/vectors/DuckDBEnum16Vector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBEnum32Vector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBEnum8Vector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBFloatVector.ts +68 -0
- package/vendor/node-api/src/vectors/DuckDBGeometryVector.ts +97 -0
- package/vendor/node-api/src/vectors/DuckDBHugeIntVector.ts +89 -0
- package/vendor/node-api/src/vectors/DuckDBIntegerVector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBIntervalVector.ts +100 -0
- package/vendor/node-api/src/vectors/DuckDBListVector.ts +221 -0
- package/vendor/node-api/src/vectors/DuckDBMapVector.ts +88 -0
- package/vendor/node-api/src/vectors/DuckDBSQLNullVector.ts +53 -0
- package/vendor/node-api/src/vectors/DuckDBSmallIntVector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBStructVector.ts +138 -0
- package/vendor/node-api/src/vectors/DuckDBTimeNSVector.ts +80 -0
- package/vendor/node-api/src/vectors/DuckDBTimeTZVector.ts +80 -0
- package/vendor/node-api/src/vectors/DuckDBTimeVector.ts +80 -0
- package/vendor/node-api/src/vectors/DuckDBTimestampMillisecondsVector.ts +88 -0
- package/vendor/node-api/src/vectors/DuckDBTimestampNanosecondsVector.ts +88 -0
- package/vendor/node-api/src/vectors/DuckDBTimestampSecondsVector.ts +88 -0
- package/vendor/node-api/src/vectors/DuckDBTimestampTZNanosecondsVector.ts +88 -0
- package/vendor/node-api/src/vectors/DuckDBTimestampTZVector.ts +86 -0
- package/vendor/node-api/src/vectors/DuckDBTimestampVector.ts +83 -0
- package/vendor/node-api/src/vectors/DuckDBTinyIntVector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBTupleVector.ts +125 -0
- package/vendor/node-api/src/vectors/DuckDBUBigIntVector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBUHugeIntVector.ts +89 -0
- package/vendor/node-api/src/vectors/DuckDBUIntegerVector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBUSmallIntVector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBUTinyIntVector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBUUIDVector.ts +89 -0
- package/vendor/node-api/src/vectors/DuckDBUnionVector.ts +84 -0
- package/vendor/node-api/src/vectors/DuckDBValidity.ts +104 -0
- package/vendor/node-api/src/vectors/DuckDBVarCharVector.ts +100 -0
- package/vendor/node-api/src/vectors/DuckDBVariantVector.ts +609 -0
- package/vendor/node-api/src/vectors/DuckDBVector.ts +33 -0
- package/vendor/node-api/src/vectors/createVector.ts +269 -0
- package/vendor/node-api/src/vectors/dataAccessors.ts +387 -0
- package/vendor/node-api/src/vectors/index.ts +50 -0
- package/vendor/node-api/src/vectors/vectorRegistry.ts +24 -0
- package/vendor/node-api/src/version.ts +5 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// Date, time, timestamp, hugeint and decimal helpers of the @duckdb/node-bindings
|
|
2
|
+
// contract. Each one converts its argument as the official binding does
|
|
3
|
+
// (bindings/src/duckdb_node_bindings.cpp and conversion_helpers.h at the vendored
|
|
4
|
+
// tag), then calls the shim's by-value wrapper of the C function.
|
|
5
|
+
import type {
|
|
6
|
+
Date_,
|
|
7
|
+
DateParts,
|
|
8
|
+
Decimal,
|
|
9
|
+
Time,
|
|
10
|
+
TimeParts,
|
|
11
|
+
Timestamp,
|
|
12
|
+
TimestampMilliseconds,
|
|
13
|
+
TimestampNanoseconds,
|
|
14
|
+
TimestampParts,
|
|
15
|
+
TimestampSeconds,
|
|
16
|
+
TimeTZ,
|
|
17
|
+
TimeTZParts,
|
|
18
|
+
} from "../generated/contract.ts";
|
|
19
|
+
import {
|
|
20
|
+
dateFromObject,
|
|
21
|
+
datePartsFromObject,
|
|
22
|
+
decimalFromObject,
|
|
23
|
+
expectNumber,
|
|
24
|
+
hugeintFromBigInt,
|
|
25
|
+
int32FromNumber,
|
|
26
|
+
int64FromNumber,
|
|
27
|
+
timeFromObject,
|
|
28
|
+
timePartsFromObject,
|
|
29
|
+
timestampFromObject,
|
|
30
|
+
timestampMillisecondsFromObject,
|
|
31
|
+
timestampNanosecondsFromObject,
|
|
32
|
+
timestampPartsFromObject,
|
|
33
|
+
timestampSecondsFromObject,
|
|
34
|
+
timeTzFromObject,
|
|
35
|
+
uhugeintFromBigInt,
|
|
36
|
+
uint32FromNumber,
|
|
37
|
+
} from "../runtime/convert.ts";
|
|
38
|
+
import { decode, encode, structBuffer } from "../runtime/marshal.ts";
|
|
39
|
+
import { shim } from "../runtime/native.ts";
|
|
40
|
+
|
|
41
|
+
// --- date and time ------------------------------------------------------------------
|
|
42
|
+
|
|
43
|
+
export function from_date(date: Date_): DateParts {
|
|
44
|
+
const out = structBuffer("date_struct");
|
|
45
|
+
shim.dbs_from_date(encode("date", dateFromObject(date)), out);
|
|
46
|
+
return decode<DateParts>("date_struct", out);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function to_date(parts: DateParts): Date_ {
|
|
50
|
+
const out = structBuffer("date");
|
|
51
|
+
shim.dbs_to_date(encode("date_struct", datePartsFromObject(parts)), out);
|
|
52
|
+
return decode<Date_>("date", out);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function is_finite_date(date: Date_): boolean {
|
|
56
|
+
return shim.dbs_is_finite_date(encode("date", dateFromObject(date)));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function from_time(time: Time): TimeParts {
|
|
60
|
+
const out = structBuffer("time_struct");
|
|
61
|
+
shim.dbs_from_time(encode("time", timeFromObject(time)), out);
|
|
62
|
+
return decode<TimeParts>("time_struct", out);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** micros and offset go through Number::Int64Value and Number::Int32Value, which coerce rather than reject. */
|
|
66
|
+
export function create_time_tz(micros: number, offset: number): TimeTZ {
|
|
67
|
+
const micros64 = int64FromNumber(micros);
|
|
68
|
+
const offset32 = int32FromNumber(offset);
|
|
69
|
+
const out = structBuffer("time_tz");
|
|
70
|
+
shim.dbs_create_time_tz(micros64, offset32, out);
|
|
71
|
+
return decode<TimeTZ>("time_tz", out);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function from_time_tz(time_tz: TimeTZ): TimeTZParts {
|
|
75
|
+
const out = structBuffer("time_tz_struct");
|
|
76
|
+
shim.dbs_from_time_tz(encode("time_tz", timeTzFromObject(time_tz)), out);
|
|
77
|
+
return decode<TimeTZParts>("time_tz_struct", out);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function to_time(parts: TimeParts): Time {
|
|
81
|
+
const out = structBuffer("time");
|
|
82
|
+
shim.dbs_to_time(encode("time_struct", timePartsFromObject(parts)), out);
|
|
83
|
+
return decode<Time>("time", out);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function from_timestamp(timestamp: Timestamp): TimestampParts {
|
|
87
|
+
const out = structBuffer("timestamp_struct");
|
|
88
|
+
shim.dbs_from_timestamp(encode("timestamp", timestampFromObject(timestamp)), out);
|
|
89
|
+
return decode<TimestampParts>("timestamp_struct", out);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function to_timestamp(parts: TimestampParts): Timestamp {
|
|
93
|
+
const out = structBuffer("timestamp");
|
|
94
|
+
shim.dbs_to_timestamp(encode("timestamp_struct", timestampPartsFromObject(parts)), out);
|
|
95
|
+
return decode<Timestamp>("timestamp", out);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function is_finite_timestamp(timestamp: Timestamp): boolean {
|
|
99
|
+
return shim.dbs_is_finite_timestamp(encode("timestamp", timestampFromObject(timestamp)));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function is_finite_timestamp_s(timestampSeconds: TimestampSeconds): boolean {
|
|
103
|
+
return shim.dbs_is_finite_timestamp_s(encode("timestamp_s", timestampSecondsFromObject(timestampSeconds)));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function is_finite_timestamp_ms(timestampMilliseconds: TimestampMilliseconds): boolean {
|
|
107
|
+
return shim.dbs_is_finite_timestamp_ms(
|
|
108
|
+
encode("timestamp_ms", timestampMillisecondsFromObject(timestampMilliseconds)),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function is_finite_timestamp_ns(timestampNanoseconds: TimestampNanoseconds): boolean {
|
|
113
|
+
return shim.dbs_is_finite_timestamp_ns(encode("timestamp_ns", timestampNanosecondsFromObject(timestampNanoseconds)));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// --- hugeint, uhugeint and decimal ------------------------------------------------------
|
|
117
|
+
|
|
118
|
+
export function hugeint_to_double(hugeint: bigint): number {
|
|
119
|
+
return shim.dbs_hugeint_to_double(encode("hugeint", hugeintFromBigInt(hugeint)));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** DuckDB returns 0 for a double outside the hugeint range. */
|
|
123
|
+
export function double_to_hugeint(double: number): bigint {
|
|
124
|
+
const input = expectNumber(double);
|
|
125
|
+
const out = structBuffer("hugeint");
|
|
126
|
+
shim.dbs_double_to_hugeint(input, out);
|
|
127
|
+
return decode<bigint>("hugeint", out);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function uhugeint_to_double(uhugeint: bigint): number {
|
|
131
|
+
return shim.dbs_uhugeint_to_double(encode("uhugeint", uhugeintFromBigInt(uhugeint)));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** DuckDB returns 0 for a double outside the uhugeint range, negative ones included. */
|
|
135
|
+
export function double_to_uhugeint(double: number): bigint {
|
|
136
|
+
const input = expectNumber(double);
|
|
137
|
+
const out = structBuffer("uhugeint");
|
|
138
|
+
shim.dbs_double_to_uhugeint(input, out);
|
|
139
|
+
return decode<bigint>("uhugeint", out);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* width and scale go through Number::Uint32Value and then narrow to uint8_t, as
|
|
144
|
+
* in the official binding. DuckDB returns a zeroed decimal when the value does
|
|
145
|
+
* not fit.
|
|
146
|
+
*/
|
|
147
|
+
export function double_to_decimal(double: number, width: number, scale: number): Decimal {
|
|
148
|
+
const input = expectNumber(double);
|
|
149
|
+
const width8 = uint32FromNumber(width) & 0xff;
|
|
150
|
+
const scale8 = uint32FromNumber(scale) & 0xff;
|
|
151
|
+
const out = structBuffer("decimal");
|
|
152
|
+
shim.dbs_double_to_decimal(input, width8, scale8, out);
|
|
153
|
+
return decode<Decimal>("decimal", out);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function decimal_to_double(decimal: Decimal): number {
|
|
157
|
+
return shim.dbs_decimal_to_double(encode("decimal", decimalFromObject(decimal)));
|
|
158
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Every function, enum, constant and type of the @duckdb/node-bindings contract
|
|
2
|
+
// (vendor/node-api/node-bindings.d.ts), gathered for src/bindings/index.ts.
|
|
3
|
+
export * from "../generated/contract.ts";
|
|
4
|
+
export * from "./appender.ts";
|
|
5
|
+
export * from "./data-chunk.ts";
|
|
6
|
+
export * from "./database.ts";
|
|
7
|
+
export * from "./datetime.ts";
|
|
8
|
+
export * from "./logical-types.ts";
|
|
9
|
+
export * from "./query.ts";
|
|
10
|
+
export * from "./scalar-function.ts";
|
|
11
|
+
export * from "./table-function.ts";
|
|
12
|
+
export * from "./values.ts";
|
|
13
|
+
export * from "./vector.ts";
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// Logical type functions of the @duckdb/node-bindings contract. Semantics, error
|
|
2
|
+
// text and index checks follow the official binding
|
|
3
|
+
// (bindings/src/duckdb_node_bindings.cpp at the vendored tag).
|
|
4
|
+
import { type Pointer, ptr } from "bun:ffi";
|
|
5
|
+
import { type LogicalType, Type } from "../generated/contract.ts";
|
|
6
|
+
import { checkIndexInRange, expectArray, expectString, uint32FromNumber } from "../runtime/convert.ts";
|
|
7
|
+
import type { Handle } from "../runtime/handle.ts";
|
|
8
|
+
import { unwrap } from "../runtime/handle.ts";
|
|
9
|
+
import { own } from "../runtime/kinds.ts";
|
|
10
|
+
import { cstr, takeCString } from "../runtime/marshal.ts";
|
|
11
|
+
import { duckdb } from "../runtime/native.ts";
|
|
12
|
+
|
|
13
|
+
function asLogicalType(handle: Handle): LogicalType {
|
|
14
|
+
return handle as unknown as LogicalType;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Wraps a logical type the caller owns; a null pointer stays null, as the official external does. */
|
|
18
|
+
function ownLogicalType(pointer: Pointer | null): LogicalType {
|
|
19
|
+
return asLogicalType(own("logical type", pointer as Pointer));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function logicalTypePointer(logical_type: unknown): Pointer | null {
|
|
23
|
+
return unwrap(logical_type, "logical type");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A C string DuckDB allocated, freed after reading. A null pointer throws what
|
|
28
|
+
* Napi::String::New throws for one.
|
|
29
|
+
*/
|
|
30
|
+
function takeString(pointer: Pointer | null): string {
|
|
31
|
+
const text = takeCString(pointer);
|
|
32
|
+
if (text === null) throw new Error("Invalid argument");
|
|
33
|
+
return text;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A `const char **` array of `names` in one buffer: a pointer slot per name (at
|
|
38
|
+
* least one, as the official binding allocates) followed by the NUL-terminated
|
|
39
|
+
* UTF-8 names it points to. Passing the buffer to the C call keeps the names
|
|
40
|
+
* alive for exactly as long as it runs.
|
|
41
|
+
*/
|
|
42
|
+
function cStringArray(names: readonly string[]): Uint8Array {
|
|
43
|
+
const strings = names.map((name) => cstr(name));
|
|
44
|
+
const slots = Math.max(names.length, 1) * 8;
|
|
45
|
+
const buffer = new Uint8Array(slots + strings.reduce((total, bytes) => total + bytes.byteLength, 0));
|
|
46
|
+
const pointers = new BigUint64Array(buffer.buffer, 0, slots / 8);
|
|
47
|
+
const base = ptr(buffer);
|
|
48
|
+
let offset = slots;
|
|
49
|
+
strings.forEach((bytes, i) => {
|
|
50
|
+
buffer.set(bytes, offset);
|
|
51
|
+
pointers[i] = BigInt(base + offset);
|
|
52
|
+
offset += bytes.byteLength;
|
|
53
|
+
});
|
|
54
|
+
return buffer;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The member types and names of create_struct_type and create_union_type, read in the official order. */
|
|
58
|
+
function members(
|
|
59
|
+
member_types: unknown,
|
|
60
|
+
member_names: unknown,
|
|
61
|
+
): { types: BigUint64Array; names: Uint8Array; count: number } {
|
|
62
|
+
const typesArray = expectArray(member_types);
|
|
63
|
+
const namesArray = expectArray(member_names);
|
|
64
|
+
const count = Math.min(typesArray.length, namesArray.length);
|
|
65
|
+
const types = new BigUint64Array(Math.max(count, 1));
|
|
66
|
+
const names: string[] = [];
|
|
67
|
+
for (let i = 0; i < count; i++) {
|
|
68
|
+
types[i] = BigInt(logicalTypePointer(typesArray[i]) ?? 0);
|
|
69
|
+
names.push(expectString(namesArray[i]));
|
|
70
|
+
}
|
|
71
|
+
return { types, names: cStringArray(names), count };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// --- creation -----------------------------------------------------------------------
|
|
75
|
+
|
|
76
|
+
export function create_logical_type(type: Type): LogicalType {
|
|
77
|
+
const id = uint32FromNumber(type);
|
|
78
|
+
// duckdb_create_logical_type returns a VARIANT without its child types, and
|
|
79
|
+
// using it crashes; see https://github.com/duckdb/duckdb/issues/24680.
|
|
80
|
+
if (id === Type.VARIANT) {
|
|
81
|
+
throw new Error("Cannot create a VARIANT logical type; see https://github.com/duckdb/duckdb/issues/24680");
|
|
82
|
+
}
|
|
83
|
+
return ownLogicalType(duckdb.duckdb_create_logical_type(id | 0) as Pointer | null);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function logical_type_get_alias(logical_type: LogicalType): string | null {
|
|
87
|
+
return takeCString(duckdb.duckdb_logical_type_get_alias(logicalTypePointer(logical_type)) as Pointer | null);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function logical_type_set_alias(logical_type: LogicalType, alias: string): void {
|
|
91
|
+
const pointer = logicalTypePointer(logical_type);
|
|
92
|
+
duckdb.duckdb_logical_type_set_alias(pointer, cstr(expectString(alias)));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function create_list_type(logical_type: LogicalType): LogicalType {
|
|
96
|
+
return ownLogicalType(duckdb.duckdb_create_list_type(logicalTypePointer(logical_type)) as Pointer | null);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function create_array_type(logical_type: LogicalType, array_size: number): LogicalType {
|
|
100
|
+
const child = logicalTypePointer(logical_type);
|
|
101
|
+
const size = uint32FromNumber(array_size);
|
|
102
|
+
return ownLogicalType(duckdb.duckdb_create_array_type(child, size) as Pointer | null);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function create_map_type(key_type: LogicalType, value_type: LogicalType): LogicalType {
|
|
106
|
+
const key = logicalTypePointer(key_type);
|
|
107
|
+
const value = logicalTypePointer(value_type);
|
|
108
|
+
return ownLogicalType(duckdb.duckdb_create_map_type(key, value) as Pointer | null);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function create_union_type(member_types: readonly LogicalType[], member_names: readonly string[]): LogicalType {
|
|
112
|
+
const { types, names, count } = members(member_types, member_names);
|
|
113
|
+
return ownLogicalType(duckdb.duckdb_create_union_type(types, names, count) as Pointer | null);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function create_struct_type(member_types: readonly LogicalType[], member_names: readonly string[]): LogicalType {
|
|
117
|
+
const { types, names, count } = members(member_types, member_names);
|
|
118
|
+
return ownLogicalType(duckdb.duckdb_create_struct_type(types, names, count) as Pointer | null);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function create_enum_type(member_names: readonly string[]): LogicalType {
|
|
122
|
+
const namesArray = expectArray(member_names);
|
|
123
|
+
const names = namesArray.map((name) => expectString(name));
|
|
124
|
+
return ownLogicalType(duckdb.duckdb_create_enum_type(cStringArray(names), names.length) as Pointer | null);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** width and scale go through Number::Uint32Value and then narrow to uint8_t, as in the official binding. */
|
|
128
|
+
export function create_decimal_type(width: number, scale: number): LogicalType {
|
|
129
|
+
const width8 = uint32FromNumber(width) & 0xff;
|
|
130
|
+
const scale8 = uint32FromNumber(scale) & 0xff;
|
|
131
|
+
return ownLogicalType(duckdb.duckdb_create_decimal_type(width8, scale8) as Pointer | null);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// --- accessors ----------------------------------------------------------------------
|
|
135
|
+
|
|
136
|
+
export function get_type_id(logical_type: LogicalType): Type {
|
|
137
|
+
return duckdb.duckdb_get_type_id(logicalTypePointer(logical_type)) as Type;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function decimal_width(logical_type: LogicalType): number {
|
|
141
|
+
return duckdb.duckdb_decimal_width(logicalTypePointer(logical_type));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function decimal_scale(logical_type: LogicalType): number {
|
|
145
|
+
return duckdb.duckdb_decimal_scale(logicalTypePointer(logical_type));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function decimal_internal_type(logical_type: LogicalType): Type {
|
|
149
|
+
return duckdb.duckdb_decimal_internal_type(logicalTypePointer(logical_type)) as Type;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function enum_internal_type(logical_type: LogicalType): Type {
|
|
153
|
+
return duckdb.duckdb_enum_internal_type(logicalTypePointer(logical_type)) as Type;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function enum_dictionary_size(logical_type: LogicalType): number {
|
|
157
|
+
return duckdb.duckdb_enum_dictionary_size(logicalTypePointer(logical_type));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** duckdb_enum_dictionary_value reads out of bounds for a bad index, so it is checked first. */
|
|
161
|
+
export function enum_dictionary_value(logical_type: LogicalType, index: number): string {
|
|
162
|
+
const pointer = logicalTypePointer(logical_type);
|
|
163
|
+
const position = uint32FromNumber(index);
|
|
164
|
+
checkIndexInRange(position, duckdb.duckdb_enum_dictionary_size(pointer), "enum value");
|
|
165
|
+
return takeString(duckdb.duckdb_enum_dictionary_value(pointer, position) as Pointer | null);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function list_type_child_type(logical_type: LogicalType): LogicalType {
|
|
169
|
+
return ownLogicalType(duckdb.duckdb_list_type_child_type(logicalTypePointer(logical_type)) as Pointer | null);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function array_type_child_type(logical_type: LogicalType): LogicalType {
|
|
173
|
+
return ownLogicalType(duckdb.duckdb_array_type_child_type(logicalTypePointer(logical_type)) as Pointer | null);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function array_type_array_size(logical_type: LogicalType): number {
|
|
177
|
+
return Number(duckdb.duckdb_array_type_array_size(logicalTypePointer(logical_type)));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function map_type_key_type(logical_type: LogicalType): LogicalType {
|
|
181
|
+
return ownLogicalType(duckdb.duckdb_map_type_key_type(logicalTypePointer(logical_type)) as Pointer | null);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function map_type_value_type(logical_type: LogicalType): LogicalType {
|
|
185
|
+
return ownLogicalType(duckdb.duckdb_map_type_value_type(logicalTypePointer(logical_type)) as Pointer | null);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function struct_type_child_count(logical_type: LogicalType): number {
|
|
189
|
+
return Number(duckdb.duckdb_struct_type_child_count(logicalTypePointer(logical_type)));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** The struct accessors throw a C++ exception across the C boundary for a bad index, so it is checked first. */
|
|
193
|
+
export function struct_type_child_name(logical_type: LogicalType, index: number): string {
|
|
194
|
+
const pointer = logicalTypePointer(logical_type);
|
|
195
|
+
const position = uint32FromNumber(index);
|
|
196
|
+
checkIndexInRange(position, Number(duckdb.duckdb_struct_type_child_count(pointer)), "struct entry");
|
|
197
|
+
return takeString(duckdb.duckdb_struct_type_child_name(pointer, position) as Pointer | null);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function struct_type_child_type(logical_type: LogicalType, index: number): LogicalType {
|
|
201
|
+
const pointer = logicalTypePointer(logical_type);
|
|
202
|
+
const position = uint32FromNumber(index);
|
|
203
|
+
checkIndexInRange(position, Number(duckdb.duckdb_struct_type_child_count(pointer)), "struct entry");
|
|
204
|
+
return ownLogicalType(duckdb.duckdb_struct_type_child_type(pointer, position) as Pointer | null);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function union_type_member_count(logical_type: LogicalType): number {
|
|
208
|
+
return Number(duckdb.duckdb_union_type_member_count(logicalTypePointer(logical_type)));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function union_type_member_name(logical_type: LogicalType, index: number): string {
|
|
212
|
+
const pointer = logicalTypePointer(logical_type);
|
|
213
|
+
const position = uint32FromNumber(index);
|
|
214
|
+
checkIndexInRange(position, Number(duckdb.duckdb_union_type_member_count(pointer)), "union member");
|
|
215
|
+
return takeString(duckdb.duckdb_union_type_member_name(pointer, position) as Pointer | null);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function union_type_member_type(logical_type: LogicalType, index: number): LogicalType {
|
|
219
|
+
const pointer = logicalTypePointer(logical_type);
|
|
220
|
+
const position = uint32FromNumber(index);
|
|
221
|
+
checkIndexInRange(position, Number(duckdb.duckdb_union_type_member_count(pointer)), "union member");
|
|
222
|
+
return ownLogicalType(duckdb.duckdb_union_type_member_type(pointer, position) as Pointer | null);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function geometry_type_get_crs(logical_type: LogicalType): string | null {
|
|
226
|
+
return takeCString(duckdb.duckdb_geometry_type_get_crs(logicalTypePointer(logical_type)) as Pointer | null);
|
|
227
|
+
}
|