@avidian/duckdb-bun 0.0.0-stage → 1.0.1
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 +286 -2
- package/package.json +96 -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 +213 -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 +153 -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,403 @@
|
|
|
1
|
+
import duckdb from "../../../src/bindings/index.ts";
|
|
2
|
+
import { DuckDBDataChunk } from './DuckDBDataChunk';
|
|
3
|
+
import { DuckDBLogicalType } from './DuckDBLogicalType';
|
|
4
|
+
import { DuckDBType } from './DuckDBType';
|
|
5
|
+
import { DuckDBTypeId } from './DuckDBTypeId';
|
|
6
|
+
import { DuckDBValueConverter } from './DuckDBValueConverter';
|
|
7
|
+
import { JS } from './JS';
|
|
8
|
+
import { JSDuckDBValueConverter } from './JSDuckDBValueConverter';
|
|
9
|
+
import { Json } from './Json';
|
|
10
|
+
import { JsonDuckDBValueConverter } from './JsonDuckDBValueConverter';
|
|
11
|
+
import { convertColumnsFromChunks } from './convertColumnsFromChunks';
|
|
12
|
+
import { convertColumnsObjectFromChunks } from './convertColumnsObjectFromChunks';
|
|
13
|
+
import { convertRowObjectsFromChunks } from './convertRowObjectsFromChunks';
|
|
14
|
+
import { convertRowsFromChunks } from './convertRowsFromChunks';
|
|
15
|
+
import { ResultReturnType, StatementType } from './enums';
|
|
16
|
+
import { getColumnsFromChunks } from './getColumnsFromChunks';
|
|
17
|
+
import { getColumnsObjectFromChunks } from './getColumnsObjectFromChunks';
|
|
18
|
+
import { getRowObjectsFromChunks } from './getRowObjectsFromChunks';
|
|
19
|
+
import { getRowsFromChunks } from './getRowsFromChunks';
|
|
20
|
+
import { DuckDBValue } from './values';
|
|
21
|
+
|
|
22
|
+
interface ClosedResultMetadata {
|
|
23
|
+
returnType: ResultReturnType;
|
|
24
|
+
statementType: StatementType;
|
|
25
|
+
columnNames: string[];
|
|
26
|
+
columnTypes: DuckDBType[];
|
|
27
|
+
isStreaming: boolean;
|
|
28
|
+
rowsChanged: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class DuckDBResult {
|
|
32
|
+
protected readonly result: duckdb.Result;
|
|
33
|
+
private readonly preparedStatementType: StatementType | undefined;
|
|
34
|
+
private closedMetadata: ClosedResultMetadata | undefined;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* `preparedStatementType` is the type of the prepared statement the result
|
|
38
|
+
* came from, if any. It is reported as the result's statement type when
|
|
39
|
+
* DuckDB reports EXECUTE instead.
|
|
40
|
+
*/
|
|
41
|
+
constructor(result: duckdb.Result, preparedStatementType?: StatementType) {
|
|
42
|
+
this.result = result;
|
|
43
|
+
this.preparedStatementType = preparedStatementType;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Destroys the result, freeing its memory. On DuckDB 2.0, a streaming result
|
|
48
|
+
* that has not been read to the end blocks its connection from starting
|
|
49
|
+
* another statement until it is closed.
|
|
50
|
+
*
|
|
51
|
+
* The return type, statement type, column names and types, and rows changed
|
|
52
|
+
* stay available; fetching throws. If a fetch is in flight, the result is
|
|
53
|
+
* destroyed, and its connection unblocked, only once that fetch finishes.
|
|
54
|
+
* Closing again does nothing.
|
|
55
|
+
*/
|
|
56
|
+
public closeSync() {
|
|
57
|
+
if (!this.closedMetadata) {
|
|
58
|
+
const columnCount = this.columnCount;
|
|
59
|
+
const columnNames: string[] = [];
|
|
60
|
+
const columnTypes: DuckDBType[] = [];
|
|
61
|
+
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
62
|
+
columnNames.push(this.columnName(columnIndex));
|
|
63
|
+
columnTypes.push(this.columnType(columnIndex));
|
|
64
|
+
}
|
|
65
|
+
this.closedMetadata = {
|
|
66
|
+
returnType: this.returnType,
|
|
67
|
+
statementType: this.statementType,
|
|
68
|
+
columnNames,
|
|
69
|
+
columnTypes,
|
|
70
|
+
isStreaming: this.isStreaming,
|
|
71
|
+
rowsChanged: this.rowsChanged,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
duckdb.destroy_result_sync(this.result);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public get returnType(): ResultReturnType {
|
|
78
|
+
if (this.closedMetadata) {
|
|
79
|
+
return this.closedMetadata.returnType;
|
|
80
|
+
}
|
|
81
|
+
return duckdb.result_return_type(this.result);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public get statementType(): StatementType {
|
|
85
|
+
if (this.closedMetadata) {
|
|
86
|
+
return this.closedMetadata.statementType;
|
|
87
|
+
}
|
|
88
|
+
const statementType = duckdb.result_statement_type(this.result);
|
|
89
|
+
// On DuckDB 2.0, results of prepared statements report EXECUTE; see
|
|
90
|
+
// https://github.com/duckdb/duckdb/issues/27415
|
|
91
|
+
if (
|
|
92
|
+
statementType === StatementType.EXECUTE &&
|
|
93
|
+
this.preparedStatementType !== undefined
|
|
94
|
+
) {
|
|
95
|
+
return this.preparedStatementType;
|
|
96
|
+
}
|
|
97
|
+
return statementType;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public get columnCount(): number {
|
|
101
|
+
if (this.closedMetadata) {
|
|
102
|
+
return this.closedMetadata.columnNames.length;
|
|
103
|
+
}
|
|
104
|
+
return duckdb.column_count(this.result);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public columnName(columnIndex: number): string {
|
|
108
|
+
if (this.closedMetadata) {
|
|
109
|
+
return this.closedMetadata.columnNames[
|
|
110
|
+
this.checkClosedColumnIndex(columnIndex)
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
return duckdb.column_name(this.result, columnIndex);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public columnNames(): string[] {
|
|
117
|
+
const columnNames: string[] = [];
|
|
118
|
+
const columnCount = this.columnCount;
|
|
119
|
+
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
120
|
+
columnNames.push(this.columnName(columnIndex));
|
|
121
|
+
}
|
|
122
|
+
return columnNames;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public deduplicatedColumnNames(): string[] {
|
|
126
|
+
const outputColumnNames: string[] = [];
|
|
127
|
+
const columnCount = this.columnCount;
|
|
128
|
+
const columnNameCount: { [columnName: string]: number } = {};
|
|
129
|
+
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
130
|
+
const inputColumnName = this.columnName(columnIndex);
|
|
131
|
+
const nameCount = (columnNameCount[inputColumnName] || 0) + 1;
|
|
132
|
+
columnNameCount[inputColumnName] = nameCount;
|
|
133
|
+
if (nameCount > 1) {
|
|
134
|
+
outputColumnNames.push(`${inputColumnName}:${nameCount - 1}`);
|
|
135
|
+
} else {
|
|
136
|
+
outputColumnNames.push(inputColumnName);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return outputColumnNames;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
public columnTypeId(columnIndex: number): DuckDBTypeId {
|
|
143
|
+
if (this.closedMetadata) {
|
|
144
|
+
return this.columnType(columnIndex).typeId;
|
|
145
|
+
}
|
|
146
|
+
return duckdb.column_type(
|
|
147
|
+
this.result,
|
|
148
|
+
columnIndex
|
|
149
|
+
) as number as DuckDBTypeId;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public columnLogicalType(columnIndex: number): DuckDBLogicalType {
|
|
153
|
+
if (this.closedMetadata) {
|
|
154
|
+
return this.columnType(columnIndex).toLogicalType();
|
|
155
|
+
}
|
|
156
|
+
return DuckDBLogicalType.create(
|
|
157
|
+
duckdb.column_logical_type(this.result, columnIndex)
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public columnType(columnIndex: number): DuckDBType {
|
|
162
|
+
if (this.closedMetadata) {
|
|
163
|
+
return this.closedMetadata.columnTypes[
|
|
164
|
+
this.checkClosedColumnIndex(columnIndex)
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
return this.columnLogicalType(columnIndex).asType();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public columnTypeJson(columnIndex: number): Json {
|
|
171
|
+
return this.columnType(columnIndex).toJson();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public columnTypes(): DuckDBType[] {
|
|
175
|
+
const columnTypes: DuckDBType[] = [];
|
|
176
|
+
const columnCount = this.columnCount;
|
|
177
|
+
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
178
|
+
columnTypes.push(this.columnType(columnIndex));
|
|
179
|
+
}
|
|
180
|
+
return columnTypes;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
public columnTypesJson(): Json {
|
|
184
|
+
const columnTypesJson: Json[] = [];
|
|
185
|
+
const columnCount = this.columnCount;
|
|
186
|
+
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
187
|
+
columnTypesJson.push(this.columnTypeJson(columnIndex));
|
|
188
|
+
}
|
|
189
|
+
return columnTypesJson;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
public columnNamesAndTypesJson(): Json {
|
|
193
|
+
return {
|
|
194
|
+
columnNames: this.columnNames(),
|
|
195
|
+
columnTypes: this.columnTypesJson(),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
public columnNameAndTypeObjectsJson(): Json {
|
|
200
|
+
const columnNameAndTypeObjects: Json[] = [];
|
|
201
|
+
const columnCount = this.columnCount;
|
|
202
|
+
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
203
|
+
columnNameAndTypeObjects.push({
|
|
204
|
+
columnName: this.columnName(columnIndex),
|
|
205
|
+
columnType: this.columnTypeJson(columnIndex),
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return columnNameAndTypeObjects;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
public get isStreaming(): boolean {
|
|
212
|
+
if (this.closedMetadata) {
|
|
213
|
+
return this.closedMetadata.isStreaming;
|
|
214
|
+
}
|
|
215
|
+
return duckdb.result_is_streaming(this.result);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
public get rowsChanged(): number {
|
|
219
|
+
if (this.closedMetadata) {
|
|
220
|
+
return this.closedMetadata.rowsChanged;
|
|
221
|
+
}
|
|
222
|
+
return duckdb.rows_changed(this.result);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
public async fetchChunk(): Promise<DuckDBDataChunk | null> {
|
|
226
|
+
const chunk = await duckdb.fetch_chunk(this.result);
|
|
227
|
+
return chunk ? new DuckDBDataChunk(chunk) : null;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
public async fetchAllChunks(): Promise<DuckDBDataChunk[]> {
|
|
231
|
+
const chunks: DuckDBDataChunk[] = [];
|
|
232
|
+
while (true) {
|
|
233
|
+
const chunk = await this.fetchChunk();
|
|
234
|
+
if (!chunk || chunk.rowCount === 0) {
|
|
235
|
+
return chunks;
|
|
236
|
+
}
|
|
237
|
+
chunks.push(chunk);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
public async getColumns(): Promise<DuckDBValue[][]> {
|
|
242
|
+
const chunks = await this.fetchAllChunks();
|
|
243
|
+
return getColumnsFromChunks(chunks, this.columnCount);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
public async convertColumns<T>(
|
|
247
|
+
converter: DuckDBValueConverter<T>
|
|
248
|
+
): Promise<(T | null)[][]> {
|
|
249
|
+
const chunks = await this.fetchAllChunks();
|
|
250
|
+
return convertColumnsFromChunks(chunks, this.columnCount, converter);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
public async getColumnsJS(): Promise<JS[][]> {
|
|
254
|
+
return this.convertColumns(JSDuckDBValueConverter);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
public async getColumnsJson(): Promise<Json[][]> {
|
|
258
|
+
return this.convertColumns(JsonDuckDBValueConverter);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
public async getColumnsObject(): Promise<Record<string, DuckDBValue[]>> {
|
|
262
|
+
const chunks = await this.fetchAllChunks();
|
|
263
|
+
return getColumnsObjectFromChunks(chunks, this.deduplicatedColumnNames());
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
public async convertColumnsObject<T>(
|
|
267
|
+
converter: DuckDBValueConverter<T>
|
|
268
|
+
): Promise<Record<string, (T | null)[]>> {
|
|
269
|
+
const chunks = await this.fetchAllChunks();
|
|
270
|
+
return convertColumnsObjectFromChunks(
|
|
271
|
+
chunks,
|
|
272
|
+
this.deduplicatedColumnNames(),
|
|
273
|
+
converter
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
public async getColumnsObjectJS(): Promise<Record<string, JS[]>> {
|
|
278
|
+
return this.convertColumnsObject(JSDuckDBValueConverter);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
public async getColumnsObjectJson(): Promise<Record<string, Json[]>> {
|
|
282
|
+
return this.convertColumnsObject(JsonDuckDBValueConverter);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
public async getRows(): Promise<DuckDBValue[][]> {
|
|
286
|
+
const chunks = await this.fetchAllChunks();
|
|
287
|
+
return getRowsFromChunks(chunks);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
public async convertRows<T>(
|
|
291
|
+
converter: DuckDBValueConverter<T>
|
|
292
|
+
): Promise<(T | null)[][]> {
|
|
293
|
+
const chunks = await this.fetchAllChunks();
|
|
294
|
+
return convertRowsFromChunks(chunks, converter);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
public async getRowsJS(): Promise<JS[][]> {
|
|
298
|
+
return this.convertRows(JSDuckDBValueConverter);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
public async getRowsJson(): Promise<Json[][]> {
|
|
302
|
+
return this.convertRows(JsonDuckDBValueConverter);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
public async getRowObjects(): Promise<Record<string, DuckDBValue>[]> {
|
|
306
|
+
const chunks = await this.fetchAllChunks();
|
|
307
|
+
return getRowObjectsFromChunks(chunks, this.deduplicatedColumnNames());
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
public async convertRowObjects<T>(
|
|
311
|
+
converter: DuckDBValueConverter<T>
|
|
312
|
+
): Promise<Record<string, T | null>[]> {
|
|
313
|
+
const chunks = await this.fetchAllChunks();
|
|
314
|
+
return convertRowObjectsFromChunks(
|
|
315
|
+
chunks,
|
|
316
|
+
this.deduplicatedColumnNames(),
|
|
317
|
+
converter
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
public async getRowObjectsJS(): Promise<Record<string, JS>[]> {
|
|
322
|
+
return this.convertRowObjects(JSDuckDBValueConverter);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
public async getRowObjectsJson(): Promise<Record<string, Json>[]> {
|
|
326
|
+
return this.convertRowObjects(JsonDuckDBValueConverter);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
public async *[Symbol.asyncIterator](): AsyncIterableIterator<DuckDBDataChunk> {
|
|
330
|
+
while (true) {
|
|
331
|
+
const chunk = await this.fetchChunk();
|
|
332
|
+
if (chunk && chunk.rowCount > 0) {
|
|
333
|
+
yield chunk;
|
|
334
|
+
} else {
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
public async *yieldRows(): AsyncIterableIterator<DuckDBValue[][]> {
|
|
341
|
+
for await (const chunk of this) {
|
|
342
|
+
yield getRowsFromChunks([chunk]);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
public async *yieldRowObjects(): AsyncIterableIterator<
|
|
347
|
+
Record<string, DuckDBValue>[]
|
|
348
|
+
> {
|
|
349
|
+
const deduplicatedColumnNames = this.deduplicatedColumnNames();
|
|
350
|
+
for await (const chunk of this) {
|
|
351
|
+
yield getRowObjectsFromChunks([chunk], deduplicatedColumnNames);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
public async *yieldConvertedRows<T>(
|
|
356
|
+
converter: DuckDBValueConverter<T>
|
|
357
|
+
): AsyncIterableIterator<(T | null)[][]> {
|
|
358
|
+
for await (const chunk of this) {
|
|
359
|
+
yield convertRowsFromChunks([chunk], converter);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
public async *yieldConvertedRowObjects<T>(
|
|
364
|
+
converter: DuckDBValueConverter<T>
|
|
365
|
+
): AsyncIterableIterator<Record<string, T | null>[]> {
|
|
366
|
+
const deduplicatedColumnNames = this.deduplicatedColumnNames();
|
|
367
|
+
for await (const chunk of this) {
|
|
368
|
+
yield convertRowObjectsFromChunks(
|
|
369
|
+
[chunk],
|
|
370
|
+
deduplicatedColumnNames,
|
|
371
|
+
converter
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
public yieldRowsJs(): AsyncIterableIterator<JS[][]> {
|
|
377
|
+
return this.yieldConvertedRows(JSDuckDBValueConverter);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
public yieldRowsJson(): AsyncIterableIterator<Json[][]> {
|
|
381
|
+
return this.yieldConvertedRows(JsonDuckDBValueConverter);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
public yieldRowObjectJs(): AsyncIterableIterator<Record<string, JS>[]> {
|
|
385
|
+
return this.yieldConvertedRowObjects(JSDuckDBValueConverter);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
public yieldRowObjectJson(): AsyncIterableIterator<Record<string, Json>[]> {
|
|
389
|
+
return this.yieldConvertedRowObjects(JsonDuckDBValueConverter);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** Converts the index as the bindings do (ToUint32), then checks range. */
|
|
393
|
+
private checkClosedColumnIndex(columnIndex: number): number {
|
|
394
|
+
const index = columnIndex >>> 0;
|
|
395
|
+
const columnCount = this.closedMetadata?.columnNames.length ?? 0;
|
|
396
|
+
if (index >= columnCount) {
|
|
397
|
+
throw new RangeError(
|
|
398
|
+
`column index ${index} is out of range (count: ${columnCount})`
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
return index;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { convertColumnsFromChunks } from './convertColumnsFromChunks';
|
|
2
|
+
import { convertColumnsObjectFromChunks } from './convertColumnsObjectFromChunks';
|
|
3
|
+
import { convertRowObjectsFromChunks } from './convertRowObjectsFromChunks';
|
|
4
|
+
import { convertRowsFromChunks } from './convertRowsFromChunks';
|
|
5
|
+
import { DuckDBDataChunk } from './DuckDBDataChunk';
|
|
6
|
+
import { DuckDBLogicalType } from './DuckDBLogicalType';
|
|
7
|
+
import { DuckDBResult } from './DuckDBResult';
|
|
8
|
+
import { DuckDBType } from './DuckDBType';
|
|
9
|
+
import { DuckDBTypeId } from './DuckDBTypeId';
|
|
10
|
+
import { DuckDBValueConverter } from './DuckDBValueConverter';
|
|
11
|
+
import { ResultReturnType, StatementType } from './enums';
|
|
12
|
+
import { getColumnsFromChunks } from './getColumnsFromChunks';
|
|
13
|
+
import { getColumnsObjectFromChunks } from './getColumnsObjectFromChunks';
|
|
14
|
+
import { getRowObjectsFromChunks } from './getRowObjectsFromChunks';
|
|
15
|
+
import { getRowsFromChunks } from './getRowsFromChunks';
|
|
16
|
+
import { JS } from './JS';
|
|
17
|
+
import { JSDuckDBValueConverter } from './JSDuckDBValueConverter';
|
|
18
|
+
import { Json } from './Json';
|
|
19
|
+
import { JsonDuckDBValueConverter } from './JsonDuckDBValueConverter';
|
|
20
|
+
import { DuckDBValue } from './values';
|
|
21
|
+
|
|
22
|
+
interface ChunkSizeRun {
|
|
23
|
+
chunkCount: number;
|
|
24
|
+
chunkSize: number;
|
|
25
|
+
rowCount: number; // Equal to chunkCount * chunkSize; precalculated for efficiency.
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class DuckDBResultReader {
|
|
29
|
+
private readonly result: DuckDBResult;
|
|
30
|
+
private readonly chunks: DuckDBDataChunk[];
|
|
31
|
+
private readonly chunkSizeRuns: ChunkSizeRun[];
|
|
32
|
+
private currentRowCount_: number;
|
|
33
|
+
private done_: boolean;
|
|
34
|
+
|
|
35
|
+
constructor(result: DuckDBResult) {
|
|
36
|
+
this.result = result;
|
|
37
|
+
this.chunks = [];
|
|
38
|
+
this.chunkSizeRuns = [];
|
|
39
|
+
this.currentRowCount_ = 0;
|
|
40
|
+
this.done_ = false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Closes the result being read; see `DuckDBResult.closeSync`. Rows already
|
|
45
|
+
* read and the column metadata stay available; reading more throws.
|
|
46
|
+
*/
|
|
47
|
+
public closeSync() {
|
|
48
|
+
this.result.closeSync();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public get returnType(): ResultReturnType {
|
|
52
|
+
return this.result.returnType;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public get statementType(): StatementType {
|
|
56
|
+
return this.result.statementType;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public get columnCount(): number {
|
|
60
|
+
return this.result.columnCount;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public columnName(columnIndex: number): string {
|
|
64
|
+
return this.result.columnName(columnIndex);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public columnNames(): string[] {
|
|
68
|
+
return this.result.columnNames();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public deduplicatedColumnNames(): string[] {
|
|
72
|
+
return this.result.deduplicatedColumnNames();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public columnTypeId(columnIndex: number): DuckDBTypeId {
|
|
76
|
+
return this.result.columnTypeId(columnIndex);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public columnLogicalType(columnIndex: number): DuckDBLogicalType {
|
|
80
|
+
return this.result.columnLogicalType(columnIndex);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public columnType(columnIndex: number): DuckDBType {
|
|
84
|
+
return this.result.columnType(columnIndex);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public columnTypeJson(columnIndex: number): Json {
|
|
88
|
+
return this.result.columnTypeJson(columnIndex);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public columnTypes(): DuckDBType[] {
|
|
92
|
+
return this.result.columnTypes();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public columnTypesJson(): Json {
|
|
96
|
+
return this.result.columnTypesJson();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public columnNamesAndTypesJson(): Json {
|
|
100
|
+
return this.result.columnNamesAndTypesJson();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public columnNameAndTypeObjectsJson(): Json {
|
|
104
|
+
return this.result.columnNameAndTypeObjectsJson();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public get rowsChanged(): number {
|
|
108
|
+
return this.result.rowsChanged;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Total number of rows read so far. Call `readAll` or `readUntil` to read rows. */
|
|
112
|
+
public get currentRowCount() {
|
|
113
|
+
return this.currentRowCount_;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Whether reading is done, that is, there are no more rows to read. */
|
|
117
|
+
public get done() {
|
|
118
|
+
return this.done_;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Returns the value for the given column and row. Both are zero-indexed.
|
|
123
|
+
*
|
|
124
|
+
* Will return an error if `rowIndex` is greater than `currentRowCount`.
|
|
125
|
+
*/
|
|
126
|
+
public value(columnIndex: number, rowIndex: number): DuckDBValue {
|
|
127
|
+
if (this.currentRowCount_ === 0) {
|
|
128
|
+
throw Error(`No rows have been read`);
|
|
129
|
+
}
|
|
130
|
+
let chunkIndex = 0;
|
|
131
|
+
let currentRowIndex = rowIndex;
|
|
132
|
+
// Find which run of chunks our row is in.
|
|
133
|
+
// Since chunkSizeRuns shouldn't ever be longer than 2, this should be O(1).
|
|
134
|
+
for (const run of this.chunkSizeRuns) {
|
|
135
|
+
if (currentRowIndex < run.rowCount) {
|
|
136
|
+
// The row we're looking for is in this run.
|
|
137
|
+
// Calculate the chunk index and the row index in that chunk.
|
|
138
|
+
chunkIndex += Math.floor(currentRowIndex / run.chunkSize);
|
|
139
|
+
const rowIndexInChunk = currentRowIndex % run.chunkSize;
|
|
140
|
+
const chunk = this.chunks[chunkIndex];
|
|
141
|
+
return chunk.getColumnVector(columnIndex).getItem(rowIndexInChunk);
|
|
142
|
+
}
|
|
143
|
+
// The row we're looking for is not in this run.
|
|
144
|
+
// Update our counts for this run and move to the next one.
|
|
145
|
+
chunkIndex += run.chunkCount;
|
|
146
|
+
currentRowIndex -= run.rowCount;
|
|
147
|
+
}
|
|
148
|
+
// We didn't find our row. It must have been out of range.
|
|
149
|
+
throw Error(
|
|
150
|
+
`Row index ${rowIndex} requested, but only ${this.currentRowCount_} row have been read so far.`
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Read all rows. */
|
|
155
|
+
public async readAll(): Promise<void> {
|
|
156
|
+
return this.fetchChunks();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Read rows until at least the given target row count has been met.
|
|
161
|
+
*
|
|
162
|
+
* Note that the resulting row count could be greater than the target, since rows are read in chunks, typically of 2048 rows each.
|
|
163
|
+
*/
|
|
164
|
+
public async readUntil(targetRowCount: number): Promise<void> {
|
|
165
|
+
return this.fetchChunks(targetRowCount);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private async fetchChunks(targetRowCount?: number): Promise<void> {
|
|
169
|
+
while (
|
|
170
|
+
!(
|
|
171
|
+
this.done_ ||
|
|
172
|
+
(targetRowCount !== undefined &&
|
|
173
|
+
this.currentRowCount_ >= targetRowCount)
|
|
174
|
+
)
|
|
175
|
+
) {
|
|
176
|
+
const chunk = await this.result.fetchChunk();
|
|
177
|
+
if (chunk && chunk.rowCount > 0) {
|
|
178
|
+
this.updateChunkSizeRuns(chunk);
|
|
179
|
+
this.chunks.push(chunk);
|
|
180
|
+
this.currentRowCount_ += chunk.rowCount;
|
|
181
|
+
} else {
|
|
182
|
+
this.done_ = true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private updateChunkSizeRuns(chunk: DuckDBDataChunk) {
|
|
188
|
+
if (this.chunkSizeRuns.length > 0) {
|
|
189
|
+
const lastRun = this.chunkSizeRuns[this.chunkSizeRuns.length - 1];
|
|
190
|
+
if (lastRun.chunkSize === chunk.rowCount) {
|
|
191
|
+
// If the new batch is the same size as the last one, just update our last run.
|
|
192
|
+
lastRun.chunkCount += 1;
|
|
193
|
+
lastRun.rowCount += lastRun.chunkSize;
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// If this is our first batch, or it's a different size, create a new run.
|
|
198
|
+
this.chunkSizeRuns.push({
|
|
199
|
+
chunkCount: 1,
|
|
200
|
+
chunkSize: chunk.rowCount,
|
|
201
|
+
rowCount: chunk.rowCount,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
public getColumns(): DuckDBValue[][] {
|
|
206
|
+
return getColumnsFromChunks(this.chunks, this.columnCount);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
public convertColumns<T>(converter: DuckDBValueConverter<T>): (T | null)[][] {
|
|
210
|
+
return convertColumnsFromChunks(this.chunks, this.columnCount, converter);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
public getColumnsJS(): JS[][] {
|
|
214
|
+
return this.convertColumns(JSDuckDBValueConverter);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
public getColumnsJson(): Json[][] {
|
|
218
|
+
return this.convertColumns(JsonDuckDBValueConverter);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
public getColumnsObject(): Record<string, DuckDBValue[]> {
|
|
222
|
+
return getColumnsObjectFromChunks(
|
|
223
|
+
this.chunks,
|
|
224
|
+
this.deduplicatedColumnNames()
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
public convertColumnsObject<T>(
|
|
229
|
+
converter: DuckDBValueConverter<T>
|
|
230
|
+
): Record<string, (T | null)[]> {
|
|
231
|
+
return convertColumnsObjectFromChunks(
|
|
232
|
+
this.chunks,
|
|
233
|
+
this.deduplicatedColumnNames(),
|
|
234
|
+
converter
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
public getColumnsObjectJS(): Record<string, JS[]> {
|
|
239
|
+
return this.convertColumnsObject(JSDuckDBValueConverter);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
public getColumnsObjectJson(): Record<string, Json[]> {
|
|
243
|
+
return this.convertColumnsObject(JsonDuckDBValueConverter);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
public getRows(): DuckDBValue[][] {
|
|
247
|
+
return getRowsFromChunks(this.chunks);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
public convertRows<T>(converter: DuckDBValueConverter<T>): (T | null)[][] {
|
|
251
|
+
return convertRowsFromChunks(this.chunks, converter);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
public getRowsJS(): JS[][] {
|
|
255
|
+
return this.convertRows(JSDuckDBValueConverter);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
public getRowsJson(): Json[][] {
|
|
259
|
+
return this.convertRows(JsonDuckDBValueConverter);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
public getRowObjects(): Record<string, DuckDBValue>[] {
|
|
263
|
+
return getRowObjectsFromChunks(this.chunks, this.deduplicatedColumnNames());
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
public convertRowObjects<T>(
|
|
267
|
+
converter: DuckDBValueConverter<T>
|
|
268
|
+
): Record<string, T | null>[] {
|
|
269
|
+
return convertRowObjectsFromChunks(
|
|
270
|
+
this.chunks,
|
|
271
|
+
this.deduplicatedColumnNames(),
|
|
272
|
+
converter
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
public getRowObjectsJS(): Record<string, JS>[] {
|
|
277
|
+
return this.convertRowObjects(JSDuckDBValueConverter);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
public getRowObjectsJson(): Record<string, Json>[] {
|
|
281
|
+
return this.convertRowObjects(JsonDuckDBValueConverter);
|
|
282
|
+
}
|
|
283
|
+
}
|