@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,376 @@
|
|
|
1
|
+
import duckdb from "../../../src/bindings/index.ts";
|
|
2
|
+
import { createValue } from './createValue';
|
|
3
|
+
import { DuckDBLogicalType } from './DuckDBLogicalType';
|
|
4
|
+
import { DuckDBMaterializedResult } from './DuckDBMaterializedResult';
|
|
5
|
+
import { DuckDBPendingResult } from './DuckDBPendingResult';
|
|
6
|
+
import { DuckDBResult } from './DuckDBResult';
|
|
7
|
+
import { DuckDBResultReader } from './DuckDBResultReader';
|
|
8
|
+
import {
|
|
9
|
+
BIGNUM,
|
|
10
|
+
BIT,
|
|
11
|
+
DuckDBArrayType,
|
|
12
|
+
DuckDBEnumType,
|
|
13
|
+
DuckDBListType,
|
|
14
|
+
DuckDBMapType,
|
|
15
|
+
DuckDBStructType,
|
|
16
|
+
DuckDBType,
|
|
17
|
+
DuckDBUnionType,
|
|
18
|
+
TIMESTAMP_MS,
|
|
19
|
+
TIMESTAMP_NS,
|
|
20
|
+
TIMESTAMP_S,
|
|
21
|
+
TIMESTAMPTZ,
|
|
22
|
+
TIMESTAMPTZ_NS,
|
|
23
|
+
TIMETZ,
|
|
24
|
+
UUID,
|
|
25
|
+
VARIANT,
|
|
26
|
+
} from './DuckDBType';
|
|
27
|
+
import { DuckDBTypeId } from './DuckDBTypeId';
|
|
28
|
+
import { StatementType } from './enums';
|
|
29
|
+
import { typeForValue } from './typeForValue';
|
|
30
|
+
import {
|
|
31
|
+
arrayValue,
|
|
32
|
+
DuckDBArrayValue,
|
|
33
|
+
DuckDBBitValue,
|
|
34
|
+
DuckDBDateValue,
|
|
35
|
+
DuckDBDecimalValue,
|
|
36
|
+
DuckDBIntervalValue,
|
|
37
|
+
DuckDBListValue,
|
|
38
|
+
DuckDBMapValue,
|
|
39
|
+
DuckDBStructValue,
|
|
40
|
+
DuckDBTimestampMillisecondsValue,
|
|
41
|
+
DuckDBTimestampNanosecondsValue,
|
|
42
|
+
DuckDBTimestampSecondsValue,
|
|
43
|
+
DuckDBTimestampTZValue,
|
|
44
|
+
DuckDBTimestampTZNanosecondsValue,
|
|
45
|
+
DuckDBTimestampValue,
|
|
46
|
+
DuckDBTimeTZValue,
|
|
47
|
+
DuckDBTimeValue,
|
|
48
|
+
DuckDBTupleValue,
|
|
49
|
+
DuckDBUnionValue,
|
|
50
|
+
DuckDBUUIDValue,
|
|
51
|
+
DuckDBValue,
|
|
52
|
+
DuckDBVariantValue,
|
|
53
|
+
listValue,
|
|
54
|
+
structValue,
|
|
55
|
+
tupleValue,
|
|
56
|
+
} from './values';
|
|
57
|
+
|
|
58
|
+
export class DuckDBPreparedStatement {
|
|
59
|
+
private readonly prepared_statement: duckdb.PreparedStatement;
|
|
60
|
+
constructor(prepared_statement: duckdb.PreparedStatement) {
|
|
61
|
+
this.prepared_statement = prepared_statement;
|
|
62
|
+
}
|
|
63
|
+
public destroySync() {
|
|
64
|
+
return duckdb.destroy_prepare_sync(this.prepared_statement);
|
|
65
|
+
}
|
|
66
|
+
public get statementType(): StatementType {
|
|
67
|
+
return duckdb.prepared_statement_type(this.prepared_statement);
|
|
68
|
+
}
|
|
69
|
+
public get parameterCount(): number {
|
|
70
|
+
return duckdb.nparams(this.prepared_statement);
|
|
71
|
+
}
|
|
72
|
+
public parameterName(parameterIndex: number): string {
|
|
73
|
+
return duckdb.parameter_name(this.prepared_statement, parameterIndex);
|
|
74
|
+
}
|
|
75
|
+
public parameterTypeId(parameterIndex: number): DuckDBTypeId {
|
|
76
|
+
return duckdb.param_type(
|
|
77
|
+
this.prepared_statement,
|
|
78
|
+
parameterIndex
|
|
79
|
+
) as number as DuckDBTypeId;
|
|
80
|
+
}
|
|
81
|
+
public parameterType(parameterIndex: number): DuckDBType {
|
|
82
|
+
return DuckDBLogicalType.create(
|
|
83
|
+
duckdb.param_logical_type(this.prepared_statement, parameterIndex)
|
|
84
|
+
).asType();
|
|
85
|
+
}
|
|
86
|
+
public get columnCount(): number {
|
|
87
|
+
return duckdb.prepared_statement_column_count(this.prepared_statement);
|
|
88
|
+
}
|
|
89
|
+
public columnName(columnIndex: number): string {
|
|
90
|
+
return duckdb.prepared_statement_column_name(
|
|
91
|
+
this.prepared_statement,
|
|
92
|
+
columnIndex
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
public columnTypeId(columnIndex: number): DuckDBTypeId {
|
|
96
|
+
return duckdb.prepared_statement_column_type(
|
|
97
|
+
this.prepared_statement,
|
|
98
|
+
columnIndex
|
|
99
|
+
) as number as DuckDBTypeId;
|
|
100
|
+
}
|
|
101
|
+
public columnType(columnIndex: number): DuckDBType {
|
|
102
|
+
return DuckDBLogicalType.create(
|
|
103
|
+
duckdb.prepared_statement_column_logical_type(
|
|
104
|
+
this.prepared_statement,
|
|
105
|
+
columnIndex
|
|
106
|
+
)
|
|
107
|
+
).asType();
|
|
108
|
+
}
|
|
109
|
+
public clearBindings() {
|
|
110
|
+
duckdb.clear_bindings(this.prepared_statement);
|
|
111
|
+
}
|
|
112
|
+
public parameterIndex(parameterName: string): number {
|
|
113
|
+
return duckdb.bind_parameter_index(this.prepared_statement, parameterName);
|
|
114
|
+
}
|
|
115
|
+
public bindBoolean(parameterIndex: number, value: boolean) {
|
|
116
|
+
duckdb.bind_boolean(this.prepared_statement, parameterIndex, value);
|
|
117
|
+
}
|
|
118
|
+
public bindTinyInt(parameterIndex: number, value: number) {
|
|
119
|
+
duckdb.bind_int8(this.prepared_statement, parameterIndex, value);
|
|
120
|
+
}
|
|
121
|
+
public bindSmallInt(parameterIndex: number, value: number) {
|
|
122
|
+
duckdb.bind_int16(this.prepared_statement, parameterIndex, value);
|
|
123
|
+
}
|
|
124
|
+
public bindInteger(parameterIndex: number, value: number) {
|
|
125
|
+
duckdb.bind_int32(this.prepared_statement, parameterIndex, value);
|
|
126
|
+
}
|
|
127
|
+
public bindBigInt(parameterIndex: number, value: bigint) {
|
|
128
|
+
duckdb.bind_int64(this.prepared_statement, parameterIndex, value);
|
|
129
|
+
}
|
|
130
|
+
public bindHugeInt(parameterIndex: number, value: bigint) {
|
|
131
|
+
duckdb.bind_hugeint(this.prepared_statement, parameterIndex, value);
|
|
132
|
+
}
|
|
133
|
+
public bindUTinyInt(parameterIndex: number, value: number) {
|
|
134
|
+
duckdb.bind_uint8(this.prepared_statement, parameterIndex, value);
|
|
135
|
+
}
|
|
136
|
+
public bindUSmallInt(parameterIndex: number, value: number) {
|
|
137
|
+
duckdb.bind_uint16(this.prepared_statement, parameterIndex, value);
|
|
138
|
+
}
|
|
139
|
+
public bindUInteger(parameterIndex: number, value: number) {
|
|
140
|
+
duckdb.bind_uint32(this.prepared_statement, parameterIndex, value);
|
|
141
|
+
}
|
|
142
|
+
public bindUBigInt(parameterIndex: number, value: bigint) {
|
|
143
|
+
duckdb.bind_uint64(this.prepared_statement, parameterIndex, value);
|
|
144
|
+
}
|
|
145
|
+
public bindUHugeInt(parameterIndex: number, value: bigint) {
|
|
146
|
+
duckdb.bind_uhugeint(this.prepared_statement, parameterIndex, value);
|
|
147
|
+
}
|
|
148
|
+
public bindBigNum(parameterIndex: number, value: bigint) {
|
|
149
|
+
this.bindValue(parameterIndex, value, BIGNUM);
|
|
150
|
+
}
|
|
151
|
+
public bindDecimal(parameterIndex: number, value: DuckDBDecimalValue) {
|
|
152
|
+
duckdb.bind_decimal(this.prepared_statement, parameterIndex, value);
|
|
153
|
+
}
|
|
154
|
+
public bindFloat(parameterIndex: number, value: number) {
|
|
155
|
+
duckdb.bind_float(this.prepared_statement, parameterIndex, value);
|
|
156
|
+
}
|
|
157
|
+
public bindDouble(parameterIndex: number, value: number) {
|
|
158
|
+
duckdb.bind_double(this.prepared_statement, parameterIndex, value);
|
|
159
|
+
}
|
|
160
|
+
public bindDate(parameterIndex: number, value: DuckDBDateValue) {
|
|
161
|
+
duckdb.bind_date(this.prepared_statement, parameterIndex, value);
|
|
162
|
+
}
|
|
163
|
+
public bindTime(parameterIndex: number, value: DuckDBTimeValue) {
|
|
164
|
+
duckdb.bind_time(this.prepared_statement, parameterIndex, value);
|
|
165
|
+
}
|
|
166
|
+
public bindTimeTZ(parameterIndex: number, value: DuckDBTimeTZValue) {
|
|
167
|
+
this.bindValue(parameterIndex, value, TIMETZ);
|
|
168
|
+
}
|
|
169
|
+
public bindTimestamp(parameterIndex: number, value: DuckDBTimestampValue) {
|
|
170
|
+
duckdb.bind_timestamp(this.prepared_statement, parameterIndex, value);
|
|
171
|
+
}
|
|
172
|
+
public bindTimestampTZ(
|
|
173
|
+
parameterIndex: number,
|
|
174
|
+
value: DuckDBTimestampTZValue
|
|
175
|
+
) {
|
|
176
|
+
this.bindValue(parameterIndex, value, TIMESTAMPTZ);
|
|
177
|
+
}
|
|
178
|
+
public bindTimestampTZNanoseconds(
|
|
179
|
+
parameterIndex: number,
|
|
180
|
+
value: DuckDBTimestampTZNanosecondsValue
|
|
181
|
+
) {
|
|
182
|
+
this.bindValue(parameterIndex, value, TIMESTAMPTZ_NS);
|
|
183
|
+
}
|
|
184
|
+
public bindTimestampSeconds(
|
|
185
|
+
parameterIndex: number,
|
|
186
|
+
value: DuckDBTimestampSecondsValue
|
|
187
|
+
) {
|
|
188
|
+
this.bindValue(parameterIndex, value, TIMESTAMP_S);
|
|
189
|
+
}
|
|
190
|
+
public bindTimestampMilliseconds(
|
|
191
|
+
parameterIndex: number,
|
|
192
|
+
value: DuckDBTimestampMillisecondsValue
|
|
193
|
+
) {
|
|
194
|
+
this.bindValue(parameterIndex, value, TIMESTAMP_MS);
|
|
195
|
+
}
|
|
196
|
+
public bindTimestampNanoseconds(
|
|
197
|
+
parameterIndex: number,
|
|
198
|
+
value: DuckDBTimestampNanosecondsValue
|
|
199
|
+
) {
|
|
200
|
+
this.bindValue(parameterIndex, value, TIMESTAMP_NS);
|
|
201
|
+
}
|
|
202
|
+
public bindInterval(parameterIndex: number, value: DuckDBIntervalValue) {
|
|
203
|
+
duckdb.bind_interval(this.prepared_statement, parameterIndex, value);
|
|
204
|
+
}
|
|
205
|
+
public bindVarchar(parameterIndex: number, value: string) {
|
|
206
|
+
duckdb.bind_varchar(this.prepared_statement, parameterIndex, value);
|
|
207
|
+
}
|
|
208
|
+
public bindBlob(parameterIndex: number, value: Uint8Array) {
|
|
209
|
+
duckdb.bind_blob(this.prepared_statement, parameterIndex, value);
|
|
210
|
+
}
|
|
211
|
+
public bindEnum(parameterIndex: number, value: string, type: DuckDBEnumType) {
|
|
212
|
+
this.bindValue(parameterIndex, value, type);
|
|
213
|
+
}
|
|
214
|
+
public bindArray(
|
|
215
|
+
parameterIndex: number,
|
|
216
|
+
value: DuckDBArrayValue | readonly DuckDBValue[],
|
|
217
|
+
type?: DuckDBArrayType
|
|
218
|
+
) {
|
|
219
|
+
this.bindValue(
|
|
220
|
+
parameterIndex,
|
|
221
|
+
value instanceof DuckDBArrayValue ? value : arrayValue(value),
|
|
222
|
+
type
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
public bindList(
|
|
226
|
+
parameterIndex: number,
|
|
227
|
+
value: DuckDBListValue | readonly DuckDBValue[],
|
|
228
|
+
type?: DuckDBListType
|
|
229
|
+
) {
|
|
230
|
+
this.bindValue(
|
|
231
|
+
parameterIndex,
|
|
232
|
+
value instanceof DuckDBListValue ? value : listValue(value),
|
|
233
|
+
type
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
public bindStruct(
|
|
237
|
+
parameterIndex: number,
|
|
238
|
+
value: DuckDBStructValue | Readonly<Record<string, DuckDBValue>>,
|
|
239
|
+
type?: DuckDBStructType
|
|
240
|
+
) {
|
|
241
|
+
this.bindValue(
|
|
242
|
+
parameterIndex,
|
|
243
|
+
value instanceof DuckDBStructValue ? value : structValue(value),
|
|
244
|
+
type
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
public bindTuple(
|
|
248
|
+
parameterIndex: number,
|
|
249
|
+
value: DuckDBTupleValue | readonly DuckDBValue[],
|
|
250
|
+
type?: DuckDBStructType
|
|
251
|
+
) {
|
|
252
|
+
this.bindValue(
|
|
253
|
+
parameterIndex,
|
|
254
|
+
value instanceof DuckDBTupleValue ? value : tupleValue(value),
|
|
255
|
+
type
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
public bindMap(
|
|
259
|
+
parameterIndex: number,
|
|
260
|
+
value: DuckDBMapValue,
|
|
261
|
+
type?: DuckDBMapType
|
|
262
|
+
) {
|
|
263
|
+
this.bindValue(parameterIndex, value, type);
|
|
264
|
+
}
|
|
265
|
+
public bindUnion(
|
|
266
|
+
parameterIndex: number,
|
|
267
|
+
value: DuckDBUnionValue,
|
|
268
|
+
type?: DuckDBUnionType
|
|
269
|
+
) {
|
|
270
|
+
this.bindValue(parameterIndex, value, type);
|
|
271
|
+
}
|
|
272
|
+
public bindUUID(parameterIndex: number, value: DuckDBUUIDValue) {
|
|
273
|
+
this.bindValue(parameterIndex, value, UUID);
|
|
274
|
+
}
|
|
275
|
+
public bindBit(parameterIndex: number, value: DuckDBBitValue) {
|
|
276
|
+
this.bindValue(parameterIndex, value, BIT);
|
|
277
|
+
}
|
|
278
|
+
public bindVariant(
|
|
279
|
+
parameterIndex: number,
|
|
280
|
+
value: DuckDBVariantValue | null
|
|
281
|
+
) {
|
|
282
|
+
if (value === null) {
|
|
283
|
+
this.bindNull(parameterIndex);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
this.bindValue(parameterIndex, value, VARIANT);
|
|
287
|
+
}
|
|
288
|
+
public bindNull(parameterIndex: number) {
|
|
289
|
+
duckdb.bind_null(this.prepared_statement, parameterIndex);
|
|
290
|
+
}
|
|
291
|
+
public bindValue(
|
|
292
|
+
parameterIndex: number,
|
|
293
|
+
value: DuckDBValue,
|
|
294
|
+
type?: DuckDBType
|
|
295
|
+
) {
|
|
296
|
+
duckdb.bind_value(
|
|
297
|
+
this.prepared_statement,
|
|
298
|
+
parameterIndex,
|
|
299
|
+
createValue(type ? type : typeForValue(value), value)
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
public bind(
|
|
303
|
+
values: DuckDBValue[] | Record<string, DuckDBValue>,
|
|
304
|
+
types?: DuckDBType[] | Record<string, DuckDBType | undefined>
|
|
305
|
+
) {
|
|
306
|
+
if (Array.isArray(values)) {
|
|
307
|
+
const typesIsArray = Array.isArray(types);
|
|
308
|
+
for (let i = 0; i < values.length; i++) {
|
|
309
|
+
this.bindValue(i + 1, values[i], typesIsArray ? types[i] : undefined);
|
|
310
|
+
}
|
|
311
|
+
} else {
|
|
312
|
+
const typesIsRecord = types && !Array.isArray(types);
|
|
313
|
+
for (const key in values) {
|
|
314
|
+
this.bindValue(
|
|
315
|
+
this.parameterIndex(key),
|
|
316
|
+
values[key],
|
|
317
|
+
typesIsRecord ? types[key] : undefined
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
public async run(): Promise<DuckDBMaterializedResult> {
|
|
323
|
+
return new DuckDBMaterializedResult(
|
|
324
|
+
await duckdb.execute_prepared(this.prepared_statement),
|
|
325
|
+
this.statementType
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
public async runAndRead(): Promise<DuckDBResultReader> {
|
|
329
|
+
return new DuckDBResultReader(await this.run());
|
|
330
|
+
}
|
|
331
|
+
public async runAndReadAll(): Promise<DuckDBResultReader> {
|
|
332
|
+
const reader = new DuckDBResultReader(await this.run());
|
|
333
|
+
await reader.readAll();
|
|
334
|
+
return reader;
|
|
335
|
+
}
|
|
336
|
+
public async runAndReadUntil(
|
|
337
|
+
targetRowCount: number
|
|
338
|
+
): Promise<DuckDBResultReader> {
|
|
339
|
+
const reader = new DuckDBResultReader(await this.run());
|
|
340
|
+
await reader.readUntil(targetRowCount);
|
|
341
|
+
return reader;
|
|
342
|
+
}
|
|
343
|
+
public async stream(): Promise<DuckDBResult> {
|
|
344
|
+
return new DuckDBResult(
|
|
345
|
+
await duckdb.execute_prepared_streaming(this.prepared_statement),
|
|
346
|
+
this.statementType
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
public async streamAndRead(): Promise<DuckDBResultReader> {
|
|
350
|
+
return new DuckDBResultReader(await this.stream());
|
|
351
|
+
}
|
|
352
|
+
public async streamAndReadAll(): Promise<DuckDBResultReader> {
|
|
353
|
+
const reader = new DuckDBResultReader(await this.stream());
|
|
354
|
+
await reader.readAll();
|
|
355
|
+
return reader;
|
|
356
|
+
}
|
|
357
|
+
public async streamAndReadUntil(
|
|
358
|
+
targetRowCount: number
|
|
359
|
+
): Promise<DuckDBResultReader> {
|
|
360
|
+
const reader = new DuckDBResultReader(await this.stream());
|
|
361
|
+
await reader.readUntil(targetRowCount);
|
|
362
|
+
return reader;
|
|
363
|
+
}
|
|
364
|
+
public start(): DuckDBPendingResult {
|
|
365
|
+
return new DuckDBPendingResult(
|
|
366
|
+
duckdb.pending_prepared(this.prepared_statement),
|
|
367
|
+
this.statementType
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
public startStream(): DuckDBPendingResult {
|
|
371
|
+
return new DuckDBPendingResult(
|
|
372
|
+
duckdb.pending_prepared_streaming(this.prepared_statement),
|
|
373
|
+
this.statementType
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DuckDBPreparedStatement } from './DuckDBPreparedStatement';
|
|
2
|
+
import { DuckDBPreparedStatementCollection } from './DuckDBPreparedStatementCollection';
|
|
3
|
+
|
|
4
|
+
export class DuckDBPreparedStatementWeakRefCollection
|
|
5
|
+
implements DuckDBPreparedStatementCollection
|
|
6
|
+
{
|
|
7
|
+
preparedStatements: WeakRef<DuckDBPreparedStatement>[] = [];
|
|
8
|
+
lastPruneTime: number = 0;
|
|
9
|
+
public add(prepared: DuckDBPreparedStatement) {
|
|
10
|
+
const now = performance.now();
|
|
11
|
+
if (now - this.lastPruneTime > 1000) {
|
|
12
|
+
this.lastPruneTime = now;
|
|
13
|
+
this.prune();
|
|
14
|
+
}
|
|
15
|
+
this.preparedStatements.push(new WeakRef(prepared));
|
|
16
|
+
}
|
|
17
|
+
public destroySync() {
|
|
18
|
+
for (const preparedRef of this.preparedStatements) {
|
|
19
|
+
const prepared = preparedRef.deref();
|
|
20
|
+
if (prepared) {
|
|
21
|
+
prepared.destroySync();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
this.preparedStatements = [];
|
|
25
|
+
}
|
|
26
|
+
private prune() {
|
|
27
|
+
this.preparedStatements = this.preparedStatements.filter(
|
|
28
|
+
(ref) => !!ref.deref()
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|