@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,28 @@
|
|
|
1
|
+
import duckdb, { TimestampSeconds } from "../../../../src/bindings/index.ts";
|
|
2
|
+
import { getDuckDBTimestampStringFromSeconds } from '../conversion/dateTimeStringConversion';
|
|
3
|
+
|
|
4
|
+
export class DuckDBTimestampSecondsValue implements TimestampSeconds {
|
|
5
|
+
public readonly seconds: bigint;
|
|
6
|
+
|
|
7
|
+
public constructor(seconds: bigint) {
|
|
8
|
+
this.seconds = seconds;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public get isFinite(): boolean {
|
|
12
|
+
return duckdb.is_finite_timestamp_s(this);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public toString(): string {
|
|
16
|
+
return getDuckDBTimestampStringFromSeconds(this.seconds);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public static readonly Epoch = new DuckDBTimestampSecondsValue(0n);
|
|
20
|
+
public static readonly Max = new DuckDBTimestampSecondsValue( 9223372036854n);
|
|
21
|
+
public static readonly Min = new DuckDBTimestampSecondsValue(-9223372022400n); // from test_all_types() select epoch(timestamp_s)::bigint;
|
|
22
|
+
public static readonly PosInf = new DuckDBTimestampSecondsValue(2n ** 63n - 1n);
|
|
23
|
+
public static readonly NegInf = new DuckDBTimestampSecondsValue(-(2n ** 63n - 1n));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function timestampSecondsValue(seconds: bigint): DuckDBTimestampSecondsValue {
|
|
27
|
+
return new DuckDBTimestampSecondsValue(seconds);
|
|
28
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import duckdb, { TimestampNanoseconds } from "../../../../src/bindings/index.ts";
|
|
2
|
+
import { getDuckDBTimestampStringFromNanoseconds } from '../conversion/dateTimeStringConversion';
|
|
3
|
+
import { DuckDBTimestampNanosecondsValue } from './DuckDBTimestampNanosecondsValue';
|
|
4
|
+
import { DuckDBTimestampTZValue } from './DuckDBTimestampTZValue';
|
|
5
|
+
|
|
6
|
+
export class DuckDBTimestampTZNanosecondsValue implements TimestampNanoseconds {
|
|
7
|
+
public readonly nanos: bigint;
|
|
8
|
+
|
|
9
|
+
public constructor(nanos: bigint) {
|
|
10
|
+
this.nanos = nanos;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public get isFinite(): boolean {
|
|
14
|
+
return duckdb.is_finite_timestamp_ns(this);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Formats in the time zone set by `DuckDBTimestampTZValue.timezoneOffsetInMinutes`. */
|
|
18
|
+
public toString(): string {
|
|
19
|
+
return getDuckDBTimestampStringFromNanoseconds(
|
|
20
|
+
this.nanos,
|
|
21
|
+
DuckDBTimestampTZValue.timezoneOffsetInMinutes
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public static readonly Epoch = new DuckDBTimestampTZNanosecondsValue(0n);
|
|
26
|
+
public static readonly Max = new DuckDBTimestampTZNanosecondsValue(
|
|
27
|
+
DuckDBTimestampNanosecondsValue.Max.nanos
|
|
28
|
+
);
|
|
29
|
+
public static readonly Min = new DuckDBTimestampTZNanosecondsValue(
|
|
30
|
+
DuckDBTimestampNanosecondsValue.Min.nanos
|
|
31
|
+
);
|
|
32
|
+
public static readonly PosInf = new DuckDBTimestampTZNanosecondsValue(
|
|
33
|
+
DuckDBTimestampNanosecondsValue.PosInf.nanos
|
|
34
|
+
);
|
|
35
|
+
public static readonly NegInf = new DuckDBTimestampTZNanosecondsValue(
|
|
36
|
+
DuckDBTimestampNanosecondsValue.NegInf.nanos
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function timestampTZNanosValue(
|
|
41
|
+
nanos: bigint
|
|
42
|
+
): DuckDBTimestampTZNanosecondsValue {
|
|
43
|
+
return new DuckDBTimestampTZNanosecondsValue(nanos);
|
|
44
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import duckdb, { Timestamp, TimestampParts } from "../../../../src/bindings/index.ts";
|
|
2
|
+
import { getDuckDBTimestampStringFromMicroseconds } from '../conversion/dateTimeStringConversion';
|
|
3
|
+
import { DuckDBTimestampValue } from './DuckDBTimestampValue';
|
|
4
|
+
|
|
5
|
+
export class DuckDBTimestampTZValue implements Timestamp {
|
|
6
|
+
public static timezoneOffsetInMinutes: number =
|
|
7
|
+
-new Date().getTimezoneOffset();
|
|
8
|
+
|
|
9
|
+
public readonly micros: bigint;
|
|
10
|
+
|
|
11
|
+
public constructor(micros: bigint) {
|
|
12
|
+
this.micros = micros;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public get isFinite(): boolean {
|
|
16
|
+
return duckdb.is_finite_timestamp(this);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public toString(): string {
|
|
20
|
+
return getDuckDBTimestampStringFromMicroseconds(
|
|
21
|
+
this.micros,
|
|
22
|
+
DuckDBTimestampTZValue.timezoneOffsetInMinutes
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public toParts(): TimestampParts {
|
|
27
|
+
return duckdb.from_timestamp(this);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public static fromParts(parts: TimestampParts): DuckDBTimestampTZValue {
|
|
31
|
+
return new DuckDBTimestampTZValue(duckdb.to_timestamp(parts).micros);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public static readonly Epoch = new DuckDBTimestampTZValue(0n);
|
|
35
|
+
public static readonly Max = new DuckDBTimestampTZValue(
|
|
36
|
+
DuckDBTimestampValue.Max.micros
|
|
37
|
+
);
|
|
38
|
+
public static readonly Min = new DuckDBTimestampTZValue(
|
|
39
|
+
DuckDBTimestampValue.Min.micros
|
|
40
|
+
);
|
|
41
|
+
public static readonly PosInf = new DuckDBTimestampTZValue(
|
|
42
|
+
DuckDBTimestampValue.PosInf.micros
|
|
43
|
+
);
|
|
44
|
+
public static readonly NegInf = new DuckDBTimestampTZValue(
|
|
45
|
+
DuckDBTimestampValue.NegInf.micros
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function timestampTZValue(microsOrParts: bigint | TimestampParts): DuckDBTimestampTZValue {
|
|
50
|
+
if (typeof microsOrParts === 'bigint') {
|
|
51
|
+
return new DuckDBTimestampTZValue(microsOrParts);
|
|
52
|
+
}
|
|
53
|
+
return DuckDBTimestampTZValue.fromParts(microsOrParts);
|
|
54
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import duckdb, { Timestamp, TimestampParts } from "../../../../src/bindings/index.ts";
|
|
2
|
+
import { getDuckDBTimestampStringFromMicroseconds } from '../conversion/dateTimeStringConversion';
|
|
3
|
+
import { DuckDBTimestampMillisecondsValue } from './DuckDBTimestampMillisecondsValue';
|
|
4
|
+
|
|
5
|
+
export type { TimestampParts };
|
|
6
|
+
|
|
7
|
+
export class DuckDBTimestampValue implements Timestamp {
|
|
8
|
+
public readonly micros: bigint;
|
|
9
|
+
|
|
10
|
+
public constructor(micros: bigint) {
|
|
11
|
+
this.micros = micros;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public get isFinite(): boolean {
|
|
15
|
+
return duckdb.is_finite_timestamp(this);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public toString(): string {
|
|
19
|
+
return getDuckDBTimestampStringFromMicroseconds(this.micros);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public toParts(): TimestampParts {
|
|
23
|
+
return duckdb.from_timestamp(this);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public static fromParts(parts: TimestampParts): DuckDBTimestampValue {
|
|
27
|
+
return new DuckDBTimestampValue(duckdb.to_timestamp(parts).micros);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public static readonly Epoch = new DuckDBTimestampValue(0n);
|
|
31
|
+
public static readonly Max = new DuckDBTimestampValue(2n ** 63n - 2n);
|
|
32
|
+
public static readonly Min = new DuckDBTimestampValue(DuckDBTimestampMillisecondsValue.Min.millis * 1000n);
|
|
33
|
+
public static readonly PosInf = new DuckDBTimestampValue(2n ** 63n - 1n);
|
|
34
|
+
public static readonly NegInf = new DuckDBTimestampValue(-(2n ** 63n - 1n));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type DuckDBTimestampMicrosecondsValue = DuckDBTimestampValue;
|
|
38
|
+
export const DuckDBTimestampMicrosecondsValue = DuckDBTimestampValue;
|
|
39
|
+
|
|
40
|
+
export function timestampValue(microsOrParts: bigint | TimestampParts): DuckDBTimestampValue {
|
|
41
|
+
if (typeof microsOrParts === 'bigint') {
|
|
42
|
+
return new DuckDBTimestampValue(microsOrParts);
|
|
43
|
+
}
|
|
44
|
+
return DuckDBTimestampValue.fromParts(microsOrParts);
|
|
45
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { displayStringForDuckDBValue } from '../conversion/displayStringForDuckDBValue';
|
|
2
|
+
import { DuckDBValue } from './DuckDBValue';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A value of a tuple type: an unnamed STRUCT, such as `(1, 'a')` or
|
|
6
|
+
* `row(1, 'a')`. Its items are in entry order.
|
|
7
|
+
*/
|
|
8
|
+
export class DuckDBTupleValue {
|
|
9
|
+
public readonly items: readonly DuckDBValue[];
|
|
10
|
+
|
|
11
|
+
public constructor(items: readonly DuckDBValue[]) {
|
|
12
|
+
this.items = items;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public toString(): string {
|
|
16
|
+
return `(${this.items.map(displayStringForDuckDBValue).join(', ')})`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function tupleValue(items: readonly DuckDBValue[]): DuckDBTupleValue {
|
|
21
|
+
return new DuckDBTupleValue(items);
|
|
22
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export class DuckDBUUIDValue {
|
|
2
|
+
public readonly hugeint: bigint;
|
|
3
|
+
|
|
4
|
+
private constructor(hugeint: bigint) {
|
|
5
|
+
this.hugeint = hugeint;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Return the UUID as an unsigned 128-bit integer in a JS BigInt. */
|
|
9
|
+
public toUint128(): bigint {
|
|
10
|
+
// UUID values are stored with their MSB flipped so their numeric ordering matches their string ordering.
|
|
11
|
+
return (this.hugeint ^ 0x80000000000000000000000000000000n) & 0xffffffffffffffffffffffffffffffffn;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public toString(): string {
|
|
15
|
+
// Prepend with a (hex) 1 before converting to a hex string.
|
|
16
|
+
// This ensures the trailing 32 characters are the hex digits we want, left padded with zeros as needed.
|
|
17
|
+
const hex = (this.toUint128() | 0x100000000000000000000000000000000n).toString(16);
|
|
18
|
+
return `${hex.substring(1, 9)}-${hex.substring(9, 13)}-${hex.substring(13, 17)}-${hex.substring(17, 21)}-${hex.substring(21, 33)}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Create a DuckDBUUIDValue from an unsigned 128-bit integer in a JS BigInt. */
|
|
22
|
+
public static fromUint128(uint128: bigint): DuckDBUUIDValue {
|
|
23
|
+
// Convert the unsigned 128-bit input into DuckDB's storage form: MSB
|
|
24
|
+
// flipped (so numeric ordering matches string ordering) and held as a
|
|
25
|
+
// signed int128 (the same form `DuckDBUUIDVector` produces via
|
|
26
|
+
// `getInt128`).
|
|
27
|
+
return new DuckDBUUIDValue(
|
|
28
|
+
BigInt.asIntN(128, uint128 ^ 0x80000000000000000000000000000000n),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Create a DuckDBUUIDValue from a HUGEINT as stored by DuckDB.
|
|
34
|
+
*
|
|
35
|
+
* UUID values are stored with their MSB flipped so their numeric ordering matches their string ordering.
|
|
36
|
+
*/
|
|
37
|
+
public static fromStoredHugeInt(hugeint: bigint): DuckDBUUIDValue {
|
|
38
|
+
return new DuckDBUUIDValue(hugeint);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public static readonly Max = new DuckDBUUIDValue(2n ** 127n - 1n); // 7fffffffffffffffffffffffffffffff
|
|
42
|
+
public static readonly Min = new DuckDBUUIDValue(-(2n ** 127n)); // 80000000000000000000000000000000
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Create a DuckDBUUIDValue from an unsigned 128-bit integer in a JS BigInt. */
|
|
46
|
+
export function uuidValue(uint128: bigint): DuckDBUUIDValue {
|
|
47
|
+
return DuckDBUUIDValue.fromUint128(uint128);
|
|
48
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DuckDBValue } from './DuckDBValue';
|
|
2
|
+
|
|
3
|
+
export class DuckDBUnionValue {
|
|
4
|
+
public readonly tag: string;
|
|
5
|
+
public readonly value: DuckDBValue;
|
|
6
|
+
|
|
7
|
+
public constructor(tag: string, value: DuckDBValue) {
|
|
8
|
+
this.tag = tag;
|
|
9
|
+
this.value = value;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public toString(): string {
|
|
13
|
+
if (this.value == null) {
|
|
14
|
+
return 'NULL';
|
|
15
|
+
}
|
|
16
|
+
return this.value.toString();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function unionValue(tag: string, value: DuckDBValue): DuckDBUnionValue {
|
|
21
|
+
return new DuckDBUnionValue(tag, value);
|
|
22
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { DuckDBArrayValue } from './DuckDBArrayValue';
|
|
2
|
+
import { DuckDBBitValue } from './DuckDBBitValue';
|
|
3
|
+
import { DuckDBBlobValue } from './DuckDBBlobValue';
|
|
4
|
+
import { DuckDBDateValue } from './DuckDBDateValue';
|
|
5
|
+
import { DuckDBDecimalValue } from './DuckDBDecimalValue';
|
|
6
|
+
import { DuckDBGeometryValue } from './DuckDBGeometryValue';
|
|
7
|
+
import { DuckDBIntervalValue } from './DuckDBIntervalValue';
|
|
8
|
+
import { DuckDBListValue } from './DuckDBListValue';
|
|
9
|
+
import { DuckDBMapValue } from './DuckDBMapValue';
|
|
10
|
+
import { DuckDBStructValue } from './DuckDBStructValue';
|
|
11
|
+
import { DuckDBTimeNSValue } from './DuckDBTimeNSValue';
|
|
12
|
+
import { DuckDBTimestampMillisecondsValue } from './DuckDBTimestampMillisecondsValue';
|
|
13
|
+
import { DuckDBTimestampNanosecondsValue } from './DuckDBTimestampNanosecondsValue';
|
|
14
|
+
import { DuckDBTimestampSecondsValue } from './DuckDBTimestampSecondsValue';
|
|
15
|
+
import { DuckDBTimestampTZValue } from './DuckDBTimestampTZValue';
|
|
16
|
+
import { DuckDBTimestampTZNanosecondsValue } from './DuckDBTimestampTZNanosecondsValue';
|
|
17
|
+
import { DuckDBTimestampValue } from './DuckDBTimestampValue';
|
|
18
|
+
import { DuckDBTimeTZValue } from './DuckDBTimeTZValue';
|
|
19
|
+
import { DuckDBTimeValue } from './DuckDBTimeValue';
|
|
20
|
+
import { DuckDBTupleValue } from './DuckDBTupleValue';
|
|
21
|
+
import { DuckDBUnionValue } from './DuckDBUnionValue';
|
|
22
|
+
import { DuckDBUUIDValue } from './DuckDBUUIDValue';
|
|
23
|
+
import { DuckDBVariantValue } from './DuckDBVariantValue';
|
|
24
|
+
|
|
25
|
+
export type DuckDBValue =
|
|
26
|
+
| null
|
|
27
|
+
| boolean
|
|
28
|
+
| number
|
|
29
|
+
| bigint
|
|
30
|
+
| string
|
|
31
|
+
| DuckDBArrayValue
|
|
32
|
+
| DuckDBBitValue
|
|
33
|
+
| DuckDBBlobValue
|
|
34
|
+
| DuckDBDateValue
|
|
35
|
+
| DuckDBDecimalValue
|
|
36
|
+
| DuckDBGeometryValue
|
|
37
|
+
| DuckDBIntervalValue
|
|
38
|
+
| DuckDBListValue
|
|
39
|
+
| DuckDBMapValue
|
|
40
|
+
| DuckDBStructValue
|
|
41
|
+
| DuckDBTimestampMillisecondsValue
|
|
42
|
+
| DuckDBTimestampNanosecondsValue
|
|
43
|
+
| DuckDBTimestampSecondsValue
|
|
44
|
+
| DuckDBTimestampTZValue
|
|
45
|
+
| DuckDBTimestampTZNanosecondsValue
|
|
46
|
+
| DuckDBTimestampValue
|
|
47
|
+
| DuckDBTimeTZValue
|
|
48
|
+
| DuckDBTimeValue
|
|
49
|
+
| DuckDBTimeNSValue
|
|
50
|
+
| DuckDBTupleValue
|
|
51
|
+
| DuckDBUnionValue
|
|
52
|
+
| DuckDBUUIDValue
|
|
53
|
+
| DuckDBVariantValue;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { displayStringForDuckDBValue } from '../conversion/displayStringForDuckDBValue';
|
|
2
|
+
// Type-only import avoids a runtime cycle with ../DuckDBType, which itself
|
|
3
|
+
// pulls in the values barrel.
|
|
4
|
+
import type { DuckDBType } from '../DuckDBType';
|
|
5
|
+
import { DuckDBValue } from './DuckDBValue';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Wraps a single decoded VARIANT row value. The wrapper distinguishes a
|
|
9
|
+
* SQL-NULL row (returned as bare `null`) from an embedded `VARIANT_NULL`
|
|
10
|
+
* tag (returned as `new DuckDBVariantValue(null)`).
|
|
11
|
+
*
|
|
12
|
+
* The optional `type` records the exact DuckDB type of the inner value
|
|
13
|
+
* (recovered from the on-disk variant tag at decode time). The append /
|
|
14
|
+
* bind paths use it so heterogeneous content round-trips faithfully —
|
|
15
|
+
* `typeForValue` is a best-effort fallback when `type` is not provided.
|
|
16
|
+
*/
|
|
17
|
+
export class DuckDBVariantValue {
|
|
18
|
+
public readonly value: DuckDBValue;
|
|
19
|
+
public readonly type?: DuckDBType;
|
|
20
|
+
public constructor(value: DuckDBValue, type?: DuckDBType) {
|
|
21
|
+
this.value = value;
|
|
22
|
+
this.type = type;
|
|
23
|
+
}
|
|
24
|
+
public toString(): string {
|
|
25
|
+
return displayStringForDuckDBValue(this.value);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function variantValue(
|
|
30
|
+
value: DuckDBValue,
|
|
31
|
+
type?: DuckDBType,
|
|
32
|
+
): DuckDBVariantValue {
|
|
33
|
+
return new DuckDBVariantValue(value, type);
|
|
34
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export * from './DuckDBArrayValue';
|
|
2
|
+
export * from './DuckDBBitValue';
|
|
3
|
+
export * from './DuckDBBlobValue';
|
|
4
|
+
export * from './DuckDBDateValue';
|
|
5
|
+
export * from './DuckDBDecimalValue';
|
|
6
|
+
export * from './DuckDBGeometryValue';
|
|
7
|
+
export * from './DuckDBIntervalValue';
|
|
8
|
+
export * from './DuckDBListValue';
|
|
9
|
+
export * from './DuckDBMapValue';
|
|
10
|
+
export * from './DuckDBStructValue';
|
|
11
|
+
export * from './DuckDBTimeNSValue';
|
|
12
|
+
export * from './DuckDBTimestampMillisecondsValue';
|
|
13
|
+
export * from './DuckDBTimestampNanosecondsValue';
|
|
14
|
+
export * from './DuckDBTimestampSecondsValue';
|
|
15
|
+
export * from './DuckDBTimestampTZValue';
|
|
16
|
+
export * from './DuckDBTimestampTZNanosecondsValue';
|
|
17
|
+
export * from './DuckDBTimestampValue';
|
|
18
|
+
export * from './DuckDBTimeTZValue';
|
|
19
|
+
export * from './DuckDBTimeValue';
|
|
20
|
+
export * from './DuckDBTupleValue';
|
|
21
|
+
export * from './DuckDBUnionValue';
|
|
22
|
+
export * from './DuckDBUUIDValue';
|
|
23
|
+
export * from './DuckDBValue';
|
|
24
|
+
export * from './DuckDBVariantValue';
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import duckdb from "../../../../src/bindings/index.ts";
|
|
2
|
+
import {
|
|
3
|
+
DuckDBArrayType,
|
|
4
|
+
} from '../DuckDBType';
|
|
5
|
+
import {
|
|
6
|
+
DuckDBArrayValue,
|
|
7
|
+
} from '../values';
|
|
8
|
+
import { DuckDBVector } from './DuckDBVector';
|
|
9
|
+
import { DuckDBValidity } from './DuckDBValidity';
|
|
10
|
+
|
|
11
|
+
export class DuckDBArrayVector extends DuckDBVector<DuckDBArrayValue> {
|
|
12
|
+
private readonly arrayType: DuckDBArrayType;
|
|
13
|
+
private readonly validity: DuckDBValidity;
|
|
14
|
+
private readonly vector: duckdb.Vector;
|
|
15
|
+
private readonly childData: DuckDBVector;
|
|
16
|
+
private readonly _itemCount: number;
|
|
17
|
+
constructor(
|
|
18
|
+
arrayType: DuckDBArrayType,
|
|
19
|
+
validity: DuckDBValidity,
|
|
20
|
+
vector: duckdb.Vector,
|
|
21
|
+
childData: DuckDBVector,
|
|
22
|
+
itemCount: number
|
|
23
|
+
) {
|
|
24
|
+
super();
|
|
25
|
+
this.arrayType = arrayType;
|
|
26
|
+
this.validity = validity;
|
|
27
|
+
this.vector = vector;
|
|
28
|
+
this.childData = childData;
|
|
29
|
+
this._itemCount = itemCount;
|
|
30
|
+
}
|
|
31
|
+
static fromRawVector(
|
|
32
|
+
arrayType: DuckDBArrayType,
|
|
33
|
+
vector: duckdb.Vector,
|
|
34
|
+
itemCount: number
|
|
35
|
+
): DuckDBArrayVector {
|
|
36
|
+
const validity = DuckDBValidity.fromVector(vector, itemCount);
|
|
37
|
+
const child_vector = duckdb.array_vector_get_child(vector);
|
|
38
|
+
const childItemsPerArray =
|
|
39
|
+
DuckDBArrayVector.itemSize(arrayType) * arrayType.length;
|
|
40
|
+
const childData = DuckDBVector.create(
|
|
41
|
+
child_vector,
|
|
42
|
+
itemCount * childItemsPerArray,
|
|
43
|
+
arrayType.valueType
|
|
44
|
+
);
|
|
45
|
+
return new DuckDBArrayVector(
|
|
46
|
+
arrayType,
|
|
47
|
+
validity,
|
|
48
|
+
vector,
|
|
49
|
+
childData,
|
|
50
|
+
itemCount
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
private static itemSize(arrayType: DuckDBArrayType): number {
|
|
54
|
+
if (arrayType.valueType instanceof DuckDBArrayType) {
|
|
55
|
+
return DuckDBArrayVector.itemSize(arrayType.valueType);
|
|
56
|
+
} else {
|
|
57
|
+
return 1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
public override get type(): DuckDBArrayType {
|
|
61
|
+
return this.arrayType;
|
|
62
|
+
}
|
|
63
|
+
public override get itemCount(): number {
|
|
64
|
+
return this._itemCount;
|
|
65
|
+
}
|
|
66
|
+
public override getItem(itemIndex: number): DuckDBArrayValue | null {
|
|
67
|
+
if (!this.validity.itemValid(itemIndex)) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return new DuckDBArrayValue(
|
|
71
|
+
this.childData
|
|
72
|
+
.slice(itemIndex * this.arrayType.length, this.arrayType.length)
|
|
73
|
+
.toArray()
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
public override setItem(itemIndex: number, value: DuckDBArrayValue | null) {
|
|
77
|
+
if (value != null) {
|
|
78
|
+
const startIndex = itemIndex * this.arrayType.length;
|
|
79
|
+
for (let i = 0; i < this.arrayType.length; i++) {
|
|
80
|
+
this.childData.setItem(startIndex + i, value.items[i]);
|
|
81
|
+
}
|
|
82
|
+
this.validity.setItemValid(itemIndex, true);
|
|
83
|
+
} else {
|
|
84
|
+
const startIndex = itemIndex * this.arrayType.length;
|
|
85
|
+
for (let i = 0; i < this.arrayType.length; i++) {
|
|
86
|
+
this.childData.setItem(startIndex + i, null);
|
|
87
|
+
}
|
|
88
|
+
this.validity.setItemValid(itemIndex, false);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
public override flush() {
|
|
92
|
+
this.childData.flush();
|
|
93
|
+
this.validity.flush(this.vector);
|
|
94
|
+
}
|
|
95
|
+
public override slice(offset: number, length: number): DuckDBArrayVector {
|
|
96
|
+
return new DuckDBArrayVector(
|
|
97
|
+
this.arrayType,
|
|
98
|
+
this.validity.slice(offset, length),
|
|
99
|
+
this.vector,
|
|
100
|
+
this.childData.slice(
|
|
101
|
+
offset * this.arrayType.length,
|
|
102
|
+
length * this.arrayType.length
|
|
103
|
+
),
|
|
104
|
+
length
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import duckdb from "../../../../src/bindings/index.ts";
|
|
2
|
+
import {
|
|
3
|
+
DuckDBBigIntType,
|
|
4
|
+
} from '../DuckDBType';
|
|
5
|
+
import { DuckDBVector } from './DuckDBVector';
|
|
6
|
+
import { DuckDBValidity } from './DuckDBValidity';
|
|
7
|
+
import {
|
|
8
|
+
vectorData,
|
|
9
|
+
} from './dataAccessors';
|
|
10
|
+
|
|
11
|
+
export class DuckDBBigIntVector extends DuckDBVector<bigint> {
|
|
12
|
+
private readonly items: BigInt64Array;
|
|
13
|
+
private readonly validity: DuckDBValidity;
|
|
14
|
+
private readonly vector: duckdb.Vector;
|
|
15
|
+
constructor(
|
|
16
|
+
items: BigInt64Array,
|
|
17
|
+
validity: DuckDBValidity,
|
|
18
|
+
vector: duckdb.Vector
|
|
19
|
+
) {
|
|
20
|
+
super();
|
|
21
|
+
this.items = items;
|
|
22
|
+
this.validity = validity;
|
|
23
|
+
this.vector = vector;
|
|
24
|
+
}
|
|
25
|
+
static fromRawVector(
|
|
26
|
+
vector: duckdb.Vector,
|
|
27
|
+
itemCount: number
|
|
28
|
+
): DuckDBBigIntVector {
|
|
29
|
+
const data = vectorData(
|
|
30
|
+
vector,
|
|
31
|
+
itemCount * BigInt64Array.BYTES_PER_ELEMENT
|
|
32
|
+
);
|
|
33
|
+
const items = new BigInt64Array(data.buffer, data.byteOffset, itemCount);
|
|
34
|
+
const validity = DuckDBValidity.fromVector(vector, itemCount);
|
|
35
|
+
return new DuckDBBigIntVector(items, validity, vector);
|
|
36
|
+
}
|
|
37
|
+
public override get type(): DuckDBBigIntType {
|
|
38
|
+
return DuckDBBigIntType.instance;
|
|
39
|
+
}
|
|
40
|
+
public override get itemCount(): number {
|
|
41
|
+
return this.items.length;
|
|
42
|
+
}
|
|
43
|
+
public override getItem(itemIndex: number): bigint | null {
|
|
44
|
+
return this.validity.itemValid(itemIndex) ? this.items[itemIndex] : null;
|
|
45
|
+
}
|
|
46
|
+
public override setItem(itemIndex: number, value: bigint | null) {
|
|
47
|
+
if (value != null) {
|
|
48
|
+
// Checked inline for bulk-write throughput; see dataAccessors.ts.
|
|
49
|
+
if (BigInt.asIntN(64, value) !== value) {
|
|
50
|
+
throw new Error(`bigint out of int64 range`);
|
|
51
|
+
}
|
|
52
|
+
this.items[itemIndex] = value;
|
|
53
|
+
this.validity.setItemValid(itemIndex, true);
|
|
54
|
+
} else {
|
|
55
|
+
this.validity.setItemValid(itemIndex, false);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
public override flush() {
|
|
59
|
+
duckdb.copy_data_to_vector(
|
|
60
|
+
this.vector,
|
|
61
|
+
0,
|
|
62
|
+
this.items.buffer as ArrayBuffer,
|
|
63
|
+
this.items.byteOffset,
|
|
64
|
+
this.items.byteLength
|
|
65
|
+
);
|
|
66
|
+
this.validity.flush(this.vector);
|
|
67
|
+
}
|
|
68
|
+
public override slice(offset: number, length: number): DuckDBBigIntVector {
|
|
69
|
+
return new DuckDBBigIntVector(
|
|
70
|
+
this.items.slice(offset, offset + length),
|
|
71
|
+
this.validity.slice(offset, length),
|
|
72
|
+
this.vector
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import duckdb from "../../../../src/bindings/index.ts";
|
|
2
|
+
import {
|
|
3
|
+
DuckDBBigNumType,
|
|
4
|
+
} from '../DuckDBType';
|
|
5
|
+
import { DuckDBVector } from './DuckDBVector';
|
|
6
|
+
import { DuckDBValidity } from './DuckDBValidity';
|
|
7
|
+
import {
|
|
8
|
+
getBigNumFromBytes,
|
|
9
|
+
getBytesFromBigNum,
|
|
10
|
+
getStringBytes,
|
|
11
|
+
vectorData,
|
|
12
|
+
} from './dataAccessors';
|
|
13
|
+
|
|
14
|
+
export class DuckDBBigNumVector extends DuckDBVector<bigint> {
|
|
15
|
+
private readonly dataView: DataView;
|
|
16
|
+
private readonly validity: DuckDBValidity;
|
|
17
|
+
private readonly vector: duckdb.Vector;
|
|
18
|
+
private readonly itemOffset: number;
|
|
19
|
+
private readonly _itemCount: number;
|
|
20
|
+
private readonly itemCache: (bigint | null | undefined)[];
|
|
21
|
+
private readonly itemCacheDirty: boolean[];
|
|
22
|
+
constructor(
|
|
23
|
+
dataView: DataView,
|
|
24
|
+
validity: DuckDBValidity,
|
|
25
|
+
vector: duckdb.Vector,
|
|
26
|
+
itemOffset: number,
|
|
27
|
+
itemCount: number
|
|
28
|
+
) {
|
|
29
|
+
super();
|
|
30
|
+
this.dataView = dataView;
|
|
31
|
+
this.validity = validity;
|
|
32
|
+
this.vector = vector;
|
|
33
|
+
this.itemOffset = itemOffset;
|
|
34
|
+
this._itemCount = itemCount;
|
|
35
|
+
this.itemCache = [];
|
|
36
|
+
this.itemCacheDirty = [];
|
|
37
|
+
}
|
|
38
|
+
static fromRawVector(
|
|
39
|
+
vector: duckdb.Vector,
|
|
40
|
+
itemCount: number
|
|
41
|
+
): DuckDBBigNumVector {
|
|
42
|
+
const data = vectorData(vector, itemCount * 16);
|
|
43
|
+
const dataView = new DataView(
|
|
44
|
+
data.buffer,
|
|
45
|
+
data.byteOffset,
|
|
46
|
+
data.byteLength
|
|
47
|
+
);
|
|
48
|
+
const validity = DuckDBValidity.fromVector(vector, itemCount);
|
|
49
|
+
return new DuckDBBigNumVector(dataView, validity, vector, 0, itemCount);
|
|
50
|
+
}
|
|
51
|
+
public override get type(): DuckDBBigNumType {
|
|
52
|
+
return DuckDBBigNumType.instance;
|
|
53
|
+
}
|
|
54
|
+
public override get itemCount(): number {
|
|
55
|
+
return this._itemCount;
|
|
56
|
+
}
|
|
57
|
+
public override getItem(itemIndex: number): bigint | null {
|
|
58
|
+
if (!this.validity.itemValid(itemIndex)) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const bytes = getStringBytes(this.dataView, itemIndex * 16);
|
|
62
|
+
return bytes ? getBigNumFromBytes(bytes) : null;
|
|
63
|
+
}
|
|
64
|
+
public override setItem(itemIndex: number, value: bigint | null) {
|
|
65
|
+
this.itemCache[itemIndex] = value;
|
|
66
|
+
this.validity.setItemValid(itemIndex, value != null);
|
|
67
|
+
this.itemCacheDirty[itemIndex] = true;
|
|
68
|
+
}
|
|
69
|
+
public override flush() {
|
|
70
|
+
for (let itemIndex = 0; itemIndex < this._itemCount; itemIndex++) {
|
|
71
|
+
if (this.itemCacheDirty[itemIndex]) {
|
|
72
|
+
const cachedItem = this.itemCache[itemIndex];
|
|
73
|
+
if (cachedItem !== undefined && cachedItem !== null) {
|
|
74
|
+
duckdb.vector_assign_string_element_len(
|
|
75
|
+
this.vector,
|
|
76
|
+
this.itemOffset + itemIndex,
|
|
77
|
+
getBytesFromBigNum(cachedItem)
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
this.itemCacheDirty[itemIndex] = false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
this.validity.flush(this.vector);
|
|
84
|
+
}
|
|
85
|
+
public override slice(offset: number, length: number): DuckDBBigNumVector {
|
|
86
|
+
return new DuckDBBigNumVector(
|
|
87
|
+
new DataView(
|
|
88
|
+
this.dataView.buffer,
|
|
89
|
+
this.dataView.byteOffset + offset * 16,
|
|
90
|
+
length * 16
|
|
91
|
+
),
|
|
92
|
+
this.validity.slice(offset, length),
|
|
93
|
+
this.vector,
|
|
94
|
+
offset,
|
|
95
|
+
length
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|