@avidian/duckdb-bun 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +286 -2
- package/package.json +96 -4
- package/src/bindings/api/appender.ts +288 -0
- package/src/bindings/api/data-chunk.ts +58 -0
- package/src/bindings/api/database.ts +232 -0
- package/src/bindings/api/datetime.ts +158 -0
- package/src/bindings/api/index.ts +13 -0
- package/src/bindings/api/logical-types.ts +227 -0
- package/src/bindings/api/query.ts +616 -0
- package/src/bindings/api/scalar-function.ts +274 -0
- package/src/bindings/api/table-function.ts +339 -0
- package/src/bindings/api/values.ts +546 -0
- package/src/bindings/api/vector.ts +266 -0
- package/src/bindings/generated/capi.ts +695 -0
- package/src/bindings/generated/contract.ts +162 -0
- package/src/bindings/index.ts +10 -0
- package/src/bindings/runtime/convert.ts +307 -0
- package/src/bindings/runtime/diagnostics.ts +45 -0
- package/src/bindings/runtime/dispatch.ts +213 -0
- package/src/bindings/runtime/exception.ts +103 -0
- package/src/bindings/runtime/flags.ts +19 -0
- package/src/bindings/runtime/handle.ts +217 -0
- package/src/bindings/runtime/kinds.ts +53 -0
- package/src/bindings/runtime/marshal.ts +190 -0
- package/src/bindings/runtime/native.ts +153 -0
- package/src/bindings/runtime/ring.ts +54 -0
- package/src/bindings/runtime/scope.ts +133 -0
- package/src/bindings/runtime/trace.ts +65 -0
- package/src/connection.ts +35 -0
- package/src/database.ts +27 -0
- package/src/errors.ts +30 -0
- package/src/file-assets.d.ts +10 -0
- package/src/index.ts +17 -0
- package/src/library.ts +83 -0
- package/src/neo.ts +16 -0
- package/src/reader.ts +47 -0
- package/src/statement.ts +61 -0
- package/src/types.ts +52 -0
- package/src/version.ts +6 -0
- package/vendor/node-api/LICENSE +7 -0
- package/vendor/node-api/PROVENANCE.md +54 -0
- package/vendor/node-api/node-bindings.d.ts +1669 -0
- package/vendor/node-api/src/DuckDBAppender.ts +237 -0
- package/vendor/node-api/src/DuckDBClientContext.ts +13 -0
- package/vendor/node-api/src/DuckDBConnection.ts +315 -0
- package/vendor/node-api/src/DuckDBDataChunk.ts +412 -0
- package/vendor/node-api/src/DuckDBDataChunkWriter.ts +144 -0
- package/vendor/node-api/src/DuckDBExtractedStatements.ts +37 -0
- package/vendor/node-api/src/DuckDBInstance.ts +35 -0
- package/vendor/node-api/src/DuckDBInstanceCache.ts +29 -0
- package/vendor/node-api/src/DuckDBLogicalType.ts +446 -0
- package/vendor/node-api/src/DuckDBMaterializedResult.ts +39 -0
- package/vendor/node-api/src/DuckDBPendingResult.ts +83 -0
- package/vendor/node-api/src/DuckDBPreparedStatement.ts +376 -0
- package/vendor/node-api/src/DuckDBPreparedStatementCollection.ts +5 -0
- package/vendor/node-api/src/DuckDBPreparedStatementWeakRefCollection.ts +31 -0
- package/vendor/node-api/src/DuckDBResult.ts +403 -0
- package/vendor/node-api/src/DuckDBResultReader.ts +283 -0
- package/vendor/node-api/src/DuckDBScalarFunction.ts +149 -0
- package/vendor/node-api/src/DuckDBScalarFunctionBindInfo.ts +34 -0
- package/vendor/node-api/src/DuckDBScalarFunctionInfo.ts +34 -0
- package/vendor/node-api/src/DuckDBScalarFunctionInitInfo.ts +35 -0
- package/vendor/node-api/src/DuckDBTableFunction.ts +149 -0
- package/vendor/node-api/src/DuckDBTableFunctionBindInfo.ts +56 -0
- package/vendor/node-api/src/DuckDBTableFunctionInfo.ts +36 -0
- package/vendor/node-api/src/DuckDBTableFunctionInitInfo.ts +52 -0
- package/vendor/node-api/src/DuckDBType.ts +1 -0
- package/vendor/node-api/src/DuckDBTypeId.ts +46 -0
- package/vendor/node-api/src/DuckDBValueConverter.ts +23 -0
- package/vendor/node-api/src/DuckDBValueConverters.ts +461 -0
- package/vendor/node-api/src/DuckDBVector.ts +1 -0
- package/vendor/node-api/src/JS.ts +11 -0
- package/vendor/node-api/src/JSDuckDBValueConverter.ts +85 -0
- package/vendor/node-api/src/JSInputTypeForTypeId.ts +101 -0
- package/vendor/node-api/src/JSToDuckDBValueConverter.ts +136 -0
- package/vendor/node-api/src/JSTypeForTypeId.ts +78 -0
- package/vendor/node-api/src/Json.ts +7 -0
- package/vendor/node-api/src/JsonDuckDBValueConverter.ts +72 -0
- package/vendor/node-api/src/JsonTypeForTypeId.ts +86 -0
- package/vendor/node-api/src/ToDuckDBValueConverter.ts +68 -0
- package/vendor/node-api/src/ToDuckDBValueConverters.ts +303 -0
- package/vendor/node-api/src/configurationOptionDescriptions.ts +13 -0
- package/vendor/node-api/src/conversion/bytesFromString.ts +5 -0
- package/vendor/node-api/src/conversion/dateTimeStringConversion.ts +343 -0
- package/vendor/node-api/src/conversion/displayStringForDuckDBValue.ts +12 -0
- package/vendor/node-api/src/conversion/stringFromBlob.ts +48 -0
- package/vendor/node-api/src/conversion/stringFromDecimal.ts +129 -0
- package/vendor/node-api/src/conversion/varintDecode.ts +42 -0
- package/vendor/node-api/src/convertColumnsFromChunks.ts +28 -0
- package/vendor/node-api/src/convertColumnsObjectFromChunks.ts +29 -0
- package/vendor/node-api/src/convertRowObjectsFromChunks.ts +21 -0
- package/vendor/node-api/src/convertRowsFromChunks.ts +16 -0
- package/vendor/node-api/src/createConfig.ts +14 -0
- package/vendor/node-api/src/createDuckDBValueConverter.ts +17 -0
- package/vendor/node-api/src/createResult.ts +15 -0
- package/vendor/node-api/src/createValue.ts +355 -0
- package/vendor/node-api/src/duckdb.ts +51 -0
- package/vendor/node-api/src/enums.ts +7 -0
- package/vendor/node-api/src/getColumnsFromChunks.ts +13 -0
- package/vendor/node-api/src/getColumnsObjectFromChunks.ts +16 -0
- package/vendor/node-api/src/getRowObjectsFromChunks.ts +13 -0
- package/vendor/node-api/src/getRowsFromChunks.ts +12 -0
- package/vendor/node-api/src/index.ts +3 -0
- package/vendor/node-api/src/readValue.ts +31 -0
- package/vendor/node-api/src/sleep.ts +5 -0
- package/vendor/node-api/src/sql.ts +7 -0
- package/vendor/node-api/src/tsconfig.json +7 -0
- package/vendor/node-api/src/typeForValue.ts +144 -0
- package/vendor/node-api/src/types/BaseDuckDBType.ts +31 -0
- package/vendor/node-api/src/types/DuckDBAnyType.ts +13 -0
- package/vendor/node-api/src/types/DuckDBArrayType.ts +43 -0
- package/vendor/node-api/src/types/DuckDBBigIntType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBBigNumType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBBitType.ts +13 -0
- package/vendor/node-api/src/types/DuckDBBlobType.ts +13 -0
- package/vendor/node-api/src/types/DuckDBBooleanType.ts +13 -0
- package/vendor/node-api/src/types/DuckDBDateType.ts +29 -0
- package/vendor/node-api/src/types/DuckDBDecimalType.ts +46 -0
- package/vendor/node-api/src/types/DuckDBDoubleType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBEnumType.ts +111 -0
- package/vendor/node-api/src/types/DuckDBFloatType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBGeometryType.ts +36 -0
- package/vendor/node-api/src/types/DuckDBHugeIntType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBIntegerLiteralType.ts +13 -0
- package/vendor/node-api/src/types/DuckDBIntegerType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBIntervalType.ts +13 -0
- package/vendor/node-api/src/types/DuckDBListType.ts +35 -0
- package/vendor/node-api/src/types/DuckDBMapType.ts +47 -0
- package/vendor/node-api/src/types/DuckDBSQLNullType.ts +17 -0
- package/vendor/node-api/src/types/DuckDBSmallIntType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBStringLiteralType.ts +13 -0
- package/vendor/node-api/src/types/DuckDBStructType.ts +104 -0
- package/vendor/node-api/src/types/DuckDBTimeNSType.ts +20 -0
- package/vendor/node-api/src/types/DuckDBTimeTZType.ts +23 -0
- package/vendor/node-api/src/types/DuckDBTimeType.ts +20 -0
- package/vendor/node-api/src/types/DuckDBTimestampMillisecondsType.ts +29 -0
- package/vendor/node-api/src/types/DuckDBTimestampNanosecondsType.ts +29 -0
- package/vendor/node-api/src/types/DuckDBTimestampSecondsType.ts +29 -0
- package/vendor/node-api/src/types/DuckDBTimestampTZNanosecondsType.ts +32 -0
- package/vendor/node-api/src/types/DuckDBTimestampTZType.ts +32 -0
- package/vendor/node-api/src/types/DuckDBTimestampType.ts +32 -0
- package/vendor/node-api/src/types/DuckDBTinyIntType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBType.ts +86 -0
- package/vendor/node-api/src/types/DuckDBUBigIntType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBUHugeIntType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBUIntegerType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBUSmallIntType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBUTinyIntType.ts +21 -0
- package/vendor/node-api/src/types/DuckDBUUIDType.ts +20 -0
- package/vendor/node-api/src/types/DuckDBUnionType.ts +74 -0
- package/vendor/node-api/src/types/DuckDBVarCharType.ts +13 -0
- package/vendor/node-api/src/types/DuckDBVariantType.ts +13 -0
- package/vendor/node-api/src/types/index.ts +44 -0
- package/vendor/node-api/src/values/DuckDBArrayValue.ts +18 -0
- package/vendor/node-api/src/values/DuckDBBitValue.ts +117 -0
- package/vendor/node-api/src/values/DuckDBBlobValue.ts +26 -0
- package/vendor/node-api/src/values/DuckDBDateValue.ts +43 -0
- package/vendor/node-api/src/values/DuckDBDecimalValue.ts +44 -0
- package/vendor/node-api/src/values/DuckDBGeometryValue.ts +30 -0
- package/vendor/node-api/src/values/DuckDBIntervalValue.ts +22 -0
- package/vendor/node-api/src/values/DuckDBListValue.ts +18 -0
- package/vendor/node-api/src/values/DuckDBMapValue.ts +25 -0
- package/vendor/node-api/src/values/DuckDBStructValue.ts +22 -0
- package/vendor/node-api/src/values/DuckDBTimeNSValue.ts +23 -0
- package/vendor/node-api/src/values/DuckDBTimeTZValue.ts +96 -0
- package/vendor/node-api/src/values/DuckDBTimeValue.ts +34 -0
- package/vendor/node-api/src/values/DuckDBTimestampMillisecondsValue.ts +29 -0
- package/vendor/node-api/src/values/DuckDBTimestampNanosecondsValue.ts +28 -0
- package/vendor/node-api/src/values/DuckDBTimestampSecondsValue.ts +28 -0
- package/vendor/node-api/src/values/DuckDBTimestampTZNanosecondsValue.ts +44 -0
- package/vendor/node-api/src/values/DuckDBTimestampTZValue.ts +54 -0
- package/vendor/node-api/src/values/DuckDBTimestampValue.ts +45 -0
- package/vendor/node-api/src/values/DuckDBTupleValue.ts +22 -0
- package/vendor/node-api/src/values/DuckDBUUIDValue.ts +48 -0
- package/vendor/node-api/src/values/DuckDBUnionValue.ts +22 -0
- package/vendor/node-api/src/values/DuckDBValue.ts +53 -0
- package/vendor/node-api/src/values/DuckDBVariantValue.ts +34 -0
- package/vendor/node-api/src/values/index.ts +24 -0
- package/vendor/node-api/src/vectors/DuckDBArrayVector.ts +107 -0
- package/vendor/node-api/src/vectors/DuckDBBigIntVector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBBigNumVector.ts +98 -0
- package/vendor/node-api/src/vectors/DuckDBBitVector.ts +102 -0
- package/vendor/node-api/src/vectors/DuckDBBlobVector.ts +112 -0
- package/vendor/node-api/src/vectors/DuckDBBooleanVector.ts +84 -0
- package/vendor/node-api/src/vectors/DuckDBDateVector.ts +80 -0
- package/vendor/node-api/src/vectors/DuckDBDecimal128Vector.ts +107 -0
- package/vendor/node-api/src/vectors/DuckDBDecimal16Vector.ts +104 -0
- package/vendor/node-api/src/vectors/DuckDBDecimal32Vector.ts +104 -0
- package/vendor/node-api/src/vectors/DuckDBDecimal64Vector.ts +104 -0
- package/vendor/node-api/src/vectors/DuckDBDoubleVector.ts +68 -0
- package/vendor/node-api/src/vectors/DuckDBEnum16Vector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBEnum32Vector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBEnum8Vector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBFloatVector.ts +68 -0
- package/vendor/node-api/src/vectors/DuckDBGeometryVector.ts +97 -0
- package/vendor/node-api/src/vectors/DuckDBHugeIntVector.ts +89 -0
- package/vendor/node-api/src/vectors/DuckDBIntegerVector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBIntervalVector.ts +100 -0
- package/vendor/node-api/src/vectors/DuckDBListVector.ts +221 -0
- package/vendor/node-api/src/vectors/DuckDBMapVector.ts +88 -0
- package/vendor/node-api/src/vectors/DuckDBSQLNullVector.ts +53 -0
- package/vendor/node-api/src/vectors/DuckDBSmallIntVector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBStructVector.ts +138 -0
- package/vendor/node-api/src/vectors/DuckDBTimeNSVector.ts +80 -0
- package/vendor/node-api/src/vectors/DuckDBTimeTZVector.ts +80 -0
- package/vendor/node-api/src/vectors/DuckDBTimeVector.ts +80 -0
- package/vendor/node-api/src/vectors/DuckDBTimestampMillisecondsVector.ts +88 -0
- package/vendor/node-api/src/vectors/DuckDBTimestampNanosecondsVector.ts +88 -0
- package/vendor/node-api/src/vectors/DuckDBTimestampSecondsVector.ts +88 -0
- package/vendor/node-api/src/vectors/DuckDBTimestampTZNanosecondsVector.ts +88 -0
- package/vendor/node-api/src/vectors/DuckDBTimestampTZVector.ts +86 -0
- package/vendor/node-api/src/vectors/DuckDBTimestampVector.ts +83 -0
- package/vendor/node-api/src/vectors/DuckDBTinyIntVector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBTupleVector.ts +125 -0
- package/vendor/node-api/src/vectors/DuckDBUBigIntVector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBUHugeIntVector.ts +89 -0
- package/vendor/node-api/src/vectors/DuckDBUIntegerVector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBUSmallIntVector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBUTinyIntVector.ts +75 -0
- package/vendor/node-api/src/vectors/DuckDBUUIDVector.ts +89 -0
- package/vendor/node-api/src/vectors/DuckDBUnionVector.ts +84 -0
- package/vendor/node-api/src/vectors/DuckDBValidity.ts +104 -0
- package/vendor/node-api/src/vectors/DuckDBVarCharVector.ts +100 -0
- package/vendor/node-api/src/vectors/DuckDBVariantVector.ts +609 -0
- package/vendor/node-api/src/vectors/DuckDBVector.ts +33 -0
- package/vendor/node-api/src/vectors/createVector.ts +269 -0
- package/vendor/node-api/src/vectors/dataAccessors.ts +387 -0
- package/vendor/node-api/src/vectors/index.ts +50 -0
- package/vendor/node-api/src/vectors/vectorRegistry.ts +24 -0
- package/vendor/node-api/src/version.ts +5 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseDuckDBType } from './BaseDuckDBType';
|
|
2
|
+
import { DuckDBTypeId } from '../DuckDBTypeId';
|
|
3
|
+
|
|
4
|
+
export class DuckDBVarCharType extends BaseDuckDBType<DuckDBTypeId.VARCHAR> {
|
|
5
|
+
public constructor(alias?: string) {
|
|
6
|
+
super(DuckDBTypeId.VARCHAR, alias);
|
|
7
|
+
}
|
|
8
|
+
public static readonly instance = new DuckDBVarCharType();
|
|
9
|
+
public static create(alias?: string): DuckDBVarCharType {
|
|
10
|
+
return alias ? new DuckDBVarCharType(alias) : DuckDBVarCharType.instance;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export const VARCHAR = DuckDBVarCharType.instance;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseDuckDBType } from './BaseDuckDBType';
|
|
2
|
+
import { DuckDBTypeId } from '../DuckDBTypeId';
|
|
3
|
+
|
|
4
|
+
export class DuckDBVariantType extends BaseDuckDBType<DuckDBTypeId.VARIANT> {
|
|
5
|
+
public constructor(alias?: string) {
|
|
6
|
+
super(DuckDBTypeId.VARIANT, alias);
|
|
7
|
+
}
|
|
8
|
+
public static readonly instance = new DuckDBVariantType();
|
|
9
|
+
public static create(alias?: string): DuckDBVariantType {
|
|
10
|
+
return alias ? new DuckDBVariantType(alias) : DuckDBVariantType.instance;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export const VARIANT = DuckDBVariantType.instance;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export * from './BaseDuckDBType';
|
|
2
|
+
export * from './DuckDBAnyType';
|
|
3
|
+
export * from './DuckDBArrayType';
|
|
4
|
+
export * from './DuckDBBigIntType';
|
|
5
|
+
export * from './DuckDBBigNumType';
|
|
6
|
+
export * from './DuckDBBitType';
|
|
7
|
+
export * from './DuckDBBlobType';
|
|
8
|
+
export * from './DuckDBBooleanType';
|
|
9
|
+
export * from './DuckDBDateType';
|
|
10
|
+
export * from './DuckDBDecimalType';
|
|
11
|
+
export * from './DuckDBDoubleType';
|
|
12
|
+
export * from './DuckDBEnumType';
|
|
13
|
+
export * from './DuckDBFloatType';
|
|
14
|
+
export * from './DuckDBGeometryType';
|
|
15
|
+
export * from './DuckDBHugeIntType';
|
|
16
|
+
export * from './DuckDBIntegerLiteralType';
|
|
17
|
+
export * from './DuckDBIntegerType';
|
|
18
|
+
export * from './DuckDBIntervalType';
|
|
19
|
+
export * from './DuckDBListType';
|
|
20
|
+
export * from './DuckDBMapType';
|
|
21
|
+
export * from './DuckDBSQLNullType';
|
|
22
|
+
export * from './DuckDBSmallIntType';
|
|
23
|
+
export * from './DuckDBStringLiteralType';
|
|
24
|
+
export * from './DuckDBStructType';
|
|
25
|
+
export * from './DuckDBTimeNSType';
|
|
26
|
+
export * from './DuckDBTimeTZType';
|
|
27
|
+
export * from './DuckDBTimeType';
|
|
28
|
+
export * from './DuckDBTimestampMillisecondsType';
|
|
29
|
+
export * from './DuckDBTimestampNanosecondsType';
|
|
30
|
+
export * from './DuckDBTimestampSecondsType';
|
|
31
|
+
export * from './DuckDBTimestampTZType';
|
|
32
|
+
export * from './DuckDBTimestampTZNanosecondsType';
|
|
33
|
+
export * from './DuckDBTimestampType';
|
|
34
|
+
export * from './DuckDBTinyIntType';
|
|
35
|
+
export * from './DuckDBType';
|
|
36
|
+
export * from './DuckDBUBigIntType';
|
|
37
|
+
export * from './DuckDBUHugeIntType';
|
|
38
|
+
export * from './DuckDBUIntegerType';
|
|
39
|
+
export * from './DuckDBUSmallIntType';
|
|
40
|
+
export * from './DuckDBUTinyIntType';
|
|
41
|
+
export * from './DuckDBUUIDType';
|
|
42
|
+
export * from './DuckDBUnionType';
|
|
43
|
+
export * from './DuckDBVarCharType';
|
|
44
|
+
export * from './DuckDBVariantType';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { displayStringForDuckDBValue } from '../conversion/displayStringForDuckDBValue';
|
|
2
|
+
import { DuckDBValue } from './DuckDBValue';
|
|
3
|
+
|
|
4
|
+
export class DuckDBArrayValue {
|
|
5
|
+
public readonly items: readonly DuckDBValue[];
|
|
6
|
+
|
|
7
|
+
public constructor(items: readonly DuckDBValue[]) {
|
|
8
|
+
this.items = items;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public toString(): string {
|
|
12
|
+
return `[${this.items.map(displayStringForDuckDBValue).join(', ')}]`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function arrayValue(items: readonly DuckDBValue[]): DuckDBArrayValue {
|
|
17
|
+
return new DuckDBArrayValue(items);
|
|
18
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export class DuckDBBitValue {
|
|
2
|
+
public readonly data: Uint8Array;
|
|
3
|
+
|
|
4
|
+
public constructor(data: Uint8Array) {
|
|
5
|
+
this.data = data;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
public padding(): number {
|
|
9
|
+
return this.data[0];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public get length(): number {
|
|
13
|
+
return (this.data.length - 1) * 8 - this.padding();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public getBool(index: number): boolean {
|
|
17
|
+
const offset = index + this.padding();
|
|
18
|
+
const dataIndex = Math.floor(offset / 8) + 1;
|
|
19
|
+
const byte = this.data[dataIndex] >> (7 - (offset % 8));
|
|
20
|
+
return (byte & 1) !== 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public toBools(): boolean[] {
|
|
24
|
+
const bools: boolean[] = [];
|
|
25
|
+
const length = this.length;
|
|
26
|
+
for (let i = 0; i < length; i++) {
|
|
27
|
+
bools.push(this.getBool(i));
|
|
28
|
+
}
|
|
29
|
+
return bools;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public getBit(index: number): 0 | 1 {
|
|
33
|
+
return this.getBool(index) ? 1 : 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public toBits(): number[] {
|
|
37
|
+
const bits: number[] = [];
|
|
38
|
+
const length = this.length;
|
|
39
|
+
for (let i = 0; i < length; i++) {
|
|
40
|
+
bits.push(this.getBit(i));
|
|
41
|
+
}
|
|
42
|
+
return bits;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public toString(): string {
|
|
46
|
+
const length = this.length;
|
|
47
|
+
const chars = Array.from<string>({ length });
|
|
48
|
+
for (let i = 0; i < length; i++) {
|
|
49
|
+
chars[i] = this.getBool(i) ? '1' : '0';
|
|
50
|
+
}
|
|
51
|
+
return chars.join('');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public static fromString(str: string, on: string = '1'): DuckDBBitValue {
|
|
55
|
+
return DuckDBBitValue.fromLengthAndPredicate(str.length, i => str[i] === on);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public static fromBits(bits: readonly number[], on: number = 1): DuckDBBitValue {
|
|
59
|
+
return DuckDBBitValue.fromLengthAndPredicate(bits.length, i => bits[i] === on);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public static fromBools(bools: readonly boolean[]): DuckDBBitValue {
|
|
63
|
+
return DuckDBBitValue.fromLengthAndPredicate(bools.length, i => bools[i]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public static fromLengthAndPredicate(length: number, predicate: (index: number) => boolean): DuckDBBitValue {
|
|
67
|
+
const byteCount = Math.ceil(length / 8) + 1;
|
|
68
|
+
const paddingBitCount = (8 - (length % 8)) % 8;
|
|
69
|
+
|
|
70
|
+
const data = new Uint8Array(byteCount);
|
|
71
|
+
let byteIndex = 0;
|
|
72
|
+
|
|
73
|
+
// first byte contains count of padding bits
|
|
74
|
+
data[byteIndex++] = paddingBitCount;
|
|
75
|
+
|
|
76
|
+
let byte = 0;
|
|
77
|
+
let byteBit = 0;
|
|
78
|
+
|
|
79
|
+
// padding consists of 1s in MSB of second byte
|
|
80
|
+
while (byteBit < paddingBitCount) {
|
|
81
|
+
byte <<= 1;
|
|
82
|
+
byte |= 1;
|
|
83
|
+
byteBit++;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let bitIndex = 0;
|
|
87
|
+
|
|
88
|
+
while (byteIndex < byteCount) {
|
|
89
|
+
while (byteBit < 8) {
|
|
90
|
+
byte <<= 1;
|
|
91
|
+
if (predicate(bitIndex++)) {
|
|
92
|
+
byte |= 1;
|
|
93
|
+
}
|
|
94
|
+
byteBit++;
|
|
95
|
+
}
|
|
96
|
+
data[byteIndex++] = byte;
|
|
97
|
+
byte = 0;
|
|
98
|
+
byteBit = 0;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return new DuckDBBitValue(data);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function bitValue(input: string | readonly boolean[] | readonly number[]): DuckDBBitValue {
|
|
106
|
+
if (typeof input === 'string') {
|
|
107
|
+
return DuckDBBitValue.fromString(input);
|
|
108
|
+
}
|
|
109
|
+
if (input.length > 0) {
|
|
110
|
+
if (typeof input[0] === 'boolean') {
|
|
111
|
+
return DuckDBBitValue.fromBools(input as readonly boolean[]);
|
|
112
|
+
} else if (typeof input[0] === 'number') {
|
|
113
|
+
return DuckDBBitValue.fromBits(input as readonly number[]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return DuckDBBitValue.fromLengthAndPredicate(0, _ => false);
|
|
117
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { bytesFromString } from '../conversion/bytesFromString';
|
|
2
|
+
import { stringFromBlob } from '../conversion/stringFromBlob';
|
|
3
|
+
|
|
4
|
+
export class DuckDBBlobValue {
|
|
5
|
+
public readonly bytes: Uint8Array;
|
|
6
|
+
|
|
7
|
+
public constructor(bytes: Uint8Array) {
|
|
8
|
+
this.bytes = bytes;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Matches BLOB-to-VARCHAR conversion behavior of DuckDB. */
|
|
12
|
+
public toString(): string {
|
|
13
|
+
return stringFromBlob(this.bytes);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public static fromString(str: string): DuckDBBlobValue {
|
|
17
|
+
return new DuckDBBlobValue(Buffer.from(bytesFromString(str)));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function blobValue(input: Uint8Array | string): DuckDBBlobValue {
|
|
22
|
+
if (typeof input === 'string') {
|
|
23
|
+
return DuckDBBlobValue.fromString(input);
|
|
24
|
+
}
|
|
25
|
+
return new DuckDBBlobValue(input);
|
|
26
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import duckdb, { Date_, DateParts } from "../../../../src/bindings/index.ts";
|
|
2
|
+
import { getDuckDBDateStringFromDays } from '../conversion/dateTimeStringConversion';
|
|
3
|
+
|
|
4
|
+
export type { DateParts };
|
|
5
|
+
|
|
6
|
+
export class DuckDBDateValue implements Date_ {
|
|
7
|
+
public readonly days: number;
|
|
8
|
+
|
|
9
|
+
public constructor(days: number) {
|
|
10
|
+
this.days = days;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public get isFinite(): boolean {
|
|
14
|
+
return duckdb.is_finite_date(this);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public toString(): string {
|
|
18
|
+
return getDuckDBDateStringFromDays(this.days);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public toParts(): DateParts {
|
|
22
|
+
return duckdb.from_date(this);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public static fromParts(parts: DateParts): DuckDBDateValue {
|
|
26
|
+
return new DuckDBDateValue(duckdb.to_date(parts).days);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public static readonly Epoch = new DuckDBDateValue(0);
|
|
30
|
+
|
|
31
|
+
public static readonly Max = new DuckDBDateValue(2 ** 31 - 2);
|
|
32
|
+
public static readonly Min = new DuckDBDateValue(-(2 ** 31 - 2));
|
|
33
|
+
|
|
34
|
+
public static readonly PosInf = new DuckDBDateValue(2 ** 31 - 1);
|
|
35
|
+
public static readonly NegInf = new DuckDBDateValue(-(2 ** 31 - 1));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function dateValue(daysOrParts: number | DateParts): DuckDBDateValue {
|
|
39
|
+
if (typeof daysOrParts === 'number') {
|
|
40
|
+
return new DuckDBDateValue(daysOrParts);
|
|
41
|
+
}
|
|
42
|
+
return DuckDBDateValue.fromParts(daysOrParts);
|
|
43
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import duckdb, { Decimal } from "../../../../src/bindings/index.ts";
|
|
2
|
+
import { stringFromDecimal } from '../conversion/stringFromDecimal';
|
|
3
|
+
|
|
4
|
+
export class DuckDBDecimalValue implements Decimal {
|
|
5
|
+
/** Total number of decimal digits (including fractional digits) in represented number. */
|
|
6
|
+
public readonly width: number;
|
|
7
|
+
|
|
8
|
+
/** Number of fractional digits in represented number. */
|
|
9
|
+
public readonly scale: number;
|
|
10
|
+
|
|
11
|
+
/** Scaled-up value. Represented number is value/(10^scale). */
|
|
12
|
+
public readonly value: bigint;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param value Scaled-up value. Represented number is value/(10^scale).
|
|
16
|
+
* @param width Total number of decimal digits (including fractional digits) in represented number.
|
|
17
|
+
* @param scale Number of fractional digits in represented number.
|
|
18
|
+
*/
|
|
19
|
+
public constructor(value: bigint, width: number, scale: number) {
|
|
20
|
+
this.width = width;
|
|
21
|
+
this.scale = scale;
|
|
22
|
+
this.value = value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public toString(): string {
|
|
26
|
+
return stringFromDecimal(this.value, this.scale);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public toDouble(): number {
|
|
30
|
+
return duckdb.decimal_to_double(this);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public static fromDouble(double: number, width: number, scale: number): DuckDBDecimalValue {
|
|
34
|
+
const decimal = duckdb.double_to_decimal(double, width, scale);
|
|
35
|
+
return new DuckDBDecimalValue(decimal.value, decimal.width, decimal.scale);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function decimalValue(value: bigint | number, width: number, scale: number): DuckDBDecimalValue {
|
|
40
|
+
if (typeof value === 'number') {
|
|
41
|
+
return DuckDBDecimalValue.fromDouble(value, width, scale);
|
|
42
|
+
}
|
|
43
|
+
return new DuckDBDecimalValue(value, width, scale);
|
|
44
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { bytesFromString } from '../conversion/bytesFromString';
|
|
2
|
+
import { stringFromBlob } from '../conversion/stringFromBlob';
|
|
3
|
+
|
|
4
|
+
export class DuckDBGeometryValue {
|
|
5
|
+
/** In WKB. */
|
|
6
|
+
public readonly bytes: Uint8Array;
|
|
7
|
+
|
|
8
|
+
/** Takes raw WKB. */
|
|
9
|
+
public constructor(bytes: Uint8Array) {
|
|
10
|
+
this.bytes = bytes;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Returns WKB in string form matching DuckDB's BLOB-to-VARCHAR. */
|
|
14
|
+
public toString(): string {
|
|
15
|
+
return stringFromBlob(this.bytes);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Takes WKB in string form matching DuckDB's BLOB-to-VARCHAR. */
|
|
19
|
+
public static fromString(str: string): DuckDBGeometryValue {
|
|
20
|
+
return new DuckDBGeometryValue(Buffer.from(bytesFromString(str)));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Takes WKB, either raw or in string form matching DuckDB's BLOB-to-VARCHAR. */
|
|
25
|
+
export function geometryValue(input: Uint8Array | string): DuckDBGeometryValue {
|
|
26
|
+
if (typeof input === 'string') {
|
|
27
|
+
return DuckDBGeometryValue.fromString(input);
|
|
28
|
+
}
|
|
29
|
+
return new DuckDBGeometryValue(input);
|
|
30
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Interval } from "../../../../src/bindings/index.ts";
|
|
2
|
+
import { getDuckDBIntervalString } from '../conversion/dateTimeStringConversion';
|
|
3
|
+
|
|
4
|
+
export class DuckDBIntervalValue implements Interval {
|
|
5
|
+
public readonly months: number;
|
|
6
|
+
public readonly days: number;
|
|
7
|
+
public readonly micros: bigint;
|
|
8
|
+
|
|
9
|
+
public constructor(months: number, days: number, micros: bigint) {
|
|
10
|
+
this.months = months;
|
|
11
|
+
this.days = days;
|
|
12
|
+
this.micros = micros;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public toString(): string {
|
|
16
|
+
return getDuckDBIntervalString(this.months, this.days, this.micros);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function intervalValue(months: number, days: number, micros: bigint): DuckDBIntervalValue {
|
|
21
|
+
return new DuckDBIntervalValue(months, days, micros);
|
|
22
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { displayStringForDuckDBValue } from '../conversion/displayStringForDuckDBValue';
|
|
2
|
+
import { DuckDBValue } from './DuckDBValue';
|
|
3
|
+
|
|
4
|
+
export class DuckDBListValue {
|
|
5
|
+
public readonly items: readonly DuckDBValue[];
|
|
6
|
+
|
|
7
|
+
public constructor(items: readonly DuckDBValue[]) {
|
|
8
|
+
this.items = items;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public toString(): string {
|
|
12
|
+
return `[${this.items.map(displayStringForDuckDBValue).join(', ')}]`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function listValue(items: readonly DuckDBValue[]): DuckDBListValue {
|
|
17
|
+
return new DuckDBListValue(items);
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { displayStringForDuckDBValue } from '../conversion/displayStringForDuckDBValue';
|
|
2
|
+
import { DuckDBValue } from './DuckDBValue';
|
|
3
|
+
|
|
4
|
+
export interface DuckDBMapEntry {
|
|
5
|
+
key: DuckDBValue;
|
|
6
|
+
value: DuckDBValue;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class DuckDBMapValue {
|
|
10
|
+
public readonly entries: DuckDBMapEntry[];
|
|
11
|
+
|
|
12
|
+
public constructor(entries: DuckDBMapEntry[]) {
|
|
13
|
+
this.entries = entries;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public toString(): string {
|
|
17
|
+
return `{${this.entries.map(({ key, value }) =>
|
|
18
|
+
`${displayStringForDuckDBValue(key)}: ${displayStringForDuckDBValue(value)}`
|
|
19
|
+
).join(', ')}}`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function mapValue(entries: DuckDBMapEntry[]): DuckDBMapValue {
|
|
24
|
+
return new DuckDBMapValue(entries);
|
|
25
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { displayStringForDuckDBValue } from '../conversion/displayStringForDuckDBValue';
|
|
2
|
+
import { DuckDBValue } from './DuckDBValue';
|
|
3
|
+
|
|
4
|
+
export class DuckDBStructValue {
|
|
5
|
+
public readonly entries: Readonly<Record<string, DuckDBValue>>;
|
|
6
|
+
|
|
7
|
+
public constructor(entries: Readonly<Record<string, DuckDBValue>>) {
|
|
8
|
+
this.entries = entries;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public toString(): string {
|
|
12
|
+
const parts: string[] = [];
|
|
13
|
+
for (const name in this.entries) {
|
|
14
|
+
parts.push(`${displayStringForDuckDBValue(name)}: ${displayStringForDuckDBValue(this.entries[name])}`);
|
|
15
|
+
}
|
|
16
|
+
return `{${parts.join(', ')}}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function structValue(entries: Readonly<Record<string, DuckDBValue>>): DuckDBStructValue {
|
|
21
|
+
return new DuckDBStructValue(entries);
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TimeNS } from "../../../../src/bindings/index.ts";
|
|
2
|
+
import { getDuckDBTimeStringFromNanosecondsInDay } from '../conversion/dateTimeStringConversion';
|
|
3
|
+
|
|
4
|
+
export class DuckDBTimeNSValue implements TimeNS {
|
|
5
|
+
public readonly nanos: bigint;
|
|
6
|
+
|
|
7
|
+
public constructor(nanos: bigint) {
|
|
8
|
+
this.nanos = nanos;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public toString(): string {
|
|
12
|
+
return getDuckDBTimeStringFromNanosecondsInDay(this.nanos);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public static readonly Max = new DuckDBTimeNSValue(
|
|
16
|
+
24n * 60n * 60n * 1000n * 1000n * 1000n
|
|
17
|
+
);
|
|
18
|
+
public static readonly Min = new DuckDBTimeNSValue(0n);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function timeNSValue(nanos: bigint): DuckDBTimeNSValue {
|
|
22
|
+
return new DuckDBTimeNSValue(nanos);
|
|
23
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import duckdb, { TimeTZ, TimeTZParts } from "../../../../src/bindings/index.ts";
|
|
2
|
+
import {
|
|
3
|
+
getDuckDBTimeStringFromMicrosecondsInDay,
|
|
4
|
+
getOffsetStringFromSeconds
|
|
5
|
+
} from '../conversion/dateTimeStringConversion';
|
|
6
|
+
|
|
7
|
+
export type { TimeTZParts };
|
|
8
|
+
|
|
9
|
+
export class DuckDBTimeTZValue implements TimeTZ {
|
|
10
|
+
/**
|
|
11
|
+
* 40 bits for micros, then 24 bits for encoded offset in seconds.
|
|
12
|
+
*
|
|
13
|
+
* Max absolute unencoded offset = 15:59:59 = 60 * (60 * 15 + 59) + 59 = 57599.
|
|
14
|
+
*
|
|
15
|
+
* Encoded offset is unencoded offset inverted then shifted (by +57599) to unsigned.
|
|
16
|
+
*
|
|
17
|
+
* Max unencoded offset = 57599 -> -57599 -> 0 encoded.
|
|
18
|
+
*
|
|
19
|
+
* Min unencoded offset = -57599 -> 57599 -> 115198 encoded.
|
|
20
|
+
*/
|
|
21
|
+
public readonly bits: bigint;
|
|
22
|
+
|
|
23
|
+
/** Ranges from 0 to 86400000000 (= 24 * 60 * 60 * 1000 * 1000) */
|
|
24
|
+
public readonly micros: bigint;
|
|
25
|
+
|
|
26
|
+
/** In seconds, ranges from -57599 to 57599 (= 16 * 60 * 60 - 1) */
|
|
27
|
+
public readonly offset: number;
|
|
28
|
+
|
|
29
|
+
public constructor(bits: bigint, micros: bigint, offset: number) {
|
|
30
|
+
this.bits = bits;
|
|
31
|
+
this.micros = micros;
|
|
32
|
+
this.offset = offset;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public toString(): string {
|
|
36
|
+
return `${getDuckDBTimeStringFromMicrosecondsInDay(
|
|
37
|
+
this.micros
|
|
38
|
+
)}${getOffsetStringFromSeconds(this.offset)}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public toParts(): TimeTZParts {
|
|
42
|
+
return duckdb.from_time_tz(this);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public static TimeBits = 40;
|
|
46
|
+
public static OffsetBits = 24;
|
|
47
|
+
public static MaxOffset = 16 * 60 * 60 - 1; // ±15:59:59 = 57599 seconds
|
|
48
|
+
public static MinOffset = -DuckDBTimeTZValue.MaxOffset;
|
|
49
|
+
public static MaxMicros = 24n * 60n * 60n * 1000n * 1000n; // 86400000000
|
|
50
|
+
public static MinMicros = 0n;
|
|
51
|
+
|
|
52
|
+
public static fromBits(bits: bigint): DuckDBTimeTZValue {
|
|
53
|
+
const micros = BigInt.asUintN(
|
|
54
|
+
DuckDBTimeTZValue.TimeBits,
|
|
55
|
+
bits >> BigInt(DuckDBTimeTZValue.OffsetBits)
|
|
56
|
+
);
|
|
57
|
+
const offset =
|
|
58
|
+
DuckDBTimeTZValue.MaxOffset -
|
|
59
|
+
Number(BigInt.asUintN(DuckDBTimeTZValue.OffsetBits, bits));
|
|
60
|
+
return new DuckDBTimeTZValue(bits, micros, offset);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public static fromMicrosAndOffset(
|
|
64
|
+
micros: bigint,
|
|
65
|
+
offset: number
|
|
66
|
+
): DuckDBTimeTZValue {
|
|
67
|
+
const bits =
|
|
68
|
+
(BigInt.asUintN(DuckDBTimeTZValue.TimeBits, micros) <<
|
|
69
|
+
BigInt(DuckDBTimeTZValue.OffsetBits)) |
|
|
70
|
+
BigInt.asUintN(
|
|
71
|
+
DuckDBTimeTZValue.OffsetBits,
|
|
72
|
+
BigInt(DuckDBTimeTZValue.MaxOffset - offset)
|
|
73
|
+
);
|
|
74
|
+
return new DuckDBTimeTZValue(bits, micros, offset);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public static fromParts(parts: TimeTZParts): DuckDBTimeTZValue {
|
|
78
|
+
return DuckDBTimeTZValue.fromMicrosAndOffset(
|
|
79
|
+
duckdb.to_time(parts.time).micros,
|
|
80
|
+
parts.offset
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public static readonly Max = DuckDBTimeTZValue.fromMicrosAndOffset(
|
|
85
|
+
DuckDBTimeTZValue.MaxMicros,
|
|
86
|
+
DuckDBTimeTZValue.MinOffset
|
|
87
|
+
);
|
|
88
|
+
public static readonly Min = DuckDBTimeTZValue.fromMicrosAndOffset(
|
|
89
|
+
DuckDBTimeTZValue.MinMicros,
|
|
90
|
+
DuckDBTimeTZValue.MaxOffset
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function timeTZValue(micros: bigint, offset: number): DuckDBTimeTZValue {
|
|
95
|
+
return DuckDBTimeTZValue.fromMicrosAndOffset(micros, offset);
|
|
96
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import duckdb, { Time, TimeParts } from "../../../../src/bindings/index.ts";
|
|
2
|
+
import { getDuckDBTimeStringFromMicrosecondsInDay } from '../conversion/dateTimeStringConversion';
|
|
3
|
+
|
|
4
|
+
export type { TimeParts };
|
|
5
|
+
|
|
6
|
+
export class DuckDBTimeValue implements Time {
|
|
7
|
+
public readonly micros: bigint;
|
|
8
|
+
|
|
9
|
+
public constructor(micros: bigint) {
|
|
10
|
+
this.micros = micros;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public toString(): string {
|
|
14
|
+
return getDuckDBTimeStringFromMicrosecondsInDay(this.micros);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public toParts(): TimeParts {
|
|
18
|
+
return duckdb.from_time(this);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public static fromParts(parts: TimeParts): DuckDBTimeValue {
|
|
22
|
+
return new DuckDBTimeValue(duckdb.to_time(parts).micros);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public static readonly Max = new DuckDBTimeValue(24n * 60n * 60n * 1000n * 1000n);
|
|
26
|
+
public static readonly Min = new DuckDBTimeValue(0n);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function timeValue(microsOrParts: bigint | TimeParts): DuckDBTimeValue {
|
|
30
|
+
if (typeof microsOrParts === 'bigint') {
|
|
31
|
+
return new DuckDBTimeValue(microsOrParts);
|
|
32
|
+
}
|
|
33
|
+
return DuckDBTimeValue.fromParts(microsOrParts);
|
|
34
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import duckdb, { TimestampMilliseconds } from "../../../../src/bindings/index.ts";
|
|
2
|
+
import { getDuckDBTimestampStringFromMilliseconds } from '../conversion/dateTimeStringConversion';
|
|
3
|
+
import { DuckDBTimestampSecondsValue } from './DuckDBTimestampSecondsValue';
|
|
4
|
+
|
|
5
|
+
export class DuckDBTimestampMillisecondsValue implements TimestampMilliseconds {
|
|
6
|
+
public readonly millis: bigint;
|
|
7
|
+
|
|
8
|
+
public constructor(millis: bigint) {
|
|
9
|
+
this.millis = millis;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public get isFinite(): boolean {
|
|
13
|
+
return duckdb.is_finite_timestamp_ms(this);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public toString(): string {
|
|
17
|
+
return getDuckDBTimestampStringFromMilliseconds(this.millis);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public static readonly Epoch = new DuckDBTimestampMillisecondsValue(0n);
|
|
21
|
+
public static readonly Max = new DuckDBTimestampMillisecondsValue((2n ** 63n - 2n) / 1000n);
|
|
22
|
+
public static readonly Min = new DuckDBTimestampMillisecondsValue(DuckDBTimestampSecondsValue.Min.seconds * 1000n);
|
|
23
|
+
public static readonly PosInf = new DuckDBTimestampMillisecondsValue(2n ** 63n - 1n);
|
|
24
|
+
public static readonly NegInf = new DuckDBTimestampMillisecondsValue(-(2n ** 63n - 1n));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function timestampMillisValue(millis: bigint): DuckDBTimestampMillisecondsValue {
|
|
28
|
+
return new DuckDBTimestampMillisecondsValue(millis);
|
|
29
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import duckdb, { TimestampNanoseconds } from "../../../../src/bindings/index.ts";
|
|
2
|
+
import { getDuckDBTimestampStringFromNanoseconds } from '../conversion/dateTimeStringConversion';
|
|
3
|
+
|
|
4
|
+
export class DuckDBTimestampNanosecondsValue implements TimestampNanoseconds {
|
|
5
|
+
public readonly nanos: bigint;
|
|
6
|
+
|
|
7
|
+
public constructor(nanos: bigint) {
|
|
8
|
+
this.nanos = nanos;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public get isFinite(): boolean {
|
|
12
|
+
return duckdb.is_finite_timestamp_ns(this);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public toString(): string {
|
|
16
|
+
return getDuckDBTimestampStringFromNanoseconds(this.nanos);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public static readonly Epoch = new DuckDBTimestampNanosecondsValue(0n);
|
|
20
|
+
public static readonly Max = new DuckDBTimestampNanosecondsValue(2n ** 63n - 2n);
|
|
21
|
+
public static readonly Min = new DuckDBTimestampNanosecondsValue(-9223286400000000000n);
|
|
22
|
+
public static readonly PosInf = new DuckDBTimestampNanosecondsValue(2n ** 63n - 1n);
|
|
23
|
+
public static readonly NegInf = new DuckDBTimestampNanosecondsValue(-(2n ** 63n - 1n));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function timestampNanosValue(nanos: bigint): DuckDBTimestampNanosecondsValue {
|
|
27
|
+
return new DuckDBTimestampNanosecondsValue(nanos);
|
|
28
|
+
}
|