@haybarn/node-api 1.5.5-rc1 → 2.0.0-rc3
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 -20
- 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
package/lib/DuckDBDataChunk.js
CHANGED
|
@@ -13,7 +13,16 @@ class DuckDBDataChunk {
|
|
|
13
13
|
this.chunk = chunk;
|
|
14
14
|
}
|
|
15
15
|
static create(types, rowCount) {
|
|
16
|
-
|
|
16
|
+
let chunk;
|
|
17
|
+
try {
|
|
18
|
+
chunk = new DuckDBDataChunk(node_bindings_1.default.create_data_chunk(types.map((t) => t.toLogicalType().logical_type)));
|
|
19
|
+
}
|
|
20
|
+
catch (cause) {
|
|
21
|
+
// The binding knows the chunk was refused but not which type did it, so
|
|
22
|
+
// name them here. Zero columns is a legitimate chunk, so there is
|
|
23
|
+
// nothing to check on the way out; only the refusal is an error.
|
|
24
|
+
throw new Error(`Cannot create a data chunk with these column types: ${types.join(', ')}`, { cause });
|
|
25
|
+
}
|
|
17
26
|
if (rowCount != undefined) {
|
|
18
27
|
chunk.rowCount = rowCount;
|
|
19
28
|
}
|
|
@@ -34,6 +43,23 @@ class DuckDBDataChunk {
|
|
|
34
43
|
throw new Error(`A data chunk cannot have more than ${maxRowCount} rows`);
|
|
35
44
|
}
|
|
36
45
|
node_bindings_1.default.data_chunk_set_size(this.chunk, count);
|
|
46
|
+
// Cached vectors were built for the previous row count, so they are the
|
|
47
|
+
// wrong size now. This matters most for a table function's output chunk,
|
|
48
|
+
// which arrives empty and is sized by the function on every call.
|
|
49
|
+
this.vectors.length = 0;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Refuses a column count that does not match the chunk's.
|
|
53
|
+
*
|
|
54
|
+
* A short array would leave the remaining vectors never written and never
|
|
55
|
+
* flushed while the chunk reports a non-zero row count, and reading or
|
|
56
|
+
* appending it then crashes the process instead of raising.
|
|
57
|
+
*/
|
|
58
|
+
assertColumnCount(count) {
|
|
59
|
+
const columnCount = this.columnCount;
|
|
60
|
+
if (count !== columnCount) {
|
|
61
|
+
throw new Error(`Provided number of columns (${count}) does not match chunk column count (${columnCount})`);
|
|
62
|
+
}
|
|
37
63
|
}
|
|
38
64
|
getColumnVector(columnIndex) {
|
|
39
65
|
if (this.vectors[columnIndex]) {
|
|
@@ -73,6 +99,31 @@ class DuckDBDataChunk {
|
|
|
73
99
|
}
|
|
74
100
|
vector.flush();
|
|
75
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* `setColumnValues` with each value converted on the way in: the write
|
|
104
|
+
* counterpart of `convertColumnValues`.
|
|
105
|
+
*
|
|
106
|
+
* The column's type comes from its vector, so the converter is the only
|
|
107
|
+
* thing the caller supplies.
|
|
108
|
+
*/
|
|
109
|
+
setColumnValuesConverted(columnIndex, values, converter) {
|
|
110
|
+
const vector = this.getColumnVector(columnIndex);
|
|
111
|
+
if (vector.itemCount !== values.length) {
|
|
112
|
+
throw new Error(`number of values must equal chunk row count`);
|
|
113
|
+
}
|
|
114
|
+
const { type } = vector;
|
|
115
|
+
try {
|
|
116
|
+
for (let i = 0; i < values.length; i++) {
|
|
117
|
+
vector.setItem(i, converter(values[i], type, converter));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch (cause) {
|
|
121
|
+
throw new Error(`Failed to set column ${columnIndex} (${type})`, {
|
|
122
|
+
cause,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
vector.flush();
|
|
126
|
+
}
|
|
76
127
|
visitColumns(visitColumn) {
|
|
77
128
|
const columnCount = this.columnCount;
|
|
78
129
|
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
@@ -104,6 +155,7 @@ class DuckDBDataChunk {
|
|
|
104
155
|
return convertedColumns;
|
|
105
156
|
}
|
|
106
157
|
setColumns(columns) {
|
|
158
|
+
this.assertColumnCount(columns.length);
|
|
107
159
|
if (columns.length > 0) {
|
|
108
160
|
this.rowCount = columns[0].length;
|
|
109
161
|
}
|
|
@@ -111,6 +163,19 @@ class DuckDBDataChunk {
|
|
|
111
163
|
this.setColumnValues(columnIndex, columns[columnIndex]);
|
|
112
164
|
}
|
|
113
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* `setColumns` with each value converted on the way in: the write
|
|
168
|
+
* counterpart of `convertColumns`.
|
|
169
|
+
*/
|
|
170
|
+
setColumnsConverted(columns, converter) {
|
|
171
|
+
this.assertColumnCount(columns.length);
|
|
172
|
+
if (columns.length > 0) {
|
|
173
|
+
this.rowCount = columns[0].length;
|
|
174
|
+
}
|
|
175
|
+
for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) {
|
|
176
|
+
this.setColumnValuesConverted(columnIndex, columns[columnIndex], converter);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
114
179
|
appendToColumnsObject(columnNames, columnsObject) {
|
|
115
180
|
const columnCount = this.columnCount;
|
|
116
181
|
if (columnNames.length !== columnCount) {
|
|
@@ -190,6 +255,34 @@ class DuckDBDataChunk {
|
|
|
190
255
|
vector.flush();
|
|
191
256
|
}
|
|
192
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* `setRows` with each value converted on the way in: the write counterpart
|
|
260
|
+
* of `convertRows`.
|
|
261
|
+
*
|
|
262
|
+
* Each column's type comes from its vector, so the converter is the only
|
|
263
|
+
* thing the caller supplies.
|
|
264
|
+
*/
|
|
265
|
+
setRowsConverted(rows, converter) {
|
|
266
|
+
this.rowCount = rows.length;
|
|
267
|
+
const columnCount = this.columnCount;
|
|
268
|
+
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
269
|
+
const vector = this.getColumnVector(columnIndex);
|
|
270
|
+
const { type } = vector;
|
|
271
|
+
// Wrapped per column rather than per value: a conversion failure names
|
|
272
|
+
// the column it came from without a try/catch in the inner loop.
|
|
273
|
+
try {
|
|
274
|
+
for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
|
|
275
|
+
vector.setItem(rowIndex, converter(rows[rowIndex][columnIndex], type, converter));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
catch (cause) {
|
|
279
|
+
throw new Error(`Failed to set column ${columnIndex} (${type})`, {
|
|
280
|
+
cause,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
vector.flush();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
193
286
|
appendToRowObjects(columnNames, rowObjects) {
|
|
194
287
|
const columnCount = this.columnCount;
|
|
195
288
|
if (columnNames.length !== columnCount) {
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { DuckDBAppender } from './DuckDBAppender';
|
|
2
|
+
import { DuckDBDataChunk } from './DuckDBDataChunk';
|
|
3
|
+
import { DuckDBType } from './DuckDBType';
|
|
4
|
+
import { ToDuckDBValueConverter } from './ToDuckDBValueConverter';
|
|
5
|
+
import { DuckDBValue } from './values';
|
|
6
|
+
/** Receives each data chunk a `DuckDBDataChunkWriter` fills. */
|
|
7
|
+
export type DuckDBDataChunkSink = (chunk: DuckDBDataChunk) => void;
|
|
8
|
+
/**
|
|
9
|
+
* `converter` is optional only when the rows are already `DuckDBValue`s, which
|
|
10
|
+
* is what `T` defaults to. Supply one to write some other representation —
|
|
11
|
+
* `JSToDuckDBValueConverter` for plain JS — and `T` follows from it.
|
|
12
|
+
*/
|
|
13
|
+
export type DuckDBDataChunkWriterOptions<T> = {
|
|
14
|
+
/**
|
|
15
|
+
* How many rows each emitted data chunk holds — its `rowCount`. Defaults to
|
|
16
|
+
* the DuckDB vector size, which is also the most a data chunk can hold.
|
|
17
|
+
*/
|
|
18
|
+
readonly rowsPerDataChunk?: number;
|
|
19
|
+
} & ([DuckDBValue] extends [T] ? {
|
|
20
|
+
readonly converter?: ToDuckDBValueConverter<T>;
|
|
21
|
+
} : {
|
|
22
|
+
readonly converter: ToDuckDBValueConverter<T>;
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Accumulates rows and emits them as filled data chunks, one per
|
|
26
|
+
* `rowsPerDataChunk` rows, passing each to `sink`.
|
|
27
|
+
*
|
|
28
|
+
* Rows are `DuckDBValue`s by default. Supply a converter to write some other
|
|
29
|
+
* representation; the row type follows from it.
|
|
30
|
+
*
|
|
31
|
+
* const writer = DuckDBDataChunkWriter.forAppender(appender, {
|
|
32
|
+
* converter: JSToDuckDBValueConverter,
|
|
33
|
+
* });
|
|
34
|
+
* for (const row of rows) {
|
|
35
|
+
* writer.appendRow(row);
|
|
36
|
+
* }
|
|
37
|
+
* writer.flush();
|
|
38
|
+
*
|
|
39
|
+
* `flush` emits whatever is buffered, so call it when done: the last chunk is
|
|
40
|
+
* usually a partial one. Rows already grouped into chunk-sized batches need no
|
|
41
|
+
* writer — fill a `DuckDBDataChunk` and pass it to the destination directly.
|
|
42
|
+
*/
|
|
43
|
+
export declare class DuckDBDataChunkWriter<T = DuckDBValue> {
|
|
44
|
+
private readonly types;
|
|
45
|
+
private readonly sink;
|
|
46
|
+
private readonly rowsPerDataChunk;
|
|
47
|
+
private readonly converter?;
|
|
48
|
+
private rows;
|
|
49
|
+
constructor(types: readonly DuckDBType[], sink: DuckDBDataChunkSink, options?: DuckDBDataChunkWriterOptions<T>);
|
|
50
|
+
/**
|
|
51
|
+
* A writer that appends each filled data chunk to `appender`, using the
|
|
52
|
+
* appender's own column types.
|
|
53
|
+
*
|
|
54
|
+
* Equivalent to constructing one with those types and a sink that calls
|
|
55
|
+
* `appendDataChunk`, but with nothing to keep in step by hand.
|
|
56
|
+
*/
|
|
57
|
+
static forAppender<T = DuckDBValue>(appender: DuckDBAppender, options?: DuckDBDataChunkWriterOptions<T>): DuckDBDataChunkWriter<T>;
|
|
58
|
+
get bufferedRowCount(): number;
|
|
59
|
+
/**
|
|
60
|
+
* Buffers one row, emitting a data chunk once `rowsPerDataChunk` are held.
|
|
61
|
+
*
|
|
62
|
+
* The row is copied, so the same array can be reused across calls.
|
|
63
|
+
*/
|
|
64
|
+
appendRow(values: readonly (T | null)[]): void;
|
|
65
|
+
/**
|
|
66
|
+
* Emits the buffered rows as one data chunk. A no-op when none are
|
|
67
|
+
* buffered, so it is safe to call more than once.
|
|
68
|
+
*
|
|
69
|
+
* The buffer is emptied either way: if converting the rows fails, or the
|
|
70
|
+
* sink rejects the chunk, those rows are discarded along with the error.
|
|
71
|
+
* Appending afterwards starts a fresh chunk.
|
|
72
|
+
*/
|
|
73
|
+
flush(): void;
|
|
74
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DuckDBDataChunkWriter = void 0;
|
|
7
|
+
const node_bindings_1 = __importDefault(require("@haybarn/node-bindings"));
|
|
8
|
+
const DuckDBDataChunk_1 = require("./DuckDBDataChunk");
|
|
9
|
+
/**
|
|
10
|
+
* Accumulates rows and emits them as filled data chunks, one per
|
|
11
|
+
* `rowsPerDataChunk` rows, passing each to `sink`.
|
|
12
|
+
*
|
|
13
|
+
* Rows are `DuckDBValue`s by default. Supply a converter to write some other
|
|
14
|
+
* representation; the row type follows from it.
|
|
15
|
+
*
|
|
16
|
+
* const writer = DuckDBDataChunkWriter.forAppender(appender, {
|
|
17
|
+
* converter: JSToDuckDBValueConverter,
|
|
18
|
+
* });
|
|
19
|
+
* for (const row of rows) {
|
|
20
|
+
* writer.appendRow(row);
|
|
21
|
+
* }
|
|
22
|
+
* writer.flush();
|
|
23
|
+
*
|
|
24
|
+
* `flush` emits whatever is buffered, so call it when done: the last chunk is
|
|
25
|
+
* usually a partial one. Rows already grouped into chunk-sized batches need no
|
|
26
|
+
* writer — fill a `DuckDBDataChunk` and pass it to the destination directly.
|
|
27
|
+
*/
|
|
28
|
+
class DuckDBDataChunkWriter {
|
|
29
|
+
types;
|
|
30
|
+
sink;
|
|
31
|
+
rowsPerDataChunk;
|
|
32
|
+
converter;
|
|
33
|
+
rows = [];
|
|
34
|
+
constructor(types, sink, options = {}) {
|
|
35
|
+
this.types = types;
|
|
36
|
+
this.sink = sink;
|
|
37
|
+
const maxRowCount = node_bindings_1.default.vector_size();
|
|
38
|
+
this.rowsPerDataChunk = options.rowsPerDataChunk ?? maxRowCount;
|
|
39
|
+
// Checked here rather than left to the first flush, which is where the
|
|
40
|
+
// chunk itself would refuse it — a whole buffer's worth of rows later.
|
|
41
|
+
if (this.rowsPerDataChunk < 1 || this.rowsPerDataChunk > maxRowCount) {
|
|
42
|
+
throw new Error(`rowsPerDataChunk must be between 1 and ${maxRowCount}, got ${this.rowsPerDataChunk}`);
|
|
43
|
+
}
|
|
44
|
+
this.converter = options.converter;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A writer that appends each filled data chunk to `appender`, using the
|
|
48
|
+
* appender's own column types.
|
|
49
|
+
*
|
|
50
|
+
* Equivalent to constructing one with those types and a sink that calls
|
|
51
|
+
* `appendDataChunk`, but with nothing to keep in step by hand.
|
|
52
|
+
*/
|
|
53
|
+
static forAppender(appender, options = {}) {
|
|
54
|
+
const types = [];
|
|
55
|
+
const columnCount = appender.columnCount;
|
|
56
|
+
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
57
|
+
types.push(appender.columnType(columnIndex));
|
|
58
|
+
}
|
|
59
|
+
return new DuckDBDataChunkWriter(types, (chunk) => appender.appendDataChunk(chunk), options);
|
|
60
|
+
}
|
|
61
|
+
get bufferedRowCount() {
|
|
62
|
+
return this.rows.length;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Buffers one row, emitting a data chunk once `rowsPerDataChunk` are held.
|
|
66
|
+
*
|
|
67
|
+
* The row is copied, so the same array can be reused across calls.
|
|
68
|
+
*/
|
|
69
|
+
appendRow(values) {
|
|
70
|
+
if (values.length !== this.types.length) {
|
|
71
|
+
throw new Error(`Provided number of values (${values.length}) does not match number of types (${this.types.length})`);
|
|
72
|
+
}
|
|
73
|
+
this.rows.push(values.slice());
|
|
74
|
+
if (this.rows.length >= this.rowsPerDataChunk) {
|
|
75
|
+
this.flush();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Emits the buffered rows as one data chunk. A no-op when none are
|
|
80
|
+
* buffered, so it is safe to call more than once.
|
|
81
|
+
*
|
|
82
|
+
* The buffer is emptied either way: if converting the rows fails, or the
|
|
83
|
+
* sink rejects the chunk, those rows are discarded along with the error.
|
|
84
|
+
* Appending afterwards starts a fresh chunk.
|
|
85
|
+
*/
|
|
86
|
+
flush() {
|
|
87
|
+
if (this.rows.length === 0) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
// Taken before anything that can throw. Left in place, a batch that failed
|
|
91
|
+
// to convert or that the sink rejected would still be buffered, and later
|
|
92
|
+
// appends would grow it past `rowsPerDataChunk` and eventually past what a
|
|
93
|
+
// data chunk can hold at all — by which point the writer can no longer
|
|
94
|
+
// flush and the original error is long gone.
|
|
95
|
+
const rows = this.rows;
|
|
96
|
+
this.rows = [];
|
|
97
|
+
const chunk = DuckDBDataChunk_1.DuckDBDataChunk.create(this.types);
|
|
98
|
+
if (this.converter) {
|
|
99
|
+
chunk.setRowsConverted(rows, this.converter);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// Without a converter the options type has already constrained `T` to
|
|
103
|
+
// `DuckDBValue`, which is the only thing that makes this cast sound.
|
|
104
|
+
chunk.setRows(rows);
|
|
105
|
+
}
|
|
106
|
+
this.sink(chunk);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.DuckDBDataChunkWriter = DuckDBDataChunkWriter;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import duckdb from '@haybarn/node-bindings';
|
|
2
|
-
import { DuckDBArrayType, DuckDBDecimalType, DuckDBEnumType, DuckDBListType, DuckDBMapType, DuckDBStructType, DuckDBType, DuckDBUnionType } from './DuckDBType';
|
|
2
|
+
import { DuckDBArrayType, DuckDBDecimalType, DuckDBEnumType, DuckDBGeometryType, DuckDBListType, DuckDBMapType, DuckDBStructType, DuckDBType, DuckDBUnionType } from './DuckDBType';
|
|
3
3
|
import { DuckDBTypeId } from './DuckDBTypeId';
|
|
4
4
|
export declare class DuckDBLogicalType {
|
|
5
5
|
readonly logical_type: duckdb.LogicalType;
|
|
@@ -64,3 +64,7 @@ export declare class DuckDBUnionLogicalType extends DuckDBLogicalType {
|
|
|
64
64
|
memberTypes(): DuckDBType[];
|
|
65
65
|
asType(): DuckDBUnionType;
|
|
66
66
|
}
|
|
67
|
+
export declare class DuckDBGeometryLogicalType extends DuckDBLogicalType {
|
|
68
|
+
get crs(): string | undefined;
|
|
69
|
+
asType(): DuckDBGeometryType;
|
|
70
|
+
}
|
package/lib/DuckDBLogicalType.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DuckDBUnionLogicalType = exports.DuckDBArrayLogicalType = exports.DuckDBMapLogicalType = exports.DuckDBStructLogicalType = exports.DuckDBListLogicalType = exports.DuckDBEnumLogicalType = exports.DuckDBDecimalLogicalType = exports.DuckDBLogicalType = void 0;
|
|
6
|
+
exports.DuckDBGeometryLogicalType = exports.DuckDBUnionLogicalType = exports.DuckDBArrayLogicalType = exports.DuckDBMapLogicalType = exports.DuckDBStructLogicalType = exports.DuckDBListLogicalType = exports.DuckDBEnumLogicalType = exports.DuckDBDecimalLogicalType = exports.DuckDBLogicalType = void 0;
|
|
7
7
|
const node_bindings_1 = __importDefault(require("@haybarn/node-bindings"));
|
|
8
8
|
const DuckDBType_1 = require("./DuckDBType");
|
|
9
9
|
const DuckDBTypeId_1 = require("./DuckDBTypeId");
|
|
@@ -28,6 +28,8 @@ class DuckDBLogicalType {
|
|
|
28
28
|
return new DuckDBArrayLogicalType(logical_type);
|
|
29
29
|
case node_bindings_1.default.Type.UNION:
|
|
30
30
|
return new DuckDBUnionLogicalType(logical_type);
|
|
31
|
+
case node_bindings_1.default.Type.GEOMETRY:
|
|
32
|
+
return new DuckDBGeometryLogicalType(logical_type);
|
|
31
33
|
default:
|
|
32
34
|
return new DuckDBLogicalType(logical_type);
|
|
33
35
|
}
|
|
@@ -165,6 +167,12 @@ class DuckDBLogicalType {
|
|
|
165
167
|
return DuckDBType_1.DuckDBIntegerLiteralType.create(alias);
|
|
166
168
|
case DuckDBTypeId_1.DuckDBTypeId.TIME_NS:
|
|
167
169
|
return DuckDBType_1.DuckDBTimeNSType.create(alias);
|
|
170
|
+
case DuckDBTypeId_1.DuckDBTypeId.GEOMETRY:
|
|
171
|
+
throw new Error('Expected override');
|
|
172
|
+
case DuckDBTypeId_1.DuckDBTypeId.VARIANT:
|
|
173
|
+
return DuckDBType_1.DuckDBVariantType.create(alias);
|
|
174
|
+
case DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_TZ_NS:
|
|
175
|
+
return DuckDBType_1.DuckDBTimestampTZNanosecondsType.create(alias);
|
|
168
176
|
default:
|
|
169
177
|
throw new Error(`Unexpected type id: ${this.typeId}`);
|
|
170
178
|
}
|
|
@@ -326,3 +334,12 @@ class DuckDBUnionLogicalType extends DuckDBLogicalType {
|
|
|
326
334
|
}
|
|
327
335
|
}
|
|
328
336
|
exports.DuckDBUnionLogicalType = DuckDBUnionLogicalType;
|
|
337
|
+
class DuckDBGeometryLogicalType extends DuckDBLogicalType {
|
|
338
|
+
get crs() {
|
|
339
|
+
return node_bindings_1.default.geometry_type_get_crs(this.logical_type) || undefined;
|
|
340
|
+
}
|
|
341
|
+
asType() {
|
|
342
|
+
return DuckDBType_1.DuckDBGeometryType.create(this.alias, this.crs);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
exports.DuckDBGeometryLogicalType = DuckDBGeometryLogicalType;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import duckdb from '@haybarn/node-bindings';
|
|
2
2
|
import { DuckDBDataChunk } from './DuckDBDataChunk';
|
|
3
3
|
import { DuckDBResult } from './DuckDBResult';
|
|
4
|
+
import { StatementType } from './enums';
|
|
4
5
|
export declare class DuckDBMaterializedResult extends DuckDBResult {
|
|
5
|
-
|
|
6
|
+
private closedCounts;
|
|
7
|
+
constructor(result: duckdb.Result, preparedStatementType?: StatementType);
|
|
8
|
+
/**
|
|
9
|
+
* Same as `DuckDBResult.closeSync`; the row and chunk counts also stay
|
|
10
|
+
* available. Getting a chunk throws.
|
|
11
|
+
*/
|
|
12
|
+
closeSync(): void;
|
|
6
13
|
get rowCount(): number;
|
|
7
14
|
get chunkCount(): number;
|
|
8
15
|
getChunk(chunkIndex: number): DuckDBDataChunk;
|
|
@@ -8,13 +8,33 @@ const node_bindings_1 = __importDefault(require("@haybarn/node-bindings"));
|
|
|
8
8
|
const DuckDBDataChunk_1 = require("./DuckDBDataChunk");
|
|
9
9
|
const DuckDBResult_1 = require("./DuckDBResult");
|
|
10
10
|
class DuckDBMaterializedResult extends DuckDBResult_1.DuckDBResult {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
closedCounts;
|
|
12
|
+
constructor(result, preparedStatementType) {
|
|
13
|
+
super(result, preparedStatementType);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Same as `DuckDBResult.closeSync`; the row and chunk counts also stay
|
|
17
|
+
* available. Getting a chunk throws.
|
|
18
|
+
*/
|
|
19
|
+
closeSync() {
|
|
20
|
+
if (!this.closedCounts) {
|
|
21
|
+
this.closedCounts = {
|
|
22
|
+
rowCount: this.rowCount,
|
|
23
|
+
chunkCount: this.chunkCount,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
super.closeSync();
|
|
13
27
|
}
|
|
14
28
|
get rowCount() {
|
|
29
|
+
if (this.closedCounts) {
|
|
30
|
+
return this.closedCounts.rowCount;
|
|
31
|
+
}
|
|
15
32
|
return node_bindings_1.default.row_count(this.result);
|
|
16
33
|
}
|
|
17
34
|
get chunkCount() {
|
|
35
|
+
if (this.closedCounts) {
|
|
36
|
+
return this.closedCounts.chunkCount;
|
|
37
|
+
}
|
|
18
38
|
return node_bindings_1.default.result_chunk_count(this.result);
|
|
19
39
|
}
|
|
20
40
|
getChunk(chunkIndex) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import duckdb from '@haybarn/node-bindings';
|
|
2
2
|
import { DuckDBResult } from './DuckDBResult';
|
|
3
3
|
import { DuckDBResultReader } from './DuckDBResultReader';
|
|
4
|
+
import { StatementType } from './enums';
|
|
4
5
|
export declare enum DuckDBPendingResultState {
|
|
5
6
|
RESULT_READY = 0,
|
|
6
7
|
RESULT_NOT_READY = 1,
|
|
@@ -8,7 +9,21 @@ export declare enum DuckDBPendingResultState {
|
|
|
8
9
|
}
|
|
9
10
|
export declare class DuckDBPendingResult {
|
|
10
11
|
private readonly pending_result;
|
|
11
|
-
|
|
12
|
+
private readonly preparedStatementType;
|
|
13
|
+
/**
|
|
14
|
+
* `preparedStatementType` is passed on to the result; see `DuckDBResult`.
|
|
15
|
+
*/
|
|
16
|
+
constructor(pending_result: duckdb.PendingResult, preparedStatementType?: StatementType);
|
|
17
|
+
/**
|
|
18
|
+
* Destroys the pending result. On DuckDB 2.0, a pending result whose result
|
|
19
|
+
* has not been gotten blocks its connection from starting another statement
|
|
20
|
+
* until it is closed.
|
|
21
|
+
*
|
|
22
|
+
* Running tasks or getting the result afterwards throws. If getting the
|
|
23
|
+
* result is in flight, the pending result is destroyed once it finishes; the
|
|
24
|
+
* result it returns is unaffected. Closing again does nothing.
|
|
25
|
+
*/
|
|
26
|
+
closeSync(): void;
|
|
12
27
|
runTask(): DuckDBPendingResultState;
|
|
13
28
|
runAllTasks(): Promise<void>;
|
|
14
29
|
getResult(): Promise<DuckDBResult>;
|
|
@@ -17,8 +17,25 @@ var DuckDBPendingResultState;
|
|
|
17
17
|
})(DuckDBPendingResultState || (exports.DuckDBPendingResultState = DuckDBPendingResultState = {}));
|
|
18
18
|
class DuckDBPendingResult {
|
|
19
19
|
pending_result;
|
|
20
|
-
|
|
20
|
+
preparedStatementType;
|
|
21
|
+
/**
|
|
22
|
+
* `preparedStatementType` is passed on to the result; see `DuckDBResult`.
|
|
23
|
+
*/
|
|
24
|
+
constructor(pending_result, preparedStatementType) {
|
|
21
25
|
this.pending_result = pending_result;
|
|
26
|
+
this.preparedStatementType = preparedStatementType;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Destroys the pending result. On DuckDB 2.0, a pending result whose result
|
|
30
|
+
* has not been gotten blocks its connection from starting another statement
|
|
31
|
+
* until it is closed.
|
|
32
|
+
*
|
|
33
|
+
* Running tasks or getting the result afterwards throws. If getting the
|
|
34
|
+
* result is in flight, the pending result is destroyed once it finishes; the
|
|
35
|
+
* result it returns is unaffected. Closing again does nothing.
|
|
36
|
+
*/
|
|
37
|
+
closeSync() {
|
|
38
|
+
node_bindings_1.default.destroy_pending_sync(this.pending_result);
|
|
22
39
|
}
|
|
23
40
|
runTask() {
|
|
24
41
|
const pending_state = node_bindings_1.default.pending_execute_task(this.pending_result);
|
|
@@ -41,7 +58,7 @@ class DuckDBPendingResult {
|
|
|
41
58
|
}
|
|
42
59
|
}
|
|
43
60
|
async getResult() {
|
|
44
|
-
return (0, createResult_1.createResult)(await node_bindings_1.default.execute_pending(this.pending_result));
|
|
61
|
+
return (0, createResult_1.createResult)(await node_bindings_1.default.execute_pending(this.pending_result), this.preparedStatementType);
|
|
45
62
|
}
|
|
46
63
|
async read() {
|
|
47
64
|
return new DuckDBResultReader_1.DuckDBResultReader(await this.getResult());
|
|
@@ -6,7 +6,7 @@ import { DuckDBResultReader } from './DuckDBResultReader';
|
|
|
6
6
|
import { DuckDBArrayType, DuckDBEnumType, DuckDBListType, DuckDBMapType, DuckDBStructType, DuckDBType, DuckDBUnionType } from './DuckDBType';
|
|
7
7
|
import { DuckDBTypeId } from './DuckDBTypeId';
|
|
8
8
|
import { StatementType } from './enums';
|
|
9
|
-
import { DuckDBArrayValue, DuckDBBitValue, DuckDBDateValue, DuckDBDecimalValue, DuckDBIntervalValue, DuckDBListValue, DuckDBMapValue, DuckDBStructValue, DuckDBTimestampMillisecondsValue, DuckDBTimestampNanosecondsValue, DuckDBTimestampSecondsValue, DuckDBTimestampTZValue, DuckDBTimestampValue, DuckDBTimeTZValue, DuckDBTimeValue, DuckDBUnionValue, DuckDBUUIDValue, DuckDBValue } from './values';
|
|
9
|
+
import { DuckDBArrayValue, DuckDBBitValue, DuckDBDateValue, DuckDBDecimalValue, DuckDBIntervalValue, DuckDBListValue, DuckDBMapValue, DuckDBStructValue, DuckDBTimestampMillisecondsValue, DuckDBTimestampNanosecondsValue, DuckDBTimestampSecondsValue, DuckDBTimestampTZValue, DuckDBTimestampTZNanosecondsValue, DuckDBTimestampValue, DuckDBTimeTZValue, DuckDBTimeValue, DuckDBTupleValue, DuckDBUnionValue, DuckDBUUIDValue, DuckDBValue, DuckDBVariantValue } from './values';
|
|
10
10
|
export declare class DuckDBPreparedStatement {
|
|
11
11
|
private readonly prepared_statement;
|
|
12
12
|
constructor(prepared_statement: duckdb.PreparedStatement);
|
|
@@ -42,6 +42,7 @@ export declare class DuckDBPreparedStatement {
|
|
|
42
42
|
bindTimeTZ(parameterIndex: number, value: DuckDBTimeTZValue): void;
|
|
43
43
|
bindTimestamp(parameterIndex: number, value: DuckDBTimestampValue): void;
|
|
44
44
|
bindTimestampTZ(parameterIndex: number, value: DuckDBTimestampTZValue): void;
|
|
45
|
+
bindTimestampTZNanoseconds(parameterIndex: number, value: DuckDBTimestampTZNanosecondsValue): void;
|
|
45
46
|
bindTimestampSeconds(parameterIndex: number, value: DuckDBTimestampSecondsValue): void;
|
|
46
47
|
bindTimestampMilliseconds(parameterIndex: number, value: DuckDBTimestampMillisecondsValue): void;
|
|
47
48
|
bindTimestampNanoseconds(parameterIndex: number, value: DuckDBTimestampNanosecondsValue): void;
|
|
@@ -52,10 +53,12 @@ export declare class DuckDBPreparedStatement {
|
|
|
52
53
|
bindArray(parameterIndex: number, value: DuckDBArrayValue | readonly DuckDBValue[], type?: DuckDBArrayType): void;
|
|
53
54
|
bindList(parameterIndex: number, value: DuckDBListValue | readonly DuckDBValue[], type?: DuckDBListType): void;
|
|
54
55
|
bindStruct(parameterIndex: number, value: DuckDBStructValue | Readonly<Record<string, DuckDBValue>>, type?: DuckDBStructType): void;
|
|
56
|
+
bindTuple(parameterIndex: number, value: DuckDBTupleValue | readonly DuckDBValue[], type?: DuckDBStructType): void;
|
|
55
57
|
bindMap(parameterIndex: number, value: DuckDBMapValue, type?: DuckDBMapType): void;
|
|
56
58
|
bindUnion(parameterIndex: number, value: DuckDBUnionValue, type?: DuckDBUnionType): void;
|
|
57
59
|
bindUUID(parameterIndex: number, value: DuckDBUUIDValue): void;
|
|
58
60
|
bindBit(parameterIndex: number, value: DuckDBBitValue): void;
|
|
61
|
+
bindVariant(parameterIndex: number, value: DuckDBVariantValue | null): void;
|
|
59
62
|
bindNull(parameterIndex: number): void;
|
|
60
63
|
bindValue(parameterIndex: number, value: DuckDBValue, type?: DuckDBType): void;
|
|
61
64
|
bind(values: DuckDBValue[] | Record<string, DuckDBValue>, types?: DuckDBType[] | Record<string, DuckDBType | undefined>): void;
|
|
@@ -115,6 +115,9 @@ class DuckDBPreparedStatement {
|
|
|
115
115
|
bindTimestampTZ(parameterIndex, value) {
|
|
116
116
|
this.bindValue(parameterIndex, value, DuckDBType_1.TIMESTAMPTZ);
|
|
117
117
|
}
|
|
118
|
+
bindTimestampTZNanoseconds(parameterIndex, value) {
|
|
119
|
+
this.bindValue(parameterIndex, value, DuckDBType_1.TIMESTAMPTZ_NS);
|
|
120
|
+
}
|
|
118
121
|
bindTimestampSeconds(parameterIndex, value) {
|
|
119
122
|
this.bindValue(parameterIndex, value, DuckDBType_1.TIMESTAMP_S);
|
|
120
123
|
}
|
|
@@ -145,6 +148,9 @@ class DuckDBPreparedStatement {
|
|
|
145
148
|
bindStruct(parameterIndex, value, type) {
|
|
146
149
|
this.bindValue(parameterIndex, value instanceof values_1.DuckDBStructValue ? value : (0, values_1.structValue)(value), type);
|
|
147
150
|
}
|
|
151
|
+
bindTuple(parameterIndex, value, type) {
|
|
152
|
+
this.bindValue(parameterIndex, value instanceof values_1.DuckDBTupleValue ? value : (0, values_1.tupleValue)(value), type);
|
|
153
|
+
}
|
|
148
154
|
bindMap(parameterIndex, value, type) {
|
|
149
155
|
this.bindValue(parameterIndex, value, type);
|
|
150
156
|
}
|
|
@@ -157,6 +163,13 @@ class DuckDBPreparedStatement {
|
|
|
157
163
|
bindBit(parameterIndex, value) {
|
|
158
164
|
this.bindValue(parameterIndex, value, DuckDBType_1.BIT);
|
|
159
165
|
}
|
|
166
|
+
bindVariant(parameterIndex, value) {
|
|
167
|
+
if (value === null) {
|
|
168
|
+
this.bindNull(parameterIndex);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
this.bindValue(parameterIndex, value, DuckDBType_1.VARIANT);
|
|
172
|
+
}
|
|
160
173
|
bindNull(parameterIndex) {
|
|
161
174
|
node_bindings_1.default.bind_null(this.prepared_statement, parameterIndex);
|
|
162
175
|
}
|
|
@@ -178,7 +191,7 @@ class DuckDBPreparedStatement {
|
|
|
178
191
|
}
|
|
179
192
|
}
|
|
180
193
|
async run() {
|
|
181
|
-
return new DuckDBMaterializedResult_1.DuckDBMaterializedResult(await node_bindings_1.default.execute_prepared(this.prepared_statement));
|
|
194
|
+
return new DuckDBMaterializedResult_1.DuckDBMaterializedResult(await node_bindings_1.default.execute_prepared(this.prepared_statement), this.statementType);
|
|
182
195
|
}
|
|
183
196
|
async runAndRead() {
|
|
184
197
|
return new DuckDBResultReader_1.DuckDBResultReader(await this.run());
|
|
@@ -194,7 +207,7 @@ class DuckDBPreparedStatement {
|
|
|
194
207
|
return reader;
|
|
195
208
|
}
|
|
196
209
|
async stream() {
|
|
197
|
-
return new DuckDBResult_1.DuckDBResult(await node_bindings_1.default.execute_prepared_streaming(this.prepared_statement));
|
|
210
|
+
return new DuckDBResult_1.DuckDBResult(await node_bindings_1.default.execute_prepared_streaming(this.prepared_statement), this.statementType);
|
|
198
211
|
}
|
|
199
212
|
async streamAndRead() {
|
|
200
213
|
return new DuckDBResultReader_1.DuckDBResultReader(await this.stream());
|
|
@@ -210,10 +223,10 @@ class DuckDBPreparedStatement {
|
|
|
210
223
|
return reader;
|
|
211
224
|
}
|
|
212
225
|
start() {
|
|
213
|
-
return new DuckDBPendingResult_1.DuckDBPendingResult(node_bindings_1.default.pending_prepared(this.prepared_statement));
|
|
226
|
+
return new DuckDBPendingResult_1.DuckDBPendingResult(node_bindings_1.default.pending_prepared(this.prepared_statement), this.statementType);
|
|
214
227
|
}
|
|
215
228
|
startStream() {
|
|
216
|
-
return new DuckDBPendingResult_1.DuckDBPendingResult(node_bindings_1.default.pending_prepared_streaming(this.prepared_statement));
|
|
229
|
+
return new DuckDBPendingResult_1.DuckDBPendingResult(node_bindings_1.default.pending_prepared_streaming(this.prepared_statement), this.statementType);
|
|
217
230
|
}
|
|
218
231
|
}
|
|
219
232
|
exports.DuckDBPreparedStatement = DuckDBPreparedStatement;
|
package/lib/DuckDBResult.d.ts
CHANGED
|
@@ -10,7 +10,25 @@ import { ResultReturnType, StatementType } from './enums';
|
|
|
10
10
|
import { DuckDBValue } from './values';
|
|
11
11
|
export declare class DuckDBResult {
|
|
12
12
|
protected readonly result: duckdb.Result;
|
|
13
|
-
|
|
13
|
+
private readonly preparedStatementType;
|
|
14
|
+
private closedMetadata;
|
|
15
|
+
/**
|
|
16
|
+
* `preparedStatementType` is the type of the prepared statement the result
|
|
17
|
+
* came from, if any. It is reported as the result's statement type when
|
|
18
|
+
* DuckDB reports EXECUTE instead.
|
|
19
|
+
*/
|
|
20
|
+
constructor(result: duckdb.Result, preparedStatementType?: StatementType);
|
|
21
|
+
/**
|
|
22
|
+
* Destroys the result, freeing its memory. On DuckDB 2.0, a streaming result
|
|
23
|
+
* that has not been read to the end blocks its connection from starting
|
|
24
|
+
* another statement until it is closed.
|
|
25
|
+
*
|
|
26
|
+
* The return type, statement type, column names and types, and rows changed
|
|
27
|
+
* stay available; fetching throws. If a fetch is in flight, the result is
|
|
28
|
+
* destroyed, and its connection unblocked, only once that fetch finishes.
|
|
29
|
+
* Closing again does nothing.
|
|
30
|
+
*/
|
|
31
|
+
closeSync(): void;
|
|
14
32
|
get returnType(): ResultReturnType;
|
|
15
33
|
get statementType(): StatementType;
|
|
16
34
|
get columnCount(): number;
|
|
@@ -54,4 +72,6 @@ export declare class DuckDBResult {
|
|
|
54
72
|
yieldRowsJson(): AsyncIterableIterator<Json[][]>;
|
|
55
73
|
yieldRowObjectJs(): AsyncIterableIterator<Record<string, JS>[]>;
|
|
56
74
|
yieldRowObjectJson(): AsyncIterableIterator<Record<string, Json>[]>;
|
|
75
|
+
/** Converts the index as the bindings do (ToUint32), then checks range. */
|
|
76
|
+
private checkClosedColumnIndex;
|
|
57
77
|
}
|