@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,288 @@
|
|
|
1
|
+
// Appender functions of the @duckdb/node-bindings contract. Semantics and
|
|
2
|
+
// error text follow the official binding (bindings/src/duckdb_node_bindings.cpp
|
|
3
|
+
// at the vendored tag): every failing call throws DuckDB's appender error.
|
|
4
|
+
import type { Pointer } from "bun:ffi";
|
|
5
|
+
import type {
|
|
6
|
+
Appender,
|
|
7
|
+
Connection,
|
|
8
|
+
DataChunk,
|
|
9
|
+
Date_,
|
|
10
|
+
Interval,
|
|
11
|
+
LogicalType,
|
|
12
|
+
Time,
|
|
13
|
+
Timestamp,
|
|
14
|
+
Value,
|
|
15
|
+
} from "../generated/contract.ts";
|
|
16
|
+
import {
|
|
17
|
+
dateFromObject,
|
|
18
|
+
expectBoolean,
|
|
19
|
+
expectNumber,
|
|
20
|
+
expectString,
|
|
21
|
+
hugeintFromBigInt,
|
|
22
|
+
type IntegerType,
|
|
23
|
+
int64FromBigInt,
|
|
24
|
+
integerFromNumber,
|
|
25
|
+
intervalFromObject,
|
|
26
|
+
throwIndexOutOfRange,
|
|
27
|
+
timeFromObject,
|
|
28
|
+
timestampFromObject,
|
|
29
|
+
uhugeintFromBigInt,
|
|
30
|
+
uint32FromNumber,
|
|
31
|
+
uint64FromBigInt,
|
|
32
|
+
} from "../runtime/convert.ts";
|
|
33
|
+
import { type Handle, unwrap } from "../runtime/handle.ts";
|
|
34
|
+
import { own } from "../runtime/kinds.ts";
|
|
35
|
+
import { cstr, encode, type LayoutName, readCString, slot, slotValue, utf8 } from "../runtime/marshal.ts";
|
|
36
|
+
import { duckdb, shim } from "../runtime/native.ts";
|
|
37
|
+
import { RingOp, record } from "../runtime/ring.ts";
|
|
38
|
+
|
|
39
|
+
function asHandle<T>(handle: Handle): T {
|
|
40
|
+
return handle as unknown as T;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** duckdb_appender_error is set whenever an appender call fails. */
|
|
44
|
+
function appenderError(appender: Pointer | null): Error {
|
|
45
|
+
return new Error(readCString(duckdb.duckdb_appender_error(appender) as Pointer | null) ?? "Unknown appender error");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function check(appender: Pointer | null, failed: number): void {
|
|
49
|
+
if (failed) throw appenderError(appender);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// --- create ----------------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
function connectionForAppender(connection: Connection): Pointer {
|
|
55
|
+
const ptr = unwrap(connection, "connection");
|
|
56
|
+
if (ptr === null) throw new Error("Failed to create appender: connection disconnected");
|
|
57
|
+
return ptr;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** A nullable name as the C API takes it: null, or a NUL-terminated copy. */
|
|
61
|
+
function optionalName(name: string | null): Buffer | null {
|
|
62
|
+
return name === null ? null : cstr(expectString(name));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Wraps the created appender, or throws its error after destroying it, as the official binding does. */
|
|
66
|
+
function created(failed: number, out: BigUint64Array): Appender {
|
|
67
|
+
if (failed) {
|
|
68
|
+
const error = appenderError(slotValue(out));
|
|
69
|
+
duckdb.duckdb_appender_destroy(out);
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
return asHandle(own("appender", slotValue(out) as Pointer));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function appender_create(connection: Connection, schema: string | null, table: string): Appender {
|
|
76
|
+
const ptr = connectionForAppender(connection);
|
|
77
|
+
const schemaName = optionalName(schema);
|
|
78
|
+
const tableName = cstr(expectString(table));
|
|
79
|
+
const out = slot();
|
|
80
|
+
return created(duckdb.duckdb_appender_create(ptr, schemaName, tableName, out), out);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function appender_create_ext(
|
|
84
|
+
connection: Connection,
|
|
85
|
+
catalog: string | null,
|
|
86
|
+
schema: string | null,
|
|
87
|
+
table: string,
|
|
88
|
+
): Appender {
|
|
89
|
+
const ptr = connectionForAppender(connection);
|
|
90
|
+
const catalogName = optionalName(catalog);
|
|
91
|
+
const schemaName = optionalName(schema);
|
|
92
|
+
const tableName = cstr(expectString(table));
|
|
93
|
+
const out = slot();
|
|
94
|
+
return created(duckdb.duckdb_appender_create_ext(ptr, catalogName, schemaName, tableName, out), out);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// --- columns, flush, close -------------------------------------------------------------------
|
|
98
|
+
|
|
99
|
+
export function appender_column_count(appender: Appender): number {
|
|
100
|
+
return Number(duckdb.duckdb_appender_column_count(unwrap(appender, "appender")));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function appender_column_type(appender: Appender, column_index: number): LogicalType {
|
|
104
|
+
const ptr = unwrap(appender, "appender");
|
|
105
|
+
const index = uint32FromNumber(column_index);
|
|
106
|
+
const type = duckdb.duckdb_appender_column_type(ptr, index) as Pointer | null;
|
|
107
|
+
if (type === null) throwIndexOutOfRange(index, Number(duckdb.duckdb_appender_column_count(ptr)), "column");
|
|
108
|
+
return asHandle(own("logical type", type));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function appender_flush_sync(appender: Appender): void {
|
|
112
|
+
const ptr = unwrap(appender, "appender");
|
|
113
|
+
record(RingOp.appenderFlush, ptr);
|
|
114
|
+
check(ptr, duckdb.duckdb_appender_flush(ptr));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function appender_clear(appender: Appender): void {
|
|
118
|
+
const ptr = unwrap(appender, "appender");
|
|
119
|
+
check(ptr, duckdb.duckdb_appender_clear(ptr));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function appender_close_sync(appender: Appender): void {
|
|
123
|
+
const ptr = unwrap(appender, "appender");
|
|
124
|
+
record(RingOp.appenderClose, ptr);
|
|
125
|
+
check(ptr, duckdb.duckdb_appender_close(ptr));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function appender_end_row(appender: Appender): void {
|
|
129
|
+
const ptr = unwrap(appender, "appender");
|
|
130
|
+
check(ptr, duckdb.duckdb_appender_end_row(ptr));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// --- append ----------------------------------------------------------------------------------
|
|
134
|
+
|
|
135
|
+
export function append_default(appender: Appender): void {
|
|
136
|
+
const ptr = unwrap(appender, "appender");
|
|
137
|
+
check(ptr, duckdb.duckdb_append_default(ptr));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function append_bool(appender: Appender, bool: boolean): void {
|
|
141
|
+
const ptr = unwrap(appender, "appender");
|
|
142
|
+
check(ptr, duckdb.duckdb_append_bool(ptr, expectBoolean(bool)));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function appendInteger(
|
|
146
|
+
appender: Appender,
|
|
147
|
+
type: IntegerType,
|
|
148
|
+
value: unknown,
|
|
149
|
+
append: (ptr: Pointer | null, value: number) => number,
|
|
150
|
+
): void {
|
|
151
|
+
const ptr = unwrap(appender, "appender");
|
|
152
|
+
check(ptr, append(ptr, integerFromNumber(value, type)));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Appends a by-value struct through the shim's pointer wrapper. */
|
|
156
|
+
/**
|
|
157
|
+
* Appends a struct the C API takes by value. `value` converts the argument only
|
|
158
|
+
* after the appender is checked, so a bad appender is reported first, as the
|
|
159
|
+
* official binding reads its arguments in order.
|
|
160
|
+
*/
|
|
161
|
+
function appendStruct(
|
|
162
|
+
appender: Appender,
|
|
163
|
+
layout: LayoutName,
|
|
164
|
+
value: () => unknown,
|
|
165
|
+
append: (ptr: Pointer | null, value: Uint8Array) => number,
|
|
166
|
+
): void {
|
|
167
|
+
const ptr = unwrap(appender, "appender");
|
|
168
|
+
check(ptr, append(ptr, encode(layout, value())));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function append_int8(appender: Appender, int8: number): void {
|
|
172
|
+
appendInteger(appender, "int8", int8, (p, v) => duckdb.duckdb_append_int8(p, v));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function append_int16(appender: Appender, int16: number): void {
|
|
176
|
+
appendInteger(appender, "int16", int16, (p, v) => duckdb.duckdb_append_int16(p, v));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function append_int32(appender: Appender, int32: number): void {
|
|
180
|
+
appendInteger(appender, "int32", int32, (p, v) => duckdb.duckdb_append_int32(p, v));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function append_int64(appender: Appender, int64: bigint): void {
|
|
184
|
+
const ptr = unwrap(appender, "appender");
|
|
185
|
+
check(ptr, duckdb.duckdb_append_int64(ptr, int64FromBigInt(int64, "bigint")));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function append_hugeint(appender: Appender, hugeint: bigint): void {
|
|
189
|
+
const ptr = unwrap(appender, "appender");
|
|
190
|
+
check(ptr, shim.dbs_append_hugeint(ptr, encode("hugeint", hugeintFromBigInt(hugeint))));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function append_uint8(appender: Appender, uint8: number): void {
|
|
194
|
+
appendInteger(appender, "uint8", uint8, (p, v) => duckdb.duckdb_append_uint8(p, v));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function append_uint16(appender: Appender, uint16: number): void {
|
|
198
|
+
appendInteger(appender, "uint16", uint16, (p, v) => duckdb.duckdb_append_uint16(p, v));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function append_uint32(appender: Appender, uint32: number): void {
|
|
202
|
+
appendInteger(appender, "uint32", uint32, (p, v) => duckdb.duckdb_append_uint32(p, v));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function append_uint64(appender: Appender, uint64: bigint): void {
|
|
206
|
+
const ptr = unwrap(appender, "appender");
|
|
207
|
+
check(ptr, duckdb.duckdb_append_uint64(ptr, uint64FromBigInt(uint64, "bigint")));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function append_uhugeint(appender: Appender, uhugeint: bigint): void {
|
|
211
|
+
const ptr = unwrap(appender, "appender");
|
|
212
|
+
check(ptr, shim.dbs_append_uhugeint(ptr, encode("uhugeint", uhugeintFromBigInt(uhugeint))));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function append_float(appender: Appender, float: number): void {
|
|
216
|
+
const ptr = unwrap(appender, "appender");
|
|
217
|
+
check(ptr, duckdb.duckdb_append_float(ptr, expectNumber(float)));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function append_double(appender: Appender, double: number): void {
|
|
221
|
+
const ptr = unwrap(appender, "appender");
|
|
222
|
+
check(ptr, duckdb.duckdb_append_double(ptr, expectNumber(double)));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function append_date(appender: Appender, date: Date_): void {
|
|
226
|
+
appendStruct(
|
|
227
|
+
appender,
|
|
228
|
+
"date",
|
|
229
|
+
() => dateFromObject(date),
|
|
230
|
+
(p, v) => shim.dbs_append_date(p, v),
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export function append_time(appender: Appender, time: Time): void {
|
|
235
|
+
appendStruct(
|
|
236
|
+
appender,
|
|
237
|
+
"time",
|
|
238
|
+
() => timeFromObject(time),
|
|
239
|
+
(p, v) => shim.dbs_append_time(p, v),
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function append_timestamp(appender: Appender, timestamp: Timestamp): void {
|
|
244
|
+
appendStruct(
|
|
245
|
+
appender,
|
|
246
|
+
"timestamp",
|
|
247
|
+
() => timestampFromObject(timestamp),
|
|
248
|
+
(p, v) => shim.dbs_append_timestamp(p, v),
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export function append_interval(appender: Appender, interval: Interval): void {
|
|
253
|
+
appendStruct(
|
|
254
|
+
appender,
|
|
255
|
+
"interval",
|
|
256
|
+
() => intervalFromObject(interval),
|
|
257
|
+
(p, v) => shim.dbs_append_interval(p, v),
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export function append_varchar(appender: Appender, varchar: string): void {
|
|
262
|
+
const ptr = unwrap(appender, "appender");
|
|
263
|
+
const { bytes, length } = utf8(expectString(varchar));
|
|
264
|
+
check(ptr, duckdb.duckdb_append_varchar_length(ptr, bytes, length));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function append_blob(appender: Appender, data: Uint8Array): void {
|
|
268
|
+
const ptr = unwrap(appender, "appender");
|
|
269
|
+
if (!ArrayBuffer.isView(data) || data instanceof DataView) throw new Error("Invalid argument");
|
|
270
|
+
const bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
271
|
+
// A zero-length view still needs a valid address; DuckDB reads none of it.
|
|
272
|
+
check(ptr, duckdb.duckdb_append_blob(ptr, bytes.byteLength === 0 ? new Uint8Array(1) : bytes, bytes.byteLength));
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function append_null(appender: Appender): void {
|
|
276
|
+
const ptr = unwrap(appender, "appender");
|
|
277
|
+
check(ptr, duckdb.duckdb_append_null(ptr));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export function append_value(appender: Appender, value: Value): void {
|
|
281
|
+
const ptr = unwrap(appender, "appender");
|
|
282
|
+
check(ptr, duckdb.duckdb_append_value(ptr, unwrap(value, "value")));
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export function append_data_chunk(appender: Appender, chunk: DataChunk): void {
|
|
286
|
+
const ptr = unwrap(appender, "appender");
|
|
287
|
+
check(ptr, duckdb.duckdb_append_data_chunk(ptr, unwrap(chunk, "data chunk")));
|
|
288
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Data chunk functions of the @duckdb/node-bindings contract. Semantics and
|
|
2
|
+
// error text follow the official binding (bindings/src/duckdb_node_bindings.cpp
|
|
3
|
+
// at the vendored tag).
|
|
4
|
+
import type { Pointer } from "bun:ffi";
|
|
5
|
+
import type { DataChunk, LogicalType, Vector } from "../generated/contract.ts";
|
|
6
|
+
import { expectArray, throwIndexOutOfRange, uint32FromNumber } from "../runtime/convert.ts";
|
|
7
|
+
import { type Handle, handleOf, unwrap } from "../runtime/handle.ts";
|
|
8
|
+
import { borrow, own } from "../runtime/kinds.ts";
|
|
9
|
+
import { duckdb } from "../runtime/native.ts";
|
|
10
|
+
import { derived } from "../runtime/scope.ts";
|
|
11
|
+
|
|
12
|
+
function asHandle<T>(handle: Handle): T {
|
|
13
|
+
return handle as unknown as T;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function create_data_chunk(logical_types: readonly LogicalType[]): DataChunk {
|
|
17
|
+
const array = expectArray(logical_types);
|
|
18
|
+
const count = array.length;
|
|
19
|
+
// duckdb_create_data_chunk needs a valid array pointer even for zero columns.
|
|
20
|
+
const types = new BigUint64Array(Math.max(count, 1));
|
|
21
|
+
for (let i = 0; i < count; i++) types[i] = BigInt(unwrap(array[i], "logical type") ?? 0);
|
|
22
|
+
const chunk = duckdb.duckdb_create_data_chunk(types, count) as Pointer | null;
|
|
23
|
+
// DuckDB returns null for a column type it will not accept (ANY, for one)
|
|
24
|
+
// rather than reporting the refusal.
|
|
25
|
+
if (chunk === null) {
|
|
26
|
+
throw new Error("Failed to create data chunk. One or more column types are not supported.");
|
|
27
|
+
}
|
|
28
|
+
return asHandle(own("data chunk", chunk));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function data_chunk_reset(chunk: DataChunk): void {
|
|
32
|
+
duckdb.duckdb_data_chunk_reset(unwrap(chunk, "data chunk"));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function data_chunk_get_column_count(chunk: DataChunk): number {
|
|
36
|
+
return Number(duckdb.duckdb_data_chunk_get_column_count(unwrap(chunk, "data chunk")));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function data_chunk_get_vector(chunk: DataChunk, column_index: number): Vector {
|
|
40
|
+
const handle = handleOf(chunk, "data chunk");
|
|
41
|
+
const ptr = handle.ptr;
|
|
42
|
+
const index = uint32FromNumber(column_index);
|
|
43
|
+
const vector = duckdb.duckdb_data_chunk_get_vector(ptr, index) as Pointer | null;
|
|
44
|
+
if (vector === null) {
|
|
45
|
+
throwIndexOutOfRange(index, Number(duckdb.duckdb_data_chunk_get_column_count(ptr)), "column");
|
|
46
|
+
}
|
|
47
|
+
// The vector belongs to the chunk, which the handle keeps alive.
|
|
48
|
+
return asHandle(derived(handle, borrow("vector", vector, handle)));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function data_chunk_get_size(chunk: DataChunk): number {
|
|
52
|
+
return Number(duckdb.duckdb_data_chunk_get_size(unwrap(chunk, "data chunk")));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function data_chunk_set_size(chunk: DataChunk, size: number): void {
|
|
56
|
+
const ptr = unwrap(chunk, "data chunk");
|
|
57
|
+
duckdb.duckdb_data_chunk_set_size(ptr, uint32FromNumber(size));
|
|
58
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// Instance cache, database, config, connection, client context and catalog
|
|
2
|
+
// functions of the @duckdb/node-bindings contract. Semantics and error text
|
|
3
|
+
// follow the official binding (bindings/src/duckdb_node_bindings.cpp and
|
|
4
|
+
// promise_workers.h at the vendored tag).
|
|
5
|
+
import type { Pointer } from "bun:ffi";
|
|
6
|
+
import type {
|
|
7
|
+
Catalog,
|
|
8
|
+
CatalogEntry,
|
|
9
|
+
CatalogEntryType,
|
|
10
|
+
ClientContext,
|
|
11
|
+
Config,
|
|
12
|
+
ConfigFlag,
|
|
13
|
+
Connection,
|
|
14
|
+
Database,
|
|
15
|
+
InstanceCache,
|
|
16
|
+
QueryProgress,
|
|
17
|
+
Value,
|
|
18
|
+
} from "../generated/contract.ts";
|
|
19
|
+
import { expectBoolean, expectString, integerFromNumber, uint32FromNumber } from "../runtime/convert.ts";
|
|
20
|
+
import { jobOut0, runJob } from "../runtime/dispatch.ts";
|
|
21
|
+
import { type Handle, handleOf, unwrap } from "../runtime/handle.ts";
|
|
22
|
+
import { own } from "../runtime/kinds.ts";
|
|
23
|
+
import { cstr, decode, readCString, slot, slotValue, structBuffer, utf8 } from "../runtime/marshal.ts";
|
|
24
|
+
import { duckdb, shim } from "../runtime/native.ts";
|
|
25
|
+
import { RingOp, record } from "../runtime/ring.ts";
|
|
26
|
+
import { callContext } from "../runtime/trace.ts";
|
|
27
|
+
|
|
28
|
+
/** The `duckdb_api` value the official binding sets on every config it creates. */
|
|
29
|
+
const DEFAULT_DUCKDB_API = "node-neo-bindings";
|
|
30
|
+
|
|
31
|
+
function asHandle<T>(handle: Handle): T {
|
|
32
|
+
return handle as unknown as T;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function databaseFrom(job: Pointer): Database {
|
|
36
|
+
return asHandle<Database>(own("database", jobOut0(job) as Pointer));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// --- instance cache and open ---------------------------------------------------------
|
|
40
|
+
|
|
41
|
+
export function create_instance_cache(): InstanceCache {
|
|
42
|
+
return asHandle(own("instance cache", duckdb.duckdb_create_instance_cache() as Pointer));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// The official binding's async workers read the path before the handles.
|
|
46
|
+
|
|
47
|
+
export function get_or_create_from_cache(cache: InstanceCache, path?: string, config?: Config): Promise<Database> {
|
|
48
|
+
const { bytes, length } = utf8(path === undefined ? "" : expectString(path));
|
|
49
|
+
const cacheHandle = handleOf(cache, "instance cache");
|
|
50
|
+
const configHandle = config === undefined ? undefined : handleOf(config, "config");
|
|
51
|
+
const handles = configHandle ? [cacheHandle, configHandle] : [cacheHandle];
|
|
52
|
+
return runJob(
|
|
53
|
+
callContext("get_or_create_from_cache"),
|
|
54
|
+
handles,
|
|
55
|
+
() =>
|
|
56
|
+
shim.dbs_job_get_or_create_from_cache(
|
|
57
|
+
cacheHandle.ptr,
|
|
58
|
+
bytes,
|
|
59
|
+
length,
|
|
60
|
+
path !== undefined,
|
|
61
|
+
configHandle?.ptr ?? null,
|
|
62
|
+
) as Pointer | null,
|
|
63
|
+
databaseFrom,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function open(path?: string, config?: Config): Promise<Database> {
|
|
68
|
+
const { bytes, length } = utf8(path === undefined ? "" : expectString(path));
|
|
69
|
+
const configHandle = config === undefined ? undefined : handleOf(config, "config");
|
|
70
|
+
return runJob(
|
|
71
|
+
callContext("open"),
|
|
72
|
+
configHandle ? [configHandle] : [],
|
|
73
|
+
() => shim.dbs_job_open(bytes, length, path !== undefined, configHandle?.ptr ?? null) as Pointer | null,
|
|
74
|
+
databaseFrom,
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function close_sync(database: Database): void {
|
|
79
|
+
const handle = handleOf(database, "database");
|
|
80
|
+
record(RingOp.close, handle.ptr);
|
|
81
|
+
handle.requestDestroy();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function library_version(): string {
|
|
85
|
+
return readCString(duckdb.duckdb_library_version() as Pointer) ?? "";
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// --- config -------------------------------------------------------------------------
|
|
89
|
+
|
|
90
|
+
export function create_config(): Config {
|
|
91
|
+
const out = slot();
|
|
92
|
+
if (duckdb.duckdb_create_config(out)) {
|
|
93
|
+
duckdb.duckdb_destroy_config(out);
|
|
94
|
+
throw new Error("Failed to create config");
|
|
95
|
+
}
|
|
96
|
+
const config = own("config", slotValue(out) as Pointer);
|
|
97
|
+
if (duckdb.duckdb_set_config(config.ptr, cstr("duckdb_api"), cstr(DEFAULT_DUCKDB_API))) {
|
|
98
|
+
throw new Error("Failed to set duckdb_api");
|
|
99
|
+
}
|
|
100
|
+
return asHandle(config);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function config_count(): number {
|
|
104
|
+
return Number(duckdb.duckdb_config_count());
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function get_config_flag(index: number): ConfigFlag {
|
|
108
|
+
// Read as Number::Uint32Value, as the official binding does.
|
|
109
|
+
const flag = uint32FromNumber(index);
|
|
110
|
+
const name = slot();
|
|
111
|
+
const description = slot();
|
|
112
|
+
if (duckdb.duckdb_get_config_flag(flag, name, description)) throw new Error("Config option not found");
|
|
113
|
+
return { name: readCString(slotValue(name)) ?? "", description: readCString(slotValue(description)) ?? "" };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function set_config(config: Config, name: string, option: string): void {
|
|
117
|
+
const ptr = unwrap(config, "config");
|
|
118
|
+
if (duckdb.duckdb_set_config(ptr, cstr(expectString(name)), cstr(expectString(option)))) {
|
|
119
|
+
throw new Error("Failed to set config");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// --- connection ---------------------------------------------------------------------
|
|
124
|
+
|
|
125
|
+
export function connect(database: Database): Promise<Connection> {
|
|
126
|
+
const handle = handleOf(database, "database");
|
|
127
|
+
return runJob(
|
|
128
|
+
callContext("connect"),
|
|
129
|
+
[handle],
|
|
130
|
+
() => shim.dbs_job_connect(handle.destroyRequested ? null : handle.ptr) as Pointer | null,
|
|
131
|
+
(job) => asHandle<Connection>(own("connection", jobOut0(job) as Pointer)),
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function interrupt(connection: Connection): void {
|
|
136
|
+
const ptr = unwrap(connection, "connection");
|
|
137
|
+
record(RingOp.interrupt, ptr);
|
|
138
|
+
duckdb.duckdb_interrupt(ptr);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function query_progress(connection: Connection): QueryProgress {
|
|
142
|
+
const out = structBuffer("query_progress_type");
|
|
143
|
+
shim.dbs_query_progress(unwrap(connection, "connection"), out);
|
|
144
|
+
return decode<QueryProgress>("query_progress_type", out);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function disconnect_sync(connection: Connection): void {
|
|
148
|
+
const handle = handleOf(connection, "connection");
|
|
149
|
+
record(RingOp.disconnect, handle.ptr);
|
|
150
|
+
handle.requestDestroy();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function connection_get_client_context(connection: Connection): ClientContext {
|
|
154
|
+
const out = slot();
|
|
155
|
+
duckdb.duckdb_connection_get_client_context(unwrap(connection, "connection"), out);
|
|
156
|
+
const context = slotValue(out);
|
|
157
|
+
if (context === null) throw new Error("Failed to get client context");
|
|
158
|
+
return asHandle(own("client context", context));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function client_context_get_connection_id(client_context: ClientContext): number {
|
|
162
|
+
return Number(duckdb.duckdb_client_context_get_connection_id(unwrap(client_context, "client context")));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function get_table_names(connection: Connection, query: string, qualified: boolean): Value {
|
|
166
|
+
const ptr = unwrap(connection, "connection");
|
|
167
|
+
const text = cstr(expectString(query));
|
|
168
|
+
const value = duckdb.duckdb_get_table_names(ptr, text, expectBoolean(qualified)) as Pointer;
|
|
169
|
+
return asHandle(own("value", value));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// --- catalog ------------------------------------------------------------------------
|
|
173
|
+
|
|
174
|
+
/** DUCKDB_CATALOG_ENTRY_TYPE_DATABASE, the highest catalog entry type. */
|
|
175
|
+
const CATALOG_ENTRY_TYPE_DATABASE = 9;
|
|
176
|
+
|
|
177
|
+
/** Entry types the built-in duckdb catalog cannot look up, by duckdb_catalog_entry_type value. */
|
|
178
|
+
const UNSUPPORTED_DUCKDB_CATALOG_ENTRY_TYPES: Readonly<Record<number, string>> = {
|
|
179
|
+
0: "INVALID",
|
|
180
|
+
2: "SCHEMA",
|
|
181
|
+
5: "PREPARED_STATEMENT",
|
|
182
|
+
9: "DATABASE",
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export function client_context_get_catalog(context: ClientContext, catalog_name: string): Catalog | null {
|
|
186
|
+
const ptr = unwrap(context, "client context");
|
|
187
|
+
const catalog = duckdb.duckdb_client_context_get_catalog(ptr, cstr(expectString(catalog_name))) as Pointer | null;
|
|
188
|
+
return catalog === null ? null : asHandle(own("catalog", catalog));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function catalog_get_type_name(catalog: Catalog): string {
|
|
192
|
+
return readCString(duckdb.duckdb_catalog_get_type_name(unwrap(catalog, "catalog")) as Pointer | null) ?? "";
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function catalog_get_entry(
|
|
196
|
+
catalog: Catalog,
|
|
197
|
+
context: ClientContext,
|
|
198
|
+
entry_type: CatalogEntryType,
|
|
199
|
+
schema_name: string,
|
|
200
|
+
entry_name: string,
|
|
201
|
+
): CatalogEntry | null {
|
|
202
|
+
const catalogPtr = unwrap(catalog, "catalog");
|
|
203
|
+
const contextPtr = unwrap(context, "client context");
|
|
204
|
+
const type = integerFromNumber(entry_type, "uint32", "entry_type");
|
|
205
|
+
if (type > CATALOG_ENTRY_TYPE_DATABASE) throw new RangeError("Invalid catalog entry type");
|
|
206
|
+
const schema = expectString(schema_name);
|
|
207
|
+
const name = expectString(entry_name);
|
|
208
|
+
if (schema.includes("\0") || name.includes("\0")) {
|
|
209
|
+
throw new Error("Catalog entry names must not contain null bytes");
|
|
210
|
+
}
|
|
211
|
+
// Extension catalogs may support different lookup categories.
|
|
212
|
+
const unsupported = UNSUPPORTED_DUCKDB_CATALOG_ENTRY_TYPES[type];
|
|
213
|
+
if (unsupported && catalog_get_type_name(catalog) === "duckdb") {
|
|
214
|
+
throw new Error(`Catalog entry type ${unsupported} is not supported by duckdb catalog lookups`);
|
|
215
|
+
}
|
|
216
|
+
const entry = duckdb.duckdb_catalog_get_entry(
|
|
217
|
+
catalogPtr,
|
|
218
|
+
contextPtr,
|
|
219
|
+
type,
|
|
220
|
+
cstr(schema),
|
|
221
|
+
cstr(name),
|
|
222
|
+
) as Pointer | null;
|
|
223
|
+
return entry === null ? null : asHandle(own("catalog entry", entry));
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function catalog_entry_get_type(entry: CatalogEntry): CatalogEntryType {
|
|
227
|
+
return duckdb.duckdb_catalog_entry_get_type(unwrap(entry, "catalog entry")) as CatalogEntryType;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function catalog_entry_get_name(entry: CatalogEntry): string {
|
|
231
|
+
return readCString(duckdb.duckdb_catalog_entry_get_name(unwrap(entry, "catalog entry")) as Pointer | null) ?? "";
|
|
232
|
+
}
|