@haybarn/node-api 1.5.3-rc2
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 +7 -0
- package/README.md +1224 -0
- package/lib/DuckDBAppender.d.ts +51 -0
- package/lib/DuckDBAppender.js +149 -0
- package/lib/DuckDBBindInfo.d.ts +12 -0
- package/lib/DuckDBBindInfo.js +33 -0
- package/lib/DuckDBClientContext.d.ts +6 -0
- package/lib/DuckDBClientContext.js +17 -0
- package/lib/DuckDBConnection.d.ts +49 -0
- package/lib/DuckDBConnection.js +208 -0
- package/lib/DuckDBDataChunk.d.ts +41 -0
- package/lib/DuckDBDataChunk.js +223 -0
- package/lib/DuckDBExtractedStatements.d.ts +12 -0
- package/lib/DuckDBExtractedStatements.js +31 -0
- package/lib/DuckDBFunctionInfo.d.ts +10 -0
- package/lib/DuckDBFunctionInfo.js +29 -0
- package/lib/DuckDBInstance.d.ts +10 -0
- package/lib/DuckDBInstance.js +30 -0
- package/lib/DuckDBInstanceCache.d.ts +8 -0
- package/lib/DuckDBInstanceCache.js +28 -0
- package/lib/DuckDBLogicalType.d.ts +66 -0
- package/lib/DuckDBLogicalType.js +328 -0
- package/lib/DuckDBMaterializedResult.d.ts +9 -0
- package/lib/DuckDBMaterializedResult.js +24 -0
- package/lib/DuckDBPendingResult.d.ts +18 -0
- package/lib/DuckDBPendingResult.js +60 -0
- package/lib/DuckDBPreparedStatement.d.ts +72 -0
- package/lib/DuckDBPreparedStatement.js +219 -0
- package/lib/DuckDBPreparedStatementCollection.d.ts +4 -0
- package/lib/DuckDBPreparedStatementCollection.js +2 -0
- package/lib/DuckDBPreparedStatementWeakRefCollection.d.ts +9 -0
- package/lib/DuckDBPreparedStatementWeakRefCollection.js +28 -0
- package/lib/DuckDBResult.d.ts +57 -0
- package/lib/DuckDBResult.js +229 -0
- package/lib/DuckDBResultReader.d.ts +68 -0
- package/lib/DuckDBResultReader.js +203 -0
- package/lib/DuckDBScalarFunction.d.ts +33 -0
- package/lib/DuckDBScalarFunction.js +83 -0
- package/lib/DuckDBType.d.ts +373 -0
- package/lib/DuckDBType.js +930 -0
- package/lib/DuckDBTypeId.d.ts +42 -0
- package/lib/DuckDBTypeId.js +47 -0
- package/lib/DuckDBValueConverter.d.ts +3 -0
- package/lib/DuckDBValueConverter.js +2 -0
- package/lib/DuckDBValueConverters.d.ts +47 -0
- package/lib/DuckDBValueConverters.js +214 -0
- package/lib/DuckDBVector.d.ts +596 -0
- package/lib/DuckDBVector.js +2525 -0
- package/lib/JS.d.ts +3 -0
- package/lib/JS.js +2 -0
- package/lib/JSDuckDBValueConverter.d.ts +3 -0
- package/lib/JSDuckDBValueConverter.js +49 -0
- package/lib/Json.d.ts +3 -0
- package/lib/Json.js +2 -0
- package/lib/JsonDuckDBValueConverter.d.ts +3 -0
- package/lib/JsonDuckDBValueConverter.js +49 -0
- package/lib/configurationOptionDescriptions.d.ts +1 -0
- package/lib/configurationOptionDescriptions.js +16 -0
- package/lib/conversion/bytesFromString.d.ts +1 -0
- package/lib/conversion/bytesFromString.js +7 -0
- package/lib/conversion/dateTimeStringConversion.d.ts +20 -0
- package/lib/conversion/dateTimeStringConversion.js +238 -0
- package/lib/conversion/displayStringForDuckDBValue.d.ts +2 -0
- package/lib/conversion/displayStringForDuckDBValue.js +13 -0
- package/lib/conversion/stringFromBlob.d.ts +4 -0
- package/lib/conversion/stringFromBlob.js +45 -0
- package/lib/conversion/stringFromDecimal.d.ts +18 -0
- package/lib/conversion/stringFromDecimal.js +80 -0
- package/lib/convertColumnsFromChunks.d.ts +3 -0
- package/lib/convertColumnsFromChunks.js +16 -0
- package/lib/convertColumnsObjectFromChunks.d.ts +3 -0
- package/lib/convertColumnsObjectFromChunks.js +19 -0
- package/lib/convertRowObjectsFromChunks.d.ts +3 -0
- package/lib/convertRowObjectsFromChunks.js +17 -0
- package/lib/convertRowsFromChunks.d.ts +3 -0
- package/lib/convertRowsFromChunks.js +13 -0
- package/lib/createConfig.d.ts +2 -0
- package/lib/createConfig.js +19 -0
- package/lib/createDuckDBValueConverter.d.ts +3 -0
- package/lib/createDuckDBValueConverter.js +15 -0
- package/lib/createResult.d.ts +3 -0
- package/lib/createResult.js +17 -0
- package/lib/createValue.d.ts +4 -0
- package/lib/createValue.js +222 -0
- package/lib/duckdb.d.ts +33 -0
- package/lib/duckdb.js +54 -0
- package/lib/enums.d.ts +5 -0
- package/lib/enums.js +9 -0
- package/lib/getColumnsFromChunks.d.ts +3 -0
- package/lib/getColumnsFromChunks.js +10 -0
- package/lib/getColumnsObjectFromChunks.d.ts +3 -0
- package/lib/getColumnsObjectFromChunks.js +10 -0
- package/lib/getRowObjectsFromChunks.d.ts +3 -0
- package/lib/getRowObjectsFromChunks.js +10 -0
- package/lib/getRowsFromChunks.d.ts +3 -0
- package/lib/getRowsFromChunks.js +10 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +41 -0
- package/lib/sleep.d.ts +1 -0
- package/lib/sleep.js +8 -0
- package/lib/sql.d.ts +2 -0
- package/lib/sql.js +10 -0
- package/lib/typeForValue.d.ts +3 -0
- package/lib/typeForValue.js +91 -0
- package/lib/values/DuckDBArrayValue.d.ts +7 -0
- package/lib/values/DuckDBArrayValue.js +18 -0
- package/lib/values/DuckDBBitValue.d.ts +16 -0
- package/lib/values/DuckDBBitValue.js +103 -0
- package/lib/values/DuckDBBlobValue.d.ts +8 -0
- package/lib/values/DuckDBBlobValue.js +26 -0
- package/lib/values/DuckDBDateValue.d.ts +16 -0
- package/lib/values/DuckDBDateValue.js +39 -0
- package/lib/values/DuckDBDecimalValue.d.ts +19 -0
- package/lib/values/DuckDBDecimalValue.js +44 -0
- package/lib/values/DuckDBIntervalValue.d.ts +9 -0
- package/lib/values/DuckDBIntervalValue.js +22 -0
- package/lib/values/DuckDBListValue.d.ts +7 -0
- package/lib/values/DuckDBListValue.js +18 -0
- package/lib/values/DuckDBMapValue.d.ts +11 -0
- package/lib/values/DuckDBMapValue.js +18 -0
- package/lib/values/DuckDBStructValue.d.ts +7 -0
- package/lib/values/DuckDBStructValue.js +22 -0
- package/lib/values/DuckDBTimeNSValue.d.ts +9 -0
- package/lib/values/DuckDBTimeNSValue.js +20 -0
- package/lib/values/DuckDBTimeTZValue.d.ts +35 -0
- package/lib/values/DuckDBTimeTZValue.js +65 -0
- package/lib/values/DuckDBTimeValue.d.ts +12 -0
- package/lib/values/DuckDBTimeValue.js +33 -0
- package/lib/values/DuckDBTimestampMillisecondsValue.d.ts +13 -0
- package/lib/values/DuckDBTimestampMillisecondsValue.js +31 -0
- package/lib/values/DuckDBTimestampNanosecondsValue.d.ts +13 -0
- package/lib/values/DuckDBTimestampNanosecondsValue.js +30 -0
- package/lib/values/DuckDBTimestampSecondsValue.d.ts +13 -0
- package/lib/values/DuckDBTimestampSecondsValue.js +30 -0
- package/lib/values/DuckDBTimestampTZValue.d.ts +16 -0
- package/lib/values/DuckDBTimestampTZValue.js +41 -0
- package/lib/values/DuckDBTimestampValue.d.ts +18 -0
- package/lib/values/DuckDBTimestampValue.js +41 -0
- package/lib/values/DuckDBUUIDValue.d.ts +19 -0
- package/lib/values/DuckDBUUIDValue.js +40 -0
- package/lib/values/DuckDBUnionValue.d.ts +8 -0
- package/lib/values/DuckDBUnionValue.js +22 -0
- package/lib/values/DuckDBValue.d.ts +20 -0
- package/lib/values/DuckDBValue.js +2 -0
- package/lib/values/index.d.ts +20 -0
- package/lib/values/index.js +36 -0
- package/lib/version.d.ts +1 -0
- package/lib/version.js +10 -0
- package/package.json +15 -0
package/lib/JS.d.ts
ADDED
package/lib/JS.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JSDuckDBValueConverter = void 0;
|
|
4
|
+
const createDuckDBValueConverter_1 = require("./createDuckDBValueConverter");
|
|
5
|
+
const DuckDBTypeId_1 = require("./DuckDBTypeId");
|
|
6
|
+
const DuckDBValueConverters_1 = require("./DuckDBValueConverters");
|
|
7
|
+
const JSConvertersByTypeId = {
|
|
8
|
+
[DuckDBTypeId_1.DuckDBTypeId.INVALID]: DuckDBValueConverters_1.unsupportedConverter,
|
|
9
|
+
[DuckDBTypeId_1.DuckDBTypeId.BOOLEAN]: DuckDBValueConverters_1.booleanFromValue,
|
|
10
|
+
[DuckDBTypeId_1.DuckDBTypeId.TINYINT]: DuckDBValueConverters_1.numberFromValue,
|
|
11
|
+
[DuckDBTypeId_1.DuckDBTypeId.SMALLINT]: DuckDBValueConverters_1.numberFromValue,
|
|
12
|
+
[DuckDBTypeId_1.DuckDBTypeId.INTEGER]: DuckDBValueConverters_1.numberFromValue,
|
|
13
|
+
[DuckDBTypeId_1.DuckDBTypeId.BIGINT]: DuckDBValueConverters_1.bigintFromBigIntValue,
|
|
14
|
+
[DuckDBTypeId_1.DuckDBTypeId.UTINYINT]: DuckDBValueConverters_1.numberFromValue,
|
|
15
|
+
[DuckDBTypeId_1.DuckDBTypeId.USMALLINT]: DuckDBValueConverters_1.numberFromValue,
|
|
16
|
+
[DuckDBTypeId_1.DuckDBTypeId.UINTEGER]: DuckDBValueConverters_1.numberFromValue,
|
|
17
|
+
[DuckDBTypeId_1.DuckDBTypeId.UBIGINT]: DuckDBValueConverters_1.bigintFromBigIntValue,
|
|
18
|
+
[DuckDBTypeId_1.DuckDBTypeId.FLOAT]: DuckDBValueConverters_1.numberFromValue,
|
|
19
|
+
[DuckDBTypeId_1.DuckDBTypeId.DOUBLE]: DuckDBValueConverters_1.numberFromValue,
|
|
20
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP]: DuckDBValueConverters_1.dateFromTimestampValue,
|
|
21
|
+
[DuckDBTypeId_1.DuckDBTypeId.DATE]: DuckDBValueConverters_1.dateFromDateValue,
|
|
22
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIME]: DuckDBValueConverters_1.bigintFromTimeValue,
|
|
23
|
+
[DuckDBTypeId_1.DuckDBTypeId.INTERVAL]: DuckDBValueConverters_1.objectFromIntervalValue,
|
|
24
|
+
[DuckDBTypeId_1.DuckDBTypeId.HUGEINT]: DuckDBValueConverters_1.bigintFromBigIntValue,
|
|
25
|
+
[DuckDBTypeId_1.DuckDBTypeId.UHUGEINT]: DuckDBValueConverters_1.bigintFromBigIntValue,
|
|
26
|
+
[DuckDBTypeId_1.DuckDBTypeId.VARCHAR]: DuckDBValueConverters_1.stringFromValue,
|
|
27
|
+
[DuckDBTypeId_1.DuckDBTypeId.BLOB]: DuckDBValueConverters_1.bytesFromBlobValue,
|
|
28
|
+
[DuckDBTypeId_1.DuckDBTypeId.DECIMAL]: DuckDBValueConverters_1.doubleFromDecimalValue,
|
|
29
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_S]: DuckDBValueConverters_1.dateFromTimestampSecondsValue,
|
|
30
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_MS]: DuckDBValueConverters_1.dateFromTimestampMillisecondsValue,
|
|
31
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_NS]: DuckDBValueConverters_1.dateFromTimestampNanosecondsValue,
|
|
32
|
+
[DuckDBTypeId_1.DuckDBTypeId.ENUM]: DuckDBValueConverters_1.stringFromValue,
|
|
33
|
+
[DuckDBTypeId_1.DuckDBTypeId.LIST]: DuckDBValueConverters_1.arrayFromListValue,
|
|
34
|
+
[DuckDBTypeId_1.DuckDBTypeId.STRUCT]: DuckDBValueConverters_1.objectFromStructValue,
|
|
35
|
+
[DuckDBTypeId_1.DuckDBTypeId.MAP]: DuckDBValueConverters_1.objectArrayFromMapValue,
|
|
36
|
+
[DuckDBTypeId_1.DuckDBTypeId.ARRAY]: DuckDBValueConverters_1.arrayFromArrayValue,
|
|
37
|
+
[DuckDBTypeId_1.DuckDBTypeId.UUID]: DuckDBValueConverters_1.stringFromValue,
|
|
38
|
+
[DuckDBTypeId_1.DuckDBTypeId.UNION]: DuckDBValueConverters_1.objectFromUnionValue,
|
|
39
|
+
[DuckDBTypeId_1.DuckDBTypeId.BIT]: DuckDBValueConverters_1.bytesFromBitValue,
|
|
40
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIME_TZ]: DuckDBValueConverters_1.objectFromTimeTZValue,
|
|
41
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_TZ]: DuckDBValueConverters_1.dateFromTimestampTZValue,
|
|
42
|
+
[DuckDBTypeId_1.DuckDBTypeId.ANY]: DuckDBValueConverters_1.unsupportedConverter,
|
|
43
|
+
[DuckDBTypeId_1.DuckDBTypeId.BIGNUM]: DuckDBValueConverters_1.bigintFromBigIntValue,
|
|
44
|
+
[DuckDBTypeId_1.DuckDBTypeId.SQLNULL]: DuckDBValueConverters_1.nullConverter,
|
|
45
|
+
[DuckDBTypeId_1.DuckDBTypeId.STRING_LITERAL]: DuckDBValueConverters_1.unsupportedConverter,
|
|
46
|
+
[DuckDBTypeId_1.DuckDBTypeId.INTEGER_LITERAL]: DuckDBValueConverters_1.unsupportedConverter,
|
|
47
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIME_NS]: DuckDBValueConverters_1.bigintFromTimeValue,
|
|
48
|
+
};
|
|
49
|
+
exports.JSDuckDBValueConverter = (0, createDuckDBValueConverter_1.createDuckDBValueConverter)(JSConvertersByTypeId);
|
package/lib/Json.d.ts
ADDED
package/lib/Json.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonDuckDBValueConverter = void 0;
|
|
4
|
+
const createDuckDBValueConverter_1 = require("./createDuckDBValueConverter");
|
|
5
|
+
const DuckDBTypeId_1 = require("./DuckDBTypeId");
|
|
6
|
+
const DuckDBValueConverters_1 = require("./DuckDBValueConverters");
|
|
7
|
+
const JsonConvertersByTypeId = {
|
|
8
|
+
[DuckDBTypeId_1.DuckDBTypeId.INVALID]: DuckDBValueConverters_1.unsupportedConverter,
|
|
9
|
+
[DuckDBTypeId_1.DuckDBTypeId.BOOLEAN]: DuckDBValueConverters_1.booleanFromValue,
|
|
10
|
+
[DuckDBTypeId_1.DuckDBTypeId.TINYINT]: DuckDBValueConverters_1.numberFromValue,
|
|
11
|
+
[DuckDBTypeId_1.DuckDBTypeId.SMALLINT]: DuckDBValueConverters_1.numberFromValue,
|
|
12
|
+
[DuckDBTypeId_1.DuckDBTypeId.INTEGER]: DuckDBValueConverters_1.numberFromValue,
|
|
13
|
+
[DuckDBTypeId_1.DuckDBTypeId.BIGINT]: DuckDBValueConverters_1.stringFromValue,
|
|
14
|
+
[DuckDBTypeId_1.DuckDBTypeId.UTINYINT]: DuckDBValueConverters_1.numberFromValue,
|
|
15
|
+
[DuckDBTypeId_1.DuckDBTypeId.USMALLINT]: DuckDBValueConverters_1.numberFromValue,
|
|
16
|
+
[DuckDBTypeId_1.DuckDBTypeId.UINTEGER]: DuckDBValueConverters_1.numberFromValue,
|
|
17
|
+
[DuckDBTypeId_1.DuckDBTypeId.UBIGINT]: DuckDBValueConverters_1.stringFromValue,
|
|
18
|
+
[DuckDBTypeId_1.DuckDBTypeId.FLOAT]: DuckDBValueConverters_1.jsonNumberFromValue,
|
|
19
|
+
[DuckDBTypeId_1.DuckDBTypeId.DOUBLE]: DuckDBValueConverters_1.jsonNumberFromValue,
|
|
20
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP]: DuckDBValueConverters_1.stringFromValue,
|
|
21
|
+
[DuckDBTypeId_1.DuckDBTypeId.DATE]: DuckDBValueConverters_1.stringFromValue,
|
|
22
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIME]: DuckDBValueConverters_1.stringFromValue,
|
|
23
|
+
[DuckDBTypeId_1.DuckDBTypeId.INTERVAL]: DuckDBValueConverters_1.jsonObjectFromIntervalValue,
|
|
24
|
+
[DuckDBTypeId_1.DuckDBTypeId.HUGEINT]: DuckDBValueConverters_1.stringFromValue,
|
|
25
|
+
[DuckDBTypeId_1.DuckDBTypeId.UHUGEINT]: DuckDBValueConverters_1.stringFromValue,
|
|
26
|
+
[DuckDBTypeId_1.DuckDBTypeId.VARCHAR]: DuckDBValueConverters_1.stringFromValue,
|
|
27
|
+
[DuckDBTypeId_1.DuckDBTypeId.BLOB]: DuckDBValueConverters_1.stringFromValue,
|
|
28
|
+
[DuckDBTypeId_1.DuckDBTypeId.DECIMAL]: DuckDBValueConverters_1.stringFromValue,
|
|
29
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_S]: DuckDBValueConverters_1.stringFromValue,
|
|
30
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_MS]: DuckDBValueConverters_1.stringFromValue,
|
|
31
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_NS]: DuckDBValueConverters_1.stringFromValue,
|
|
32
|
+
[DuckDBTypeId_1.DuckDBTypeId.ENUM]: DuckDBValueConverters_1.stringFromValue,
|
|
33
|
+
[DuckDBTypeId_1.DuckDBTypeId.LIST]: DuckDBValueConverters_1.arrayFromListValue,
|
|
34
|
+
[DuckDBTypeId_1.DuckDBTypeId.STRUCT]: DuckDBValueConverters_1.objectFromStructValue,
|
|
35
|
+
[DuckDBTypeId_1.DuckDBTypeId.MAP]: DuckDBValueConverters_1.objectArrayFromMapValue,
|
|
36
|
+
[DuckDBTypeId_1.DuckDBTypeId.ARRAY]: DuckDBValueConverters_1.arrayFromArrayValue,
|
|
37
|
+
[DuckDBTypeId_1.DuckDBTypeId.UUID]: DuckDBValueConverters_1.stringFromValue,
|
|
38
|
+
[DuckDBTypeId_1.DuckDBTypeId.UNION]: DuckDBValueConverters_1.objectFromUnionValue,
|
|
39
|
+
[DuckDBTypeId_1.DuckDBTypeId.BIT]: DuckDBValueConverters_1.stringFromValue,
|
|
40
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIME_TZ]: DuckDBValueConverters_1.stringFromValue,
|
|
41
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_TZ]: DuckDBValueConverters_1.stringFromValue,
|
|
42
|
+
[DuckDBTypeId_1.DuckDBTypeId.ANY]: DuckDBValueConverters_1.unsupportedConverter,
|
|
43
|
+
[DuckDBTypeId_1.DuckDBTypeId.BIGNUM]: DuckDBValueConverters_1.stringFromValue,
|
|
44
|
+
[DuckDBTypeId_1.DuckDBTypeId.SQLNULL]: DuckDBValueConverters_1.nullConverter,
|
|
45
|
+
[DuckDBTypeId_1.DuckDBTypeId.STRING_LITERAL]: DuckDBValueConverters_1.unsupportedConverter,
|
|
46
|
+
[DuckDBTypeId_1.DuckDBTypeId.INTEGER_LITERAL]: DuckDBValueConverters_1.unsupportedConverter,
|
|
47
|
+
[DuckDBTypeId_1.DuckDBTypeId.TIME_NS]: DuckDBValueConverters_1.stringFromValue,
|
|
48
|
+
};
|
|
49
|
+
exports.JsonDuckDBValueConverter = (0, createDuckDBValueConverter_1.createDuckDBValueConverter)(JsonConvertersByTypeId);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function configurationOptionDescriptions(): Readonly<Record<string, string>>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.configurationOptionDescriptions = configurationOptionDescriptions;
|
|
7
|
+
const node_bindings_1 = __importDefault(require("@haybarn/node-bindings"));
|
|
8
|
+
function configurationOptionDescriptions() {
|
|
9
|
+
const descriptions = {};
|
|
10
|
+
const count = node_bindings_1.default.config_count();
|
|
11
|
+
for (let i = 0; i < count; i++) {
|
|
12
|
+
const { name, description } = node_bindings_1.default.get_config_flag(i);
|
|
13
|
+
descriptions[name] = description;
|
|
14
|
+
}
|
|
15
|
+
return descriptions;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function bytesFromString(str: string): Uint8Array;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare function getDuckDBDateStringFromYearMonthDay(year: number, month: number, dayOfMonth: number): string;
|
|
2
|
+
export declare function getDuckDBDateStringFromDays(days: number): string;
|
|
3
|
+
export declare function getTimezoneOffsetString(timezoneOffsetInMinutes?: number): string | undefined;
|
|
4
|
+
export declare function getAbsoluteOffsetStringFromParts(hoursPart: number, minutesPart: number, secondsPart: number): string;
|
|
5
|
+
export declare function getOffsetStringFromAbsoluteSeconds(absoluteOffsetInSeconds: number): string;
|
|
6
|
+
export declare function getOffsetStringFromSeconds(offsetInSeconds: number): string;
|
|
7
|
+
export declare function getDuckDBTimeStringFromParts(hoursPart: bigint, minutesPart: bigint, secondsPart: bigint, microsecondsPart: bigint): string;
|
|
8
|
+
export declare function getDuckDBTimeStringFromPartsNS(hoursPart: bigint, minutesPart: bigint, secondsPart: bigint, nanosecondsPart: bigint): string;
|
|
9
|
+
export declare function getDuckDBTimeStringFromPositiveMicroseconds(positiveMicroseconds: bigint): string;
|
|
10
|
+
export declare function getDuckDBTimeStringFromPositiveNanoseconds(positiveNanoseconds: bigint): string;
|
|
11
|
+
export declare function getDuckDBTimeStringFromMicrosecondsInDay(microsecondsInDay: bigint): string;
|
|
12
|
+
export declare function getDuckDBTimeStringFromNanosecondsInDay(nanosecondsInDay: bigint): string;
|
|
13
|
+
export declare function getDuckDBTimeStringFromMicroseconds(microseconds: bigint): string;
|
|
14
|
+
export declare function getDuckDBTimestampStringFromDaysAndMicroseconds(days: bigint, microsecondsInDay: bigint, timezonePart?: string): string;
|
|
15
|
+
export declare function getDuckDBTimestampStringFromDaysAndNanoseconds(days: bigint, nanosecondsInDay: bigint): string;
|
|
16
|
+
export declare function getDuckDBTimestampStringFromMicroseconds(microseconds: bigint, timezoneOffsetInMinutes?: number): string;
|
|
17
|
+
export declare function getDuckDBTimestampStringFromSeconds(seconds: bigint): string;
|
|
18
|
+
export declare function getDuckDBTimestampStringFromMilliseconds(milliseconds: bigint): string;
|
|
19
|
+
export declare function getDuckDBTimestampStringFromNanoseconds(nanoseconds: bigint): string;
|
|
20
|
+
export declare function getDuckDBIntervalString(months: number, days: number, microseconds: bigint): string;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDuckDBDateStringFromYearMonthDay = getDuckDBDateStringFromYearMonthDay;
|
|
4
|
+
exports.getDuckDBDateStringFromDays = getDuckDBDateStringFromDays;
|
|
5
|
+
exports.getTimezoneOffsetString = getTimezoneOffsetString;
|
|
6
|
+
exports.getAbsoluteOffsetStringFromParts = getAbsoluteOffsetStringFromParts;
|
|
7
|
+
exports.getOffsetStringFromAbsoluteSeconds = getOffsetStringFromAbsoluteSeconds;
|
|
8
|
+
exports.getOffsetStringFromSeconds = getOffsetStringFromSeconds;
|
|
9
|
+
exports.getDuckDBTimeStringFromParts = getDuckDBTimeStringFromParts;
|
|
10
|
+
exports.getDuckDBTimeStringFromPartsNS = getDuckDBTimeStringFromPartsNS;
|
|
11
|
+
exports.getDuckDBTimeStringFromPositiveMicroseconds = getDuckDBTimeStringFromPositiveMicroseconds;
|
|
12
|
+
exports.getDuckDBTimeStringFromPositiveNanoseconds = getDuckDBTimeStringFromPositiveNanoseconds;
|
|
13
|
+
exports.getDuckDBTimeStringFromMicrosecondsInDay = getDuckDBTimeStringFromMicrosecondsInDay;
|
|
14
|
+
exports.getDuckDBTimeStringFromNanosecondsInDay = getDuckDBTimeStringFromNanosecondsInDay;
|
|
15
|
+
exports.getDuckDBTimeStringFromMicroseconds = getDuckDBTimeStringFromMicroseconds;
|
|
16
|
+
exports.getDuckDBTimestampStringFromDaysAndMicroseconds = getDuckDBTimestampStringFromDaysAndMicroseconds;
|
|
17
|
+
exports.getDuckDBTimestampStringFromDaysAndNanoseconds = getDuckDBTimestampStringFromDaysAndNanoseconds;
|
|
18
|
+
exports.getDuckDBTimestampStringFromMicroseconds = getDuckDBTimestampStringFromMicroseconds;
|
|
19
|
+
exports.getDuckDBTimestampStringFromSeconds = getDuckDBTimestampStringFromSeconds;
|
|
20
|
+
exports.getDuckDBTimestampStringFromMilliseconds = getDuckDBTimestampStringFromMilliseconds;
|
|
21
|
+
exports.getDuckDBTimestampStringFromNanoseconds = getDuckDBTimestampStringFromNanoseconds;
|
|
22
|
+
exports.getDuckDBIntervalString = getDuckDBIntervalString;
|
|
23
|
+
const DAYS_IN_400_YEARS = 146097; // (((365 * 4 + 1) * 25) - 1) * 4 + 1
|
|
24
|
+
const MILLISECONDS_PER_DAY_NUM = 86400000; // 1000 * 60 * 60 * 24
|
|
25
|
+
const MICROSECONDS_PER_SECOND = 1000000n;
|
|
26
|
+
const MICROSECONDS_PER_MILLISECOND = 1000n;
|
|
27
|
+
const NANOSECONDS_PER_SECOND = 1000000000n;
|
|
28
|
+
const SECONDS_PER_MINUTE = 60n;
|
|
29
|
+
const MINUTES_PER_HOUR = 60n;
|
|
30
|
+
const MICROSECONDS_PER_DAY = 86400000000n; // 24 * 60 * 60 * 1000000
|
|
31
|
+
const NANOSECONDS_PER_DAY = 86400000000000n; // 24 * 60 * 60 * 1000000000
|
|
32
|
+
const NEGATIVE_INFINITY_TIMESTAMP = -9223372036854775807n; // -(2^63-1)
|
|
33
|
+
const POSITIVE_INFINITY_TIMESTAMP = 9223372036854775807n; // 2^63-1
|
|
34
|
+
function getDuckDBDateStringFromYearMonthDay(year, month, dayOfMonth) {
|
|
35
|
+
const yearStr = String(Math.abs(year)).padStart(4, '0');
|
|
36
|
+
const monthStr = String(month).padStart(2, '0');
|
|
37
|
+
const dayOfMonthStr = String(dayOfMonth).padStart(2, '0');
|
|
38
|
+
return `${yearStr}-${monthStr}-${dayOfMonthStr}${year < 0 ? ' (BC)' : ''}`;
|
|
39
|
+
}
|
|
40
|
+
function getDuckDBDateStringFromDays(days) {
|
|
41
|
+
const absDays = Math.abs(days);
|
|
42
|
+
const sign = days < 0 ? -1 : 1;
|
|
43
|
+
// 400 years is the shortest interval with a fixed number of days. (Leap years and different length months can result
|
|
44
|
+
// in shorter intervals having different number of days.) By separating the number of 400 year intervals from the
|
|
45
|
+
// interval covered by the remaining days, we can guarantee that the date resulting from shifting the epoch by the
|
|
46
|
+
// remaining interval is within the valid range of the JS Date object. This allows us to use JS Date to calculate the
|
|
47
|
+
// year, month, and day of month for the date represented by the remaining interval, thus accounting for leap years
|
|
48
|
+
// and different length months. We can then safely add back the years from the 400 year intervals, because the month
|
|
49
|
+
// and day of month won't change when a date is shifted by a whole number of such intervals.
|
|
50
|
+
const num400YearIntervals = Math.floor(absDays / DAYS_IN_400_YEARS);
|
|
51
|
+
const yearsFrom400YearIntervals = sign * num400YearIntervals * 400;
|
|
52
|
+
const absDaysFromRemainingInterval = absDays % DAYS_IN_400_YEARS;
|
|
53
|
+
const millisecondsFromRemainingInterval = sign * absDaysFromRemainingInterval * MILLISECONDS_PER_DAY_NUM;
|
|
54
|
+
const date = new Date(millisecondsFromRemainingInterval);
|
|
55
|
+
let year = yearsFrom400YearIntervals + date.getUTCFullYear();
|
|
56
|
+
if (year < 0) {
|
|
57
|
+
year--; // correct for non-existence of year zero
|
|
58
|
+
}
|
|
59
|
+
const month = date.getUTCMonth() + 1; // getUTCMonth returns zero-indexed month, but we want a one-index month for display
|
|
60
|
+
const dayOfMonth = date.getUTCDate(); // getUTCDate returns one-indexed day-of-month
|
|
61
|
+
return getDuckDBDateStringFromYearMonthDay(year, month, dayOfMonth);
|
|
62
|
+
}
|
|
63
|
+
function getTimezoneOffsetString(timezoneOffsetInMinutes) {
|
|
64
|
+
if (timezoneOffsetInMinutes === undefined) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
const negative = timezoneOffsetInMinutes < 0;
|
|
68
|
+
const positiveMinutes = Math.abs(timezoneOffsetInMinutes);
|
|
69
|
+
const minutesPart = positiveMinutes % 60;
|
|
70
|
+
const hoursPart = Math.floor(positiveMinutes / 60);
|
|
71
|
+
const minutesStr = minutesPart !== 0 ? String(minutesPart).padStart(2, '0') : '';
|
|
72
|
+
const hoursStr = String(hoursPart).padStart(2, '0');
|
|
73
|
+
return `${negative ? '-' : '+'}${hoursStr}${minutesStr ? `:${minutesStr}` : ''}`;
|
|
74
|
+
}
|
|
75
|
+
function getAbsoluteOffsetStringFromParts(hoursPart, minutesPart, secondsPart) {
|
|
76
|
+
const hoursStr = String(hoursPart).padStart(2, '0');
|
|
77
|
+
const minutesStr = minutesPart !== 0 || secondsPart !== 0
|
|
78
|
+
? String(minutesPart).padStart(2, '0')
|
|
79
|
+
: '';
|
|
80
|
+
const secondsStr = secondsPart !== 0 ? String(secondsPart).padStart(2, '0') : '';
|
|
81
|
+
let result = hoursStr;
|
|
82
|
+
if (minutesStr) {
|
|
83
|
+
result += `:${minutesStr}`;
|
|
84
|
+
if (secondsStr) {
|
|
85
|
+
result += `:${secondsStr}`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
function getOffsetStringFromAbsoluteSeconds(absoluteOffsetInSeconds) {
|
|
91
|
+
const secondsPart = absoluteOffsetInSeconds % 60;
|
|
92
|
+
const minutes = Math.floor(absoluteOffsetInSeconds / 60);
|
|
93
|
+
const minutesPart = minutes % 60;
|
|
94
|
+
const hoursPart = Math.floor(minutes / 60);
|
|
95
|
+
return getAbsoluteOffsetStringFromParts(hoursPart, minutesPart, secondsPart);
|
|
96
|
+
}
|
|
97
|
+
function getOffsetStringFromSeconds(offsetInSeconds) {
|
|
98
|
+
const negative = offsetInSeconds < 0;
|
|
99
|
+
const absoluteOffsetInSeconds = negative ? -offsetInSeconds : offsetInSeconds;
|
|
100
|
+
const absoluteString = getOffsetStringFromAbsoluteSeconds(absoluteOffsetInSeconds);
|
|
101
|
+
return `${negative ? '-' : '+'}${absoluteString}`;
|
|
102
|
+
}
|
|
103
|
+
function getDuckDBTimeStringFromParts(hoursPart, minutesPart, secondsPart, microsecondsPart) {
|
|
104
|
+
const hoursStr = String(hoursPart).padStart(2, '0');
|
|
105
|
+
const minutesStr = String(minutesPart).padStart(2, '0');
|
|
106
|
+
const secondsStr = String(secondsPart).padStart(2, '0');
|
|
107
|
+
const microsecondsStr = String(microsecondsPart)
|
|
108
|
+
.padStart(6, '0')
|
|
109
|
+
.replace(/0+$/, '');
|
|
110
|
+
return `${hoursStr}:${minutesStr}:${secondsStr}${microsecondsStr.length > 0 ? `.${microsecondsStr}` : ''}`;
|
|
111
|
+
}
|
|
112
|
+
function getDuckDBTimeStringFromPartsNS(hoursPart, minutesPart, secondsPart, nanosecondsPart) {
|
|
113
|
+
const hoursStr = String(hoursPart).padStart(2, '0');
|
|
114
|
+
const minutesStr = String(minutesPart).padStart(2, '0');
|
|
115
|
+
const secondsStr = String(secondsPart).padStart(2, '0');
|
|
116
|
+
const nanosecondsStr = String(nanosecondsPart)
|
|
117
|
+
.padStart(9, '0')
|
|
118
|
+
.replace(/0+$/, '');
|
|
119
|
+
return `${hoursStr}:${minutesStr}:${secondsStr}${nanosecondsStr.length > 0 ? `.${nanosecondsStr}` : ''}`;
|
|
120
|
+
}
|
|
121
|
+
function getDuckDBTimeStringFromPositiveMicroseconds(positiveMicroseconds) {
|
|
122
|
+
const microsecondsPart = positiveMicroseconds % MICROSECONDS_PER_SECOND;
|
|
123
|
+
const seconds = positiveMicroseconds / MICROSECONDS_PER_SECOND;
|
|
124
|
+
const secondsPart = seconds % SECONDS_PER_MINUTE;
|
|
125
|
+
const minutes = seconds / SECONDS_PER_MINUTE;
|
|
126
|
+
const minutesPart = minutes % MINUTES_PER_HOUR;
|
|
127
|
+
const hoursPart = minutes / MINUTES_PER_HOUR;
|
|
128
|
+
return getDuckDBTimeStringFromParts(hoursPart, minutesPart, secondsPart, microsecondsPart);
|
|
129
|
+
}
|
|
130
|
+
function getDuckDBTimeStringFromPositiveNanoseconds(positiveNanoseconds) {
|
|
131
|
+
const nanosecondsPart = positiveNanoseconds % NANOSECONDS_PER_SECOND;
|
|
132
|
+
const seconds = positiveNanoseconds / NANOSECONDS_PER_SECOND;
|
|
133
|
+
const secondsPart = seconds % SECONDS_PER_MINUTE;
|
|
134
|
+
const minutes = seconds / SECONDS_PER_MINUTE;
|
|
135
|
+
const minutesPart = minutes % MINUTES_PER_HOUR;
|
|
136
|
+
const hoursPart = minutes / MINUTES_PER_HOUR;
|
|
137
|
+
return getDuckDBTimeStringFromPartsNS(hoursPart, minutesPart, secondsPart, nanosecondsPart);
|
|
138
|
+
}
|
|
139
|
+
function getDuckDBTimeStringFromMicrosecondsInDay(microsecondsInDay) {
|
|
140
|
+
const positiveMicroseconds = microsecondsInDay < 0
|
|
141
|
+
? microsecondsInDay + MICROSECONDS_PER_DAY
|
|
142
|
+
: microsecondsInDay;
|
|
143
|
+
return getDuckDBTimeStringFromPositiveMicroseconds(positiveMicroseconds);
|
|
144
|
+
}
|
|
145
|
+
function getDuckDBTimeStringFromNanosecondsInDay(nanosecondsInDay) {
|
|
146
|
+
const positiveNanoseconds = nanosecondsInDay < 0
|
|
147
|
+
? nanosecondsInDay + NANOSECONDS_PER_DAY
|
|
148
|
+
: nanosecondsInDay;
|
|
149
|
+
return getDuckDBTimeStringFromPositiveNanoseconds(positiveNanoseconds);
|
|
150
|
+
}
|
|
151
|
+
function getDuckDBTimeStringFromMicroseconds(microseconds) {
|
|
152
|
+
const negative = microseconds < 0;
|
|
153
|
+
const positiveMicroseconds = negative ? -microseconds : microseconds;
|
|
154
|
+
const positiveString = getDuckDBTimeStringFromPositiveMicroseconds(positiveMicroseconds);
|
|
155
|
+
return negative ? `-${positiveString}` : positiveString;
|
|
156
|
+
}
|
|
157
|
+
function getDuckDBTimestampStringFromDaysAndMicroseconds(days, microsecondsInDay, timezonePart) {
|
|
158
|
+
// This conversion of BigInt to Number is safe, because the largest absolute value that `days` can has is 106751991,
|
|
159
|
+
// which fits without loss of precision in a JS Number. (106751991 = (2^63-1) / MICROSECONDS_PER_DAY)
|
|
160
|
+
const dateStr = getDuckDBDateStringFromDays(Number(days));
|
|
161
|
+
const timeStr = getDuckDBTimeStringFromMicrosecondsInDay(microsecondsInDay);
|
|
162
|
+
return `${dateStr} ${timeStr}${timezonePart ?? ''}`;
|
|
163
|
+
}
|
|
164
|
+
function getDuckDBTimestampStringFromDaysAndNanoseconds(days, nanosecondsInDay) {
|
|
165
|
+
// This conversion of BigInt to Number is safe, because the largest absolute value that `days` can has is 106751
|
|
166
|
+
// which fits without loss of precision in a JS Number. (106751 = (2^63-1) / NANOSECONDS_PER_DAY)
|
|
167
|
+
const dateStr = getDuckDBDateStringFromDays(Number(days));
|
|
168
|
+
const timeStr = getDuckDBTimeStringFromNanosecondsInDay(nanosecondsInDay);
|
|
169
|
+
return `${dateStr} ${timeStr}`;
|
|
170
|
+
}
|
|
171
|
+
function getDuckDBTimestampStringFromMicroseconds(microseconds, timezoneOffsetInMinutes) {
|
|
172
|
+
// Note that -infinity and infinity are only representable in TIMESTAMP (and TIMESTAMPTZ), not the other timestamp
|
|
173
|
+
// variants. This is by-design and matches DuckDB.
|
|
174
|
+
if (microseconds === NEGATIVE_INFINITY_TIMESTAMP) {
|
|
175
|
+
return '-infinity';
|
|
176
|
+
}
|
|
177
|
+
if (microseconds === POSITIVE_INFINITY_TIMESTAMP) {
|
|
178
|
+
return 'infinity';
|
|
179
|
+
}
|
|
180
|
+
const offsetMicroseconds = timezoneOffsetInMinutes !== undefined
|
|
181
|
+
? microseconds +
|
|
182
|
+
BigInt(timezoneOffsetInMinutes) *
|
|
183
|
+
MICROSECONDS_PER_SECOND *
|
|
184
|
+
SECONDS_PER_MINUTE
|
|
185
|
+
: microseconds;
|
|
186
|
+
let days = offsetMicroseconds / MICROSECONDS_PER_DAY;
|
|
187
|
+
let microsecondsPart = offsetMicroseconds % MICROSECONDS_PER_DAY;
|
|
188
|
+
if (microsecondsPart < 0) {
|
|
189
|
+
days--;
|
|
190
|
+
microsecondsPart += MICROSECONDS_PER_DAY;
|
|
191
|
+
}
|
|
192
|
+
return getDuckDBTimestampStringFromDaysAndMicroseconds(days, microsecondsPart, getTimezoneOffsetString(timezoneOffsetInMinutes));
|
|
193
|
+
}
|
|
194
|
+
function getDuckDBTimestampStringFromSeconds(seconds) {
|
|
195
|
+
return getDuckDBTimestampStringFromMicroseconds(seconds * MICROSECONDS_PER_SECOND);
|
|
196
|
+
}
|
|
197
|
+
function getDuckDBTimestampStringFromMilliseconds(milliseconds) {
|
|
198
|
+
return getDuckDBTimestampStringFromMicroseconds(milliseconds * MICROSECONDS_PER_MILLISECOND);
|
|
199
|
+
}
|
|
200
|
+
function getDuckDBTimestampStringFromNanoseconds(nanoseconds) {
|
|
201
|
+
let days = nanoseconds / NANOSECONDS_PER_DAY;
|
|
202
|
+
let nanosecondsPart = nanoseconds % NANOSECONDS_PER_DAY;
|
|
203
|
+
if (nanosecondsPart < 0) {
|
|
204
|
+
days--;
|
|
205
|
+
nanosecondsPart += NANOSECONDS_PER_DAY;
|
|
206
|
+
}
|
|
207
|
+
return getDuckDBTimestampStringFromDaysAndNanoseconds(days, nanosecondsPart);
|
|
208
|
+
}
|
|
209
|
+
// Assumes baseUnit can be pluralized by adding an 's'.
|
|
210
|
+
function numberAndUnit(value, baseUnit) {
|
|
211
|
+
return `${value} ${baseUnit}${Math.abs(value) !== 1 ? 's' : ''}`;
|
|
212
|
+
}
|
|
213
|
+
function getDuckDBIntervalString(months, days, microseconds) {
|
|
214
|
+
const parts = [];
|
|
215
|
+
if (months !== 0) {
|
|
216
|
+
const sign = months < 0 ? -1 : 1;
|
|
217
|
+
const absMonths = Math.abs(months);
|
|
218
|
+
const absYears = Math.floor(absMonths / 12);
|
|
219
|
+
const years = sign * absYears;
|
|
220
|
+
const extraMonths = sign * (absMonths - absYears * 12);
|
|
221
|
+
if (years !== 0) {
|
|
222
|
+
parts.push(numberAndUnit(years, 'year'));
|
|
223
|
+
}
|
|
224
|
+
if (extraMonths !== 0) {
|
|
225
|
+
parts.push(numberAndUnit(extraMonths, 'month'));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (days !== 0) {
|
|
229
|
+
parts.push(numberAndUnit(days, 'day'));
|
|
230
|
+
}
|
|
231
|
+
if (microseconds !== 0n) {
|
|
232
|
+
parts.push(getDuckDBTimeStringFromMicroseconds(microseconds));
|
|
233
|
+
}
|
|
234
|
+
if (parts.length > 0) {
|
|
235
|
+
return parts.join(' ');
|
|
236
|
+
}
|
|
237
|
+
return '00:00:00';
|
|
238
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.displayStringForDuckDBValue = displayStringForDuckDBValue;
|
|
4
|
+
const sql_1 = require("../sql");
|
|
5
|
+
function displayStringForDuckDBValue(value) {
|
|
6
|
+
if (value == null) {
|
|
7
|
+
return 'NULL';
|
|
8
|
+
}
|
|
9
|
+
if (typeof value === 'string') {
|
|
10
|
+
return (0, sql_1.quotedString)(value);
|
|
11
|
+
}
|
|
12
|
+
return value.toString();
|
|
13
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Matches BLOB-to-VARCHAR conversion behavior of DuckDB. */
|
|
2
|
+
export declare function stringFromBlob(bytes: Uint8Array): string;
|
|
3
|
+
export declare function stringFromBlobStringConcat(bytes: Uint8Array): string;
|
|
4
|
+
export declare function stringFromBlobArrayJoin(bytes: Uint8Array): string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringFromBlob = stringFromBlob;
|
|
4
|
+
exports.stringFromBlobStringConcat = stringFromBlobStringConcat;
|
|
5
|
+
exports.stringFromBlobArrayJoin = stringFromBlobArrayJoin;
|
|
6
|
+
/** Matches BLOB-to-VARCHAR conversion behavior of DuckDB. */
|
|
7
|
+
function stringFromBlob(bytes) {
|
|
8
|
+
// String concatenation appears to be faster for this function at smaller sizes.
|
|
9
|
+
// Threshold of (2^16) experimentally determined on a MacBook Pro (M2 Max).
|
|
10
|
+
// See stringFromBlob.bench.ts.
|
|
11
|
+
if (bytes.length <= 65536) {
|
|
12
|
+
return stringFromBlobStringConcat(bytes);
|
|
13
|
+
}
|
|
14
|
+
return stringFromBlobArrayJoin(bytes);
|
|
15
|
+
}
|
|
16
|
+
function stringFromBlobStringConcat(bytes) {
|
|
17
|
+
let byteString = '';
|
|
18
|
+
for (const byte of bytes) {
|
|
19
|
+
if (byte <= 0x1f ||
|
|
20
|
+
byte === 0x22 /* double quote */ ||
|
|
21
|
+
byte === 0x27 /* single quote */ ||
|
|
22
|
+
byte >= 0x7f) {
|
|
23
|
+
byteString += `\\x${byte.toString(16).toUpperCase().padStart(2, '0')}`;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
byteString += String.fromCharCode(byte);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return byteString;
|
|
30
|
+
}
|
|
31
|
+
function stringFromBlobArrayJoin(bytes) {
|
|
32
|
+
const byteStrings = [];
|
|
33
|
+
for (const byte of bytes) {
|
|
34
|
+
if (byte <= 0x1f ||
|
|
35
|
+
byte === 0x22 /* double quote */ ||
|
|
36
|
+
byte === 0x27 /* single quote */ ||
|
|
37
|
+
byte >= 0x7f) {
|
|
38
|
+
byteStrings.push(`\\x${byte.toString(16).toUpperCase().padStart(2, '0')}`);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
byteStrings.push(String.fromCharCode(byte));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return byteStrings.join('');
|
|
45
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decimal string formatting.
|
|
3
|
+
*
|
|
4
|
+
* Supports a subset of the functionality of `BigInt.prototype.toLocaleString` for locale-specific formatting.
|
|
5
|
+
*/
|
|
6
|
+
export interface DuckDBDecimalFormatOptions {
|
|
7
|
+
useGrouping?: boolean;
|
|
8
|
+
minimumFractionDigits?: number;
|
|
9
|
+
maximumFractionDigits?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface LocaleOptions {
|
|
12
|
+
locales?: string | string[];
|
|
13
|
+
options?: DuckDBDecimalFormatOptions;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Convert a scaled decimal value to a string, possibly using locale-specific formatting.
|
|
17
|
+
*/
|
|
18
|
+
export declare function stringFromDecimal(scaledValue: bigint, scale: number, localeOptions?: LocaleOptions): string;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Decimal string formatting.
|
|
4
|
+
*
|
|
5
|
+
* Supports a subset of the functionality of `BigInt.prototype.toLocaleString` for locale-specific formatting.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.stringFromDecimal = stringFromDecimal;
|
|
9
|
+
/*
|
|
10
|
+
* Get the decimal separator for a given locale.
|
|
11
|
+
* Somewhat expensive, so use getCachedDecimalSeparator if you need to call this multiple times.
|
|
12
|
+
*/
|
|
13
|
+
function getDecimalSeparator(locales) {
|
|
14
|
+
const decimalSeparator = new Intl.NumberFormat(locales, { useGrouping: false })
|
|
15
|
+
.formatToParts(0.1)
|
|
16
|
+
.find((part) => part.type === 'decimal')?.value ?? '.';
|
|
17
|
+
return decimalSeparator;
|
|
18
|
+
}
|
|
19
|
+
/*
|
|
20
|
+
* Get the decimal separator for a given locale, and cache the result.
|
|
21
|
+
*/
|
|
22
|
+
const cachedDecimalSeparators = {};
|
|
23
|
+
function getCachedDecimalSeparator(locales) {
|
|
24
|
+
const cacheKey = JSON.stringify(locales);
|
|
25
|
+
if (cacheKey in cachedDecimalSeparators) {
|
|
26
|
+
return cachedDecimalSeparators[cacheKey];
|
|
27
|
+
}
|
|
28
|
+
const decimalSeparator = getDecimalSeparator(locales);
|
|
29
|
+
cachedDecimalSeparators[cacheKey] = decimalSeparator;
|
|
30
|
+
return decimalSeparator;
|
|
31
|
+
}
|
|
32
|
+
// Helper function to format whole part of a decimal value.
|
|
33
|
+
// Note that we explicitly omit 'minimumFractionDigits' and 'maximumFractionDigits' from the options
|
|
34
|
+
// passed to toLocaleString, because they are only relevant for the fractional part of the number, and
|
|
35
|
+
// would result in formatting the whole part as a real number, which we don't want.
|
|
36
|
+
function formatWholePart(localeOptions, val) {
|
|
37
|
+
if (localeOptions) {
|
|
38
|
+
const { minimumFractionDigits: _minFD, maximumFractionDigits: _maxFD, ...restOptions } = localeOptions.options ?? {};
|
|
39
|
+
return val.toLocaleString(localeOptions?.locales, restOptions);
|
|
40
|
+
}
|
|
41
|
+
return String(val);
|
|
42
|
+
}
|
|
43
|
+
// Format the fractional part of a decimal value
|
|
44
|
+
// Note that we must handle minimumFractionDigits and maximumFractionDigits ourselves, and that
|
|
45
|
+
// we don't apply `useGrouping` because that only applies to the whole part of the number.
|
|
46
|
+
function formatFractionalPart(localeOptions, val, scale) {
|
|
47
|
+
const fractionalPartStr = String(val).padStart(scale, '0');
|
|
48
|
+
if (!localeOptions) {
|
|
49
|
+
return fractionalPartStr;
|
|
50
|
+
}
|
|
51
|
+
const minFracDigits = localeOptions?.options?.minimumFractionDigits ?? 0;
|
|
52
|
+
const maxFracDigits = localeOptions?.options?.maximumFractionDigits ?? 20;
|
|
53
|
+
return fractionalPartStr.padEnd(minFracDigits, '0').slice(0, maxFracDigits);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Convert a scaled decimal value to a string, possibly using locale-specific formatting.
|
|
57
|
+
*/
|
|
58
|
+
function stringFromDecimal(scaledValue, scale, localeOptions) {
|
|
59
|
+
// Decimal values are represented as integers that have been scaled up by a power of ten. The `scale` property of
|
|
60
|
+
// the type is the exponent of the scale factor. For a scale greater than zero, we need to separate out the
|
|
61
|
+
// fractional part by reversing this scaling.
|
|
62
|
+
if (scale > 0) {
|
|
63
|
+
const scaleFactor = BigInt(10) ** BigInt(scale);
|
|
64
|
+
const absScaledValue = scaledValue < 0 ? -scaledValue : scaledValue;
|
|
65
|
+
const prefix = scaledValue < 0 ? '-' : '';
|
|
66
|
+
const wholePartNum = absScaledValue / scaleFactor;
|
|
67
|
+
const wholePartStr = formatWholePart(localeOptions, wholePartNum);
|
|
68
|
+
const fractionalPartNum = absScaledValue % scaleFactor;
|
|
69
|
+
const fractionalPartStr = formatFractionalPart(localeOptions, fractionalPartNum, scale);
|
|
70
|
+
const decimalSeparatorStr = localeOptions
|
|
71
|
+
? getCachedDecimalSeparator(localeOptions.locales)
|
|
72
|
+
: '.';
|
|
73
|
+
return `${prefix}${wholePartStr}${decimalSeparatorStr}${fractionalPartStr}`;
|
|
74
|
+
}
|
|
75
|
+
// For a scale of zero, there is no fractional part, so a direct string conversion works.
|
|
76
|
+
if (localeOptions) {
|
|
77
|
+
return scaledValue.toLocaleString(localeOptions?.locales, localeOptions?.options);
|
|
78
|
+
}
|
|
79
|
+
return String(scaledValue);
|
|
80
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertColumnsFromChunks = convertColumnsFromChunks;
|
|
4
|
+
function convertColumnsFromChunks(chunks, converter) {
|
|
5
|
+
if (chunks.length === 0) {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
|
+
const convertedColumns = chunks[0].convertColumns(converter);
|
|
9
|
+
for (let chunkIndex = 1; chunkIndex < chunks.length; chunkIndex++) {
|
|
10
|
+
for (let columnIndex = 0; columnIndex < convertedColumns.length; columnIndex++) {
|
|
11
|
+
const chunk = chunks[chunkIndex];
|
|
12
|
+
chunk.visitColumnValues(columnIndex, (value, _rowIndex, _columnIndex, type) => convertedColumns[columnIndex].push(converter(value, type, converter)));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return convertedColumns;
|
|
16
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DuckDBDataChunk } from './DuckDBDataChunk';
|
|
2
|
+
import { DuckDBValueConverter } from './DuckDBValueConverter';
|
|
3
|
+
export declare function convertColumnsObjectFromChunks<T>(chunks: readonly DuckDBDataChunk[], columnNames: readonly string[], converter: DuckDBValueConverter<T>): Record<string, (T | null)[]>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertColumnsObjectFromChunks = convertColumnsObjectFromChunks;
|
|
4
|
+
function convertColumnsObjectFromChunks(chunks, columnNames, converter) {
|
|
5
|
+
const convertedColumnsObject = {};
|
|
6
|
+
for (const columnName of columnNames) {
|
|
7
|
+
convertedColumnsObject[columnName] = [];
|
|
8
|
+
}
|
|
9
|
+
if (chunks.length === 0) {
|
|
10
|
+
return convertedColumnsObject;
|
|
11
|
+
}
|
|
12
|
+
const columnCount = chunks[0].columnCount;
|
|
13
|
+
for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
|
|
14
|
+
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
15
|
+
chunks[chunkIndex].visitColumnValues(columnIndex, (value, _rowIndex, _columnIndex, type) => convertedColumnsObject[columnNames[columnIndex]].push(converter(value, type, converter)));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return convertedColumnsObject;
|
|
19
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DuckDBDataChunk } from './DuckDBDataChunk';
|
|
2
|
+
import { DuckDBValueConverter } from './DuckDBValueConverter';
|
|
3
|
+
export declare function convertRowObjectsFromChunks<T>(chunks: readonly DuckDBDataChunk[], columnNames: readonly string[], converter: DuckDBValueConverter<T>): Record<string, T | null>[];
|