@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,162 @@
|
|
|
1
|
+
// Generated by scripts/gen-contract.ts from vendor/node-api/node-bindings.d.ts; do not edit.
|
|
2
|
+
|
|
3
|
+
export const sizeof_bool: number = 1;
|
|
4
|
+
|
|
5
|
+
export enum CatalogEntryType {
|
|
6
|
+
INVALID = 0,
|
|
7
|
+
TABLE = 1,
|
|
8
|
+
SCHEMA = 2,
|
|
9
|
+
VIEW = 3,
|
|
10
|
+
INDEX = 4,
|
|
11
|
+
PREPARED_STATEMENT = 5,
|
|
12
|
+
SEQUENCE = 6,
|
|
13
|
+
COLLATION = 7,
|
|
14
|
+
TYPE = 8,
|
|
15
|
+
DATABASE = 9,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export enum PendingState {
|
|
19
|
+
RESULT_READY = 0,
|
|
20
|
+
RESULT_NOT_READY = 1,
|
|
21
|
+
ERROR = 2,
|
|
22
|
+
NO_TASKS_AVAILABLE = 3,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export enum ResultType {
|
|
26
|
+
INVALID = 0,
|
|
27
|
+
CHANGED_ROWS = 1,
|
|
28
|
+
NOTHING = 2,
|
|
29
|
+
QUERY_RESULT = 3,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export enum StatementType {
|
|
33
|
+
INVALID = 0,
|
|
34
|
+
SELECT = 1,
|
|
35
|
+
INSERT = 2,
|
|
36
|
+
UPDATE = 3,
|
|
37
|
+
EXPLAIN = 4,
|
|
38
|
+
DELETE = 5,
|
|
39
|
+
PREPARE = 6,
|
|
40
|
+
CREATE = 7,
|
|
41
|
+
EXECUTE = 8,
|
|
42
|
+
ALTER = 9,
|
|
43
|
+
TRANSACTION = 10,
|
|
44
|
+
COPY = 11,
|
|
45
|
+
ANALYZE = 12,
|
|
46
|
+
VARIABLE_SET = 13,
|
|
47
|
+
CREATE_FUNC = 14,
|
|
48
|
+
DROP = 15,
|
|
49
|
+
EXPORT = 16,
|
|
50
|
+
PRAGMA = 17,
|
|
51
|
+
VACUUM = 18,
|
|
52
|
+
CALL = 19,
|
|
53
|
+
SET = 20,
|
|
54
|
+
LOAD = 21,
|
|
55
|
+
RELATION = 22,
|
|
56
|
+
EXTENSION = 23,
|
|
57
|
+
LOGICAL_PLAN = 24,
|
|
58
|
+
ATTACH = 25,
|
|
59
|
+
DETACH = 26,
|
|
60
|
+
MULTI = 27,
|
|
61
|
+
COPY_DATABASE = 28,
|
|
62
|
+
UPDATE_EXTENSIONS = 29,
|
|
63
|
+
MERGE_INTO = 30,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export enum Type {
|
|
67
|
+
INVALID = 0,
|
|
68
|
+
BOOLEAN = 1,
|
|
69
|
+
TINYINT = 2,
|
|
70
|
+
SMALLINT = 3,
|
|
71
|
+
INTEGER = 4,
|
|
72
|
+
BIGINT = 5,
|
|
73
|
+
UTINYINT = 6,
|
|
74
|
+
USMALLINT = 7,
|
|
75
|
+
UINTEGER = 8,
|
|
76
|
+
UBIGINT = 9,
|
|
77
|
+
FLOAT = 10,
|
|
78
|
+
DOUBLE = 11,
|
|
79
|
+
TIMESTAMP = 12,
|
|
80
|
+
DATE = 13,
|
|
81
|
+
TIME = 14,
|
|
82
|
+
INTERVAL = 15,
|
|
83
|
+
HUGEINT = 16,
|
|
84
|
+
UHUGEINT = 32,
|
|
85
|
+
VARCHAR = 17,
|
|
86
|
+
BLOB = 18,
|
|
87
|
+
DECIMAL = 19,
|
|
88
|
+
TIMESTAMP_S = 20,
|
|
89
|
+
TIMESTAMP_MS = 21,
|
|
90
|
+
TIMESTAMP_NS = 22,
|
|
91
|
+
ENUM = 23,
|
|
92
|
+
LIST = 24,
|
|
93
|
+
STRUCT = 25,
|
|
94
|
+
MAP = 26,
|
|
95
|
+
ARRAY = 33,
|
|
96
|
+
UUID = 27,
|
|
97
|
+
UNION = 28,
|
|
98
|
+
BIT = 29,
|
|
99
|
+
TIME_TZ = 30,
|
|
100
|
+
TIMESTAMP_TZ = 31,
|
|
101
|
+
ANY = 34,
|
|
102
|
+
BIGNUM = 35,
|
|
103
|
+
SQLNULL = 36,
|
|
104
|
+
STRING_LITERAL = 37,
|
|
105
|
+
INTEGER_LITERAL = 38,
|
|
106
|
+
TIME_NS = 39,
|
|
107
|
+
GEOMETRY = 40,
|
|
108
|
+
VARIANT = 41,
|
|
109
|
+
TIMESTAMP_TZ_NS = 42,
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export type {
|
|
113
|
+
Appender,
|
|
114
|
+
BindInfo,
|
|
115
|
+
Catalog,
|
|
116
|
+
CatalogEntry,
|
|
117
|
+
ClientContext,
|
|
118
|
+
Config,
|
|
119
|
+
ConfigFlag,
|
|
120
|
+
Connection,
|
|
121
|
+
Database,
|
|
122
|
+
DataChunk,
|
|
123
|
+
Date_,
|
|
124
|
+
DateParts,
|
|
125
|
+
Decimal,
|
|
126
|
+
ExtractedStatements,
|
|
127
|
+
ExtractedStatementsAndCount,
|
|
128
|
+
FunctionInfo,
|
|
129
|
+
InstanceCache,
|
|
130
|
+
Interval,
|
|
131
|
+
LogicalType,
|
|
132
|
+
PendingResult,
|
|
133
|
+
PreparedStatement,
|
|
134
|
+
QueryProgress,
|
|
135
|
+
Result,
|
|
136
|
+
ScalarFunction,
|
|
137
|
+
ScalarFunctionBindFunction,
|
|
138
|
+
ScalarFunctionBindInfo,
|
|
139
|
+
ScalarFunctionInfo,
|
|
140
|
+
ScalarFunctionInitFunction,
|
|
141
|
+
ScalarFunctionInitInfo,
|
|
142
|
+
ScalarFunctionMainFunction,
|
|
143
|
+
TableFunction,
|
|
144
|
+
TableFunctionBindFunction,
|
|
145
|
+
TableFunctionBindInfo,
|
|
146
|
+
TableFunctionInfo,
|
|
147
|
+
TableFunctionInitFunction,
|
|
148
|
+
TableFunctionInitInfo,
|
|
149
|
+
TableFunctionMainFunction,
|
|
150
|
+
Time,
|
|
151
|
+
TimeNS,
|
|
152
|
+
TimeParts,
|
|
153
|
+
Timestamp,
|
|
154
|
+
TimestampMilliseconds,
|
|
155
|
+
TimestampNanoseconds,
|
|
156
|
+
TimestampParts,
|
|
157
|
+
TimestampSeconds,
|
|
158
|
+
TimeTZ,
|
|
159
|
+
TimeTZParts,
|
|
160
|
+
Value,
|
|
161
|
+
Vector,
|
|
162
|
+
} from "../../../vendor/node-api/node-bindings.d.ts";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Our reimplementation of the `@duckdb/node-bindings` contract
|
|
2
|
+
// (vendor/node-api/node-bindings.d.ts) over the libduckdb C API, through bun:ffi
|
|
3
|
+
// and the Rust shim. The vendored `@duckdb/node-api` imports it as a default
|
|
4
|
+
// (`import duckdb from ...`), a namespace and by name, so it exports all three.
|
|
5
|
+
// The default export is a namespace, so `duckdb.Database` and the other contract
|
|
6
|
+
// types resolve through it as they do through the official module.
|
|
7
|
+
import * as duckdb from "./api/index.ts";
|
|
8
|
+
|
|
9
|
+
export * from "./api/index.ts";
|
|
10
|
+
export default duckdb;
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
// JavaScript argument checks and conversions, ported from the official binding's
|
|
2
|
+
// bindings/src/conversion_helpers.h (vendored tag), with the same error text.
|
|
3
|
+
// Where the official binding gets a JS value through a node-addon-api cast, a
|
|
4
|
+
// value of the wrong JS type fails with N-API's own message, such as
|
|
5
|
+
// "A number was expected", and these helpers throw the same. node-addon-api
|
|
6
|
+
// raises the number, string, boolean, and object expectations as a TypeError and
|
|
7
|
+
// every other N-API status, "A bigint was expected" included, as an Error.
|
|
8
|
+
|
|
9
|
+
// --- N-API type expectations ----------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
export function expectNumber(value: unknown): number {
|
|
12
|
+
if (typeof value !== "number") throw new TypeError("A number was expected");
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function expectBigInt(value: unknown): bigint {
|
|
17
|
+
if (typeof value !== "bigint") throw new Error("A bigint was expected");
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function expectString(value: unknown): string {
|
|
22
|
+
if (typeof value !== "string") throw new TypeError("A string was expected");
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function expectBoolean(value: unknown): boolean {
|
|
27
|
+
if (typeof value !== "boolean") throw new TypeError("A boolean was expected");
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* An object argument whose properties the official binding reads with
|
|
33
|
+
* node-addon-api's Object::Get. N-API converts the value with ToObject first, so
|
|
34
|
+
* a primitive other than null and undefined reads as its wrapper object, whose
|
|
35
|
+
* fields are missing, and the field's own check is what fails. For null and
|
|
36
|
+
* undefined, the official binding under Bun throws Bun's own TypeError, such as
|
|
37
|
+
* "null is not an object (evaluating '...')", whose text quotes the caller's
|
|
38
|
+
* source; this throws N-API's object expectation instead.
|
|
39
|
+
*/
|
|
40
|
+
export function expectObject(value: unknown): Record<string, unknown> {
|
|
41
|
+
if (value === null || value === undefined) throw new TypeError("An object was expected");
|
|
42
|
+
return Object(value) as Record<string, unknown>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A value the official binding keeps with napi_create_reference: extra info,
|
|
47
|
+
* bind data, init data, and scalar function state. The runtime refuses a
|
|
48
|
+
* reference to null or to a number, string, boolean, or bigint with
|
|
49
|
+
* napi_invalid_arg, which node-addon-api reports as "Invalid argument".
|
|
50
|
+
*/
|
|
51
|
+
export function expectReferenceable<T>(value: T): T {
|
|
52
|
+
if (value === null || ["number", "string", "boolean", "bigint"].includes(typeof value)) {
|
|
53
|
+
throw new Error("Invalid argument");
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function expectArray(value: unknown): readonly unknown[] {
|
|
59
|
+
if (!Array.isArray(value)) throw new Error("An array was expected");
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// --- N-API number coercions ------------------------------------------------------------
|
|
64
|
+
// The official binding reads some numbers with node-addon-api's lossy accessors
|
|
65
|
+
// rather than GetIntegerFromNumber; these reproduce what each accessor returns.
|
|
66
|
+
|
|
67
|
+
/** Number::Int32Value: ToInt32, so fractions truncate, values wrap modulo 2^32, and NaN and infinities read as 0. */
|
|
68
|
+
export function int32FromNumber(value: unknown): number {
|
|
69
|
+
return expectNumber(value) | 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Number::Uint32Value: ToUint32, so a negative index arrives as a large unsigned one. */
|
|
73
|
+
export function uint32FromNumber(value: unknown): number {
|
|
74
|
+
return expectNumber(value) >>> 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const INT64_MAX = 2n ** 63n - 1n;
|
|
78
|
+
const INT64_MIN = -(2n ** 63n);
|
|
79
|
+
|
|
80
|
+
/** Number::Int64Value: truncates, saturates at the int64 bounds, and reads NaN and infinities as 0. */
|
|
81
|
+
export function int64FromNumber(value: unknown): bigint {
|
|
82
|
+
const number = expectNumber(value);
|
|
83
|
+
if (!Number.isFinite(number)) return 0n;
|
|
84
|
+
if (number >= 2 ** 63) return INT64_MAX;
|
|
85
|
+
if (number <= -(2 ** 63)) return INT64_MIN;
|
|
86
|
+
return BigInt(Math.trunc(number));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** node-addon-api's Function cast, as the official binding makes before it stores a callback. */
|
|
90
|
+
export function expectFunction<T>(value: T): T {
|
|
91
|
+
if (typeof value !== "function") throw new Error("A function was expected");
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// --- bounds -------------------------------------------------------------------------------
|
|
96
|
+
|
|
97
|
+
export function throwIndexOutOfRange(index: number | bigint, count: number | bigint, what: string): never {
|
|
98
|
+
throw new RangeError(`${what} index ${index} is out of range (count: ${count})`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function checkIndexInRange(index: number, count: number, what: string): void {
|
|
102
|
+
if (index >= count) throwIndexOutOfRange(index, count, what);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function checkOneBasedIndexInRange(index: number, count: number, what: string): void {
|
|
106
|
+
if (index < 1 || index > count) throwIndexOutOfRange(index, count, what);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Call before handing a row index to a duckdb_validity_* function, which indexes the mask unchecked. */
|
|
110
|
+
export function checkValidityRowInRange(mask: Uint8Array, rowIndex: number): void {
|
|
111
|
+
const rowCount = mask.byteLength * 8;
|
|
112
|
+
if (rowIndex >= rowCount) {
|
|
113
|
+
throw new RangeError(
|
|
114
|
+
`row index ${rowIndex} is out of range for a validity mask of ${mask.byteLength} bytes (${rowCount} rows)`,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// --- fixed-width integers from JS numbers ---------------------------------------------
|
|
120
|
+
|
|
121
|
+
const INTEGER_RANGES = {
|
|
122
|
+
int8: [-128, 127],
|
|
123
|
+
int16: [-32768, 32767],
|
|
124
|
+
int32: [-2147483648, 2147483647],
|
|
125
|
+
uint8: [0, 255],
|
|
126
|
+
uint16: [0, 65535],
|
|
127
|
+
uint32: [0, 4294967295],
|
|
128
|
+
} as const;
|
|
129
|
+
|
|
130
|
+
export type IntegerType = keyof typeof INTEGER_RANGES;
|
|
131
|
+
|
|
132
|
+
/** Rejects any number that does not fit `type` exactly, as GetIntegerFromNumber does. */
|
|
133
|
+
export function integerFromNumber(value: unknown, type: IntegerType, valueName = "number"): number {
|
|
134
|
+
const number = expectNumber(value);
|
|
135
|
+
if (!Number.isFinite(number) || number !== Math.trunc(number)) throw new Error(`${valueName} is not an integer`);
|
|
136
|
+
const [min, max] = INTEGER_RANGES[type];
|
|
137
|
+
if (number < min || number > max) throw new Error(`${valueName} out of ${type} range`);
|
|
138
|
+
return number;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* An unsigned 64-bit index or count from a JS number, as node-addon-api's
|
|
143
|
+
* Number::Int64Value then a cast to idx_t: fractions truncate and a negative
|
|
144
|
+
* value wraps, so callers range-check the result against a count.
|
|
145
|
+
*/
|
|
146
|
+
export function indexFromNumber(value: unknown): number {
|
|
147
|
+
const number = Math.trunc(expectNumber(value));
|
|
148
|
+
return Number.isFinite(number) ? number : 0;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// --- 64-bit and wider integers from BigInts -----------------------------------------------
|
|
152
|
+
|
|
153
|
+
/** An int64 from a BigInt, rejecting a lossy conversion with `${name} out of int64 range`. */
|
|
154
|
+
export function int64FromBigInt(value: unknown, name: string): bigint {
|
|
155
|
+
const big = expectBigInt(value);
|
|
156
|
+
if (BigInt.asIntN(64, big) !== big) throw new Error(`${name} out of int64 range`);
|
|
157
|
+
return big;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function uint64FromBigInt(value: unknown, name: string): bigint {
|
|
161
|
+
const big = expectBigInt(value);
|
|
162
|
+
if (BigInt.asUintN(64, big) !== big) throw new Error(`${name} out of uint64 range`);
|
|
163
|
+
return big;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const TWO_128 = 1n << 128n;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* A hugeint from a BigInt. Like GetHugeIntFromBigInt, it rejects a magnitude
|
|
170
|
+
* wider than 128 bits and wraps anything narrower into the 128-bit two's
|
|
171
|
+
* complement range.
|
|
172
|
+
*/
|
|
173
|
+
export function hugeintFromBigInt(value: unknown): bigint {
|
|
174
|
+
const big = expectBigInt(value);
|
|
175
|
+
if ((big < 0n ? -big : big) >= TWO_128) throw new Error("bigint out of hugeint range");
|
|
176
|
+
return BigInt.asIntN(128, big);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function uhugeintFromBigInt(value: unknown): bigint {
|
|
180
|
+
const big = expectBigInt(value);
|
|
181
|
+
if (big < 0n || big >= TWO_128) throw new Error("bigint out of uhugeint range");
|
|
182
|
+
return big;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// --- struct objects ------------------------------------------------------------------------
|
|
186
|
+
|
|
187
|
+
export interface DateParts {
|
|
188
|
+
year: number;
|
|
189
|
+
month: number;
|
|
190
|
+
day: number;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export interface TimeParts {
|
|
194
|
+
hour: number;
|
|
195
|
+
min: number;
|
|
196
|
+
sec: number;
|
|
197
|
+
micros: number;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function dateFromObject(value: unknown): { days: number } {
|
|
201
|
+
return { days: integerFromNumber(expectObject(value).days, "int32", "days") };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function datePartsFromObject(value: unknown): DateParts {
|
|
205
|
+
const object = expectObject(value);
|
|
206
|
+
return {
|
|
207
|
+
year: integerFromNumber(object.year, "int32", "year"),
|
|
208
|
+
month: integerFromNumber(object.month, "int8", "month"),
|
|
209
|
+
day: integerFromNumber(object.day, "int8", "day"),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export function timeFromObject(value: unknown): { micros: bigint } {
|
|
214
|
+
return { micros: int64FromBigInt(expectObject(value).micros, "micros") };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function timePartsFromObject(value: unknown): TimeParts {
|
|
218
|
+
const object = expectObject(value);
|
|
219
|
+
return {
|
|
220
|
+
hour: integerFromNumber(object.hour, "int8", "hour"),
|
|
221
|
+
min: integerFromNumber(object.min, "int8", "min"),
|
|
222
|
+
sec: integerFromNumber(object.sec, "int8", "sec"),
|
|
223
|
+
micros: integerFromNumber(object.micros, "int32", "micros"),
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function timeNsFromObject(value: unknown): { nanos: bigint } {
|
|
228
|
+
return { nanos: int64FromBigInt(expectObject(value).nanos, "nanos") };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function timeTzFromObject(value: unknown): { bits: bigint } {
|
|
232
|
+
return { bits: uint64FromBigInt(expectObject(value).bits, "bits") };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function timestampFromObject(value: unknown): { micros: bigint } {
|
|
236
|
+
return { micros: int64FromBigInt(expectObject(value).micros, "micros") };
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function timestampSecondsFromObject(value: unknown): { seconds: bigint } {
|
|
240
|
+
return { seconds: int64FromBigInt(expectObject(value).seconds, "seconds") };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function timestampMillisecondsFromObject(value: unknown): { millis: bigint } {
|
|
244
|
+
return { millis: int64FromBigInt(expectObject(value).millis, "millis") };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function timestampNanosecondsFromObject(value: unknown): { nanos: bigint } {
|
|
248
|
+
return { nanos: int64FromBigInt(expectObject(value).nanos, "nanos") };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function timestampPartsFromObject(value: unknown): { date: DateParts; time: TimeParts } {
|
|
252
|
+
const object = expectObject(value);
|
|
253
|
+
return { date: datePartsFromObject(object.date), time: timePartsFromObject(object.time) };
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export function intervalFromObject(value: unknown): { months: number; days: number; micros: bigint } {
|
|
257
|
+
const object = expectObject(value);
|
|
258
|
+
return {
|
|
259
|
+
months: integerFromNumber(object.months, "int32", "months"),
|
|
260
|
+
days: integerFromNumber(object.days, "int32", "days"),
|
|
261
|
+
micros: int64FromBigInt(object.micros, "micros"),
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export function decimalFromObject(value: unknown): { width: number; scale: number; value: bigint } {
|
|
266
|
+
const object = expectObject(value);
|
|
267
|
+
return {
|
|
268
|
+
width: integerFromNumber(object.width, "uint8", "width"),
|
|
269
|
+
scale: integerFromNumber(object.scale, "uint8", "scale"),
|
|
270
|
+
value: hugeintFromBigInt(object.value),
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// --- bignum ----------------------------------------------------------------------------------
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* The big-endian magnitude bytes and sign of a BigInt, padded to whole 64-bit
|
|
278
|
+
* words as GetBigNumFromBigInt does. Zero is one zero byte rather than the
|
|
279
|
+
* official binding's empty array: DuckDB's Bignum::FromByteArray throws a C++
|
|
280
|
+
* exception for an empty array, which aborts the process.
|
|
281
|
+
*/
|
|
282
|
+
export function bignumFromBigInt(value: unknown): { bytes: Uint8Array; isNegative: boolean } {
|
|
283
|
+
const big = expectBigInt(value);
|
|
284
|
+
if (big === 0n) return { bytes: new Uint8Array(1), isNegative: false };
|
|
285
|
+
const isNegative = big < 0n;
|
|
286
|
+
let magnitude = isNegative ? -big : big;
|
|
287
|
+
let wordCount = 0;
|
|
288
|
+
for (let rest = magnitude; rest > 0n; rest >>= 64n) wordCount++;
|
|
289
|
+
const bytes = new Uint8Array(wordCount * 8);
|
|
290
|
+
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
291
|
+
bytes[i] = Number(magnitude & 0xffn);
|
|
292
|
+
magnitude >>= 8n;
|
|
293
|
+
}
|
|
294
|
+
return { bytes, isNegative };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* The BigInt for big-endian magnitude bytes of any length. The official
|
|
299
|
+
* MakeBigIntFromBigNum reads only size / 8 whole words, so it returns a wrong
|
|
300
|
+
* value for every bignum whose byte count is not a multiple of 8, which is
|
|
301
|
+
* every bignum DuckDB produces itself (`1::BIGNUM` has one byte).
|
|
302
|
+
*/
|
|
303
|
+
export function bigIntFromBignum(bytes: Uint8Array, isNegative: boolean): bigint {
|
|
304
|
+
let magnitude = 0n;
|
|
305
|
+
for (const byte of bytes) magnitude = (magnitude << 8n) | BigInt(byte);
|
|
306
|
+
return isNegative ? -magnitude : magnitude;
|
|
307
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// diagnostics(): a snapshot of the binding's native state, for leak hunting,
|
|
2
|
+
// support requests and health checks. README.md documents every field.
|
|
3
|
+
import { toArrayBuffer } from "bun:ffi";
|
|
4
|
+
import { jobsInFlight } from "./dispatch.ts";
|
|
5
|
+
import { flags } from "./flags.ts";
|
|
6
|
+
import { liveHandles } from "./handle.ts";
|
|
7
|
+
import { crashHandler, libraryPath, shim, shimPath, versions } from "./native.ts";
|
|
8
|
+
import { CALL_CHANNEL } from "./trace.ts";
|
|
9
|
+
|
|
10
|
+
export interface Diagnostics {
|
|
11
|
+
versions: { package: string; duckdb: string; bun: string; shim: string };
|
|
12
|
+
paths: { libduckdb: string; shim: string };
|
|
13
|
+
crashHandler: string;
|
|
14
|
+
flags: { debug: boolean; traceSql: boolean; crashHandler: boolean };
|
|
15
|
+
tracingChannel: string;
|
|
16
|
+
/** Native threads running blocking calls now, and the most at once. */
|
|
17
|
+
nativeThreads: { running: number; peak: number };
|
|
18
|
+
/** Blocking calls run on native threads: started, completed, and awaited by JavaScript now. */
|
|
19
|
+
jobs: { started: number; completed: number; inFlight: number };
|
|
20
|
+
/** Scalar and table function callbacks DuckDB made: posted from its threads, completed, and run inline. */
|
|
21
|
+
callbacks: { posted: number; completed: number; inline: number };
|
|
22
|
+
/** Entries written to the crash-report ring buffer. */
|
|
23
|
+
ringEntries: number;
|
|
24
|
+
/** Owned native handles not yet freed, by kind. */
|
|
25
|
+
liveHandles: Record<string, number>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const COUNTERS = 8;
|
|
29
|
+
|
|
30
|
+
export function diagnostics(): Diagnostics {
|
|
31
|
+
const counters = new BigUint64Array(toArrayBuffer(shim.dbs_counters() as never, 0, COUNTERS * 8));
|
|
32
|
+
const at = (index: number) => Number(counters[index]);
|
|
33
|
+
return {
|
|
34
|
+
versions: { ...versions },
|
|
35
|
+
paths: { libduckdb: libraryPath, shim: shimPath },
|
|
36
|
+
crashHandler,
|
|
37
|
+
flags: { ...flags },
|
|
38
|
+
tracingChannel: CALL_CHANNEL,
|
|
39
|
+
nativeThreads: { running: at(0), peak: at(1) },
|
|
40
|
+
jobs: { started: at(2), completed: at(3), inFlight: jobsInFlight() },
|
|
41
|
+
callbacks: { posted: at(4), completed: at(5), inline: at(6) },
|
|
42
|
+
ringEntries: at(7),
|
|
43
|
+
liveHandles: liveHandles(),
|
|
44
|
+
};
|
|
45
|
+
}
|