@duckdb/node-api 1.1.3-alpha.9 → 1.2.0-alpha.14
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/README.md +414 -13
- package/lib/DuckDBConnection.d.ts +10 -10
- package/lib/DuckDBDataChunk.d.ts +14 -2
- package/lib/DuckDBDataChunk.js +79 -18
- package/lib/DuckDBLogicalType.d.ts +1 -1
- package/lib/DuckDBLogicalType.js +1 -1
- package/lib/DuckDBPreparedStatement.d.ts +2 -1
- package/lib/DuckDBPreparedStatement.js +9 -1
- package/lib/DuckDBResult.d.ts +8 -0
- package/lib/DuckDBResult.js +52 -35
- package/lib/DuckDBResultReader.d.ts +8 -0
- package/lib/DuckDBResultReader.js +34 -36
- package/lib/DuckDBType.d.ts +10 -0
- package/lib/DuckDBType.js +33 -0
- package/lib/DuckDBValueConverter.d.ts +5 -0
- package/lib/DuckDBValueConverter.js +2 -0
- package/lib/DuckDBValueToJsonConverter.d.ts +10 -0
- package/lib/DuckDBValueToJsonConverter.js +101 -0
- package/lib/DuckDBVector.js +2 -2
- package/lib/conversion/dateTimeStringConversion.d.ts +10 -6
- package/lib/conversion/dateTimeStringConversion.js +64 -16
- 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/createValue.js +10 -1
- package/lib/getColumnsFromChunks.d.ts +3 -0
- package/lib/getColumnsFromChunks.js +16 -0
- package/lib/getColumnsObjectFromChunks.d.ts +3 -0
- package/lib/getColumnsObjectFromChunks.js +19 -0
- package/lib/getRowObjectsFromChunks.d.ts +3 -0
- package/lib/getRowObjectsFromChunks.js +17 -0
- package/lib/getRowsFromChunks.d.ts +3 -0
- package/lib/getRowsFromChunks.js +10 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/typeForValue.js +6 -1
- package/lib/values/DuckDBTimeTZValue.d.ts +10 -10
- package/lib/values/DuckDBTimeTZValue.js +16 -15
- package/lib/values/DuckDBTimestampMillisecondsValue.d.ts +8 -4
- package/lib/values/DuckDBTimestampMillisecondsValue.js +15 -6
- package/lib/values/DuckDBTimestampNanosecondsValue.d.ts +8 -4
- package/lib/values/DuckDBTimestampNanosecondsValue.js +15 -6
- package/lib/values/DuckDBTimestampSecondsValue.d.ts +5 -1
- package/lib/values/DuckDBTimestampSecondsValue.js +9 -0
- package/lib/values/DuckDBTimestampTZValue.d.ts +2 -0
- package/lib/values/DuckDBTimestampTZValue.js +5 -2
- package/lib/values/DuckDBTimestampValue.d.ts +1 -0
- package/lib/values/DuckDBTimestampValue.js +4 -1
- package/package.json +3 -2
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DuckDBValueToJsonConverter = void 0;
|
|
4
|
+
const DuckDBTypeId_1 = require("./DuckDBTypeId");
|
|
5
|
+
const values_1 = require("./values");
|
|
6
|
+
class DuckDBValueToJsonConverter {
|
|
7
|
+
static default = new DuckDBValueToJsonConverter();
|
|
8
|
+
convertValue(value, type) {
|
|
9
|
+
if (value == null) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
switch (type.typeId) {
|
|
13
|
+
case DuckDBTypeId_1.DuckDBTypeId.BOOLEAN:
|
|
14
|
+
return Boolean(value);
|
|
15
|
+
case DuckDBTypeId_1.DuckDBTypeId.TINYINT:
|
|
16
|
+
case DuckDBTypeId_1.DuckDBTypeId.SMALLINT:
|
|
17
|
+
case DuckDBTypeId_1.DuckDBTypeId.INTEGER:
|
|
18
|
+
case DuckDBTypeId_1.DuckDBTypeId.UTINYINT:
|
|
19
|
+
case DuckDBTypeId_1.DuckDBTypeId.USMALLINT:
|
|
20
|
+
case DuckDBTypeId_1.DuckDBTypeId.UINTEGER:
|
|
21
|
+
return Number(value);
|
|
22
|
+
case DuckDBTypeId_1.DuckDBTypeId.FLOAT:
|
|
23
|
+
case DuckDBTypeId_1.DuckDBTypeId.DOUBLE:
|
|
24
|
+
if (Number.isFinite(value)) {
|
|
25
|
+
return Number(value);
|
|
26
|
+
}
|
|
27
|
+
return String(value);
|
|
28
|
+
case DuckDBTypeId_1.DuckDBTypeId.BIGINT:
|
|
29
|
+
case DuckDBTypeId_1.DuckDBTypeId.UBIGINT:
|
|
30
|
+
case DuckDBTypeId_1.DuckDBTypeId.HUGEINT:
|
|
31
|
+
case DuckDBTypeId_1.DuckDBTypeId.UHUGEINT:
|
|
32
|
+
return String(value);
|
|
33
|
+
case DuckDBTypeId_1.DuckDBTypeId.DATE:
|
|
34
|
+
case DuckDBTypeId_1.DuckDBTypeId.TIME:
|
|
35
|
+
case DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP:
|
|
36
|
+
case DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_S:
|
|
37
|
+
case DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_MS:
|
|
38
|
+
case DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_NS:
|
|
39
|
+
case DuckDBTypeId_1.DuckDBTypeId.TIME_TZ:
|
|
40
|
+
case DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_TZ:
|
|
41
|
+
return String(value);
|
|
42
|
+
case DuckDBTypeId_1.DuckDBTypeId.INTERVAL:
|
|
43
|
+
if (value instanceof values_1.DuckDBIntervalValue) {
|
|
44
|
+
return {
|
|
45
|
+
months: value.months,
|
|
46
|
+
days: value.days,
|
|
47
|
+
micros: String(value.micros),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
case DuckDBTypeId_1.DuckDBTypeId.VARCHAR:
|
|
52
|
+
case DuckDBTypeId_1.DuckDBTypeId.BLOB:
|
|
53
|
+
case DuckDBTypeId_1.DuckDBTypeId.BIT:
|
|
54
|
+
return String(value);
|
|
55
|
+
case DuckDBTypeId_1.DuckDBTypeId.DECIMAL:
|
|
56
|
+
case DuckDBTypeId_1.DuckDBTypeId.VARINT:
|
|
57
|
+
return String(value);
|
|
58
|
+
case DuckDBTypeId_1.DuckDBTypeId.ENUM:
|
|
59
|
+
return String(value);
|
|
60
|
+
case DuckDBTypeId_1.DuckDBTypeId.LIST:
|
|
61
|
+
if (value instanceof values_1.DuckDBListValue) {
|
|
62
|
+
return value.items.map((v) => this.convertValue(v, type.valueType));
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
case DuckDBTypeId_1.DuckDBTypeId.STRUCT:
|
|
66
|
+
if (value instanceof values_1.DuckDBStructValue) {
|
|
67
|
+
const result = {};
|
|
68
|
+
for (const key in value.entries) {
|
|
69
|
+
result[key] = this.convertValue(value.entries[key], type.typeForEntry(key));
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
case DuckDBTypeId_1.DuckDBTypeId.MAP:
|
|
75
|
+
if (value instanceof values_1.DuckDBMapValue) {
|
|
76
|
+
return value.entries.map((entry) => ({
|
|
77
|
+
key: this.convertValue(entry.key, type.keyType),
|
|
78
|
+
value: this.convertValue(entry.value, type.valueType),
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
case DuckDBTypeId_1.DuckDBTypeId.ARRAY:
|
|
83
|
+
if (value instanceof values_1.DuckDBArrayValue) {
|
|
84
|
+
return value.items.map((v) => this.convertValue(v, type.valueType));
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
case DuckDBTypeId_1.DuckDBTypeId.UNION:
|
|
88
|
+
if (value instanceof values_1.DuckDBUnionValue) {
|
|
89
|
+
return {
|
|
90
|
+
tag: value.tag,
|
|
91
|
+
value: this.convertValue(value.value, type.memberTypeForTag(value.tag)),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
case DuckDBTypeId_1.DuckDBTypeId.UUID:
|
|
96
|
+
return String(value);
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.DuckDBValueToJsonConverter = DuckDBValueToJsonConverter;
|
package/lib/DuckDBVector.js
CHANGED
|
@@ -1628,7 +1628,7 @@ class DuckDBTimestampMillisecondsVector extends DuckDBVector {
|
|
|
1628
1628
|
}
|
|
1629
1629
|
setItem(itemIndex, value) {
|
|
1630
1630
|
if (value != null) {
|
|
1631
|
-
this.items[itemIndex] = value.
|
|
1631
|
+
this.items[itemIndex] = value.millis;
|
|
1632
1632
|
this.validity.setItemValid(itemIndex, true);
|
|
1633
1633
|
}
|
|
1634
1634
|
else {
|
|
@@ -1673,7 +1673,7 @@ class DuckDBTimestampNanosecondsVector extends DuckDBVector {
|
|
|
1673
1673
|
}
|
|
1674
1674
|
setItem(itemIndex, value) {
|
|
1675
1675
|
if (value != null) {
|
|
1676
|
-
this.items[itemIndex] = value.
|
|
1676
|
+
this.items[itemIndex] = value.nanos;
|
|
1677
1677
|
this.validity.setItemValid(itemIndex, true);
|
|
1678
1678
|
}
|
|
1679
1679
|
else {
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export declare function getDuckDBDateStringFromYearMonthDay(year: number, month: number, dayOfMonth: number): string;
|
|
2
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;
|
|
3
7
|
export declare function getDuckDBTimeStringFromParts(hoursPart: bigint, minutesPart: bigint, secondsPart: bigint, microsecondsPart: bigint): string;
|
|
4
8
|
export declare function getDuckDBTimeStringFromPartsNS(hoursPart: bigint, minutesPart: bigint, secondsPart: bigint, nanosecondsPart: bigint): string;
|
|
5
9
|
export declare function getDuckDBTimeStringFromPositiveMicroseconds(positiveMicroseconds: bigint): string;
|
|
@@ -7,10 +11,10 @@ export declare function getDuckDBTimeStringFromPositiveNanoseconds(positiveNanos
|
|
|
7
11
|
export declare function getDuckDBTimeStringFromMicrosecondsInDay(microsecondsInDay: bigint): string;
|
|
8
12
|
export declare function getDuckDBTimeStringFromNanosecondsInDay(nanosecondsInDay: bigint): string;
|
|
9
13
|
export declare function getDuckDBTimeStringFromMicroseconds(microseconds: bigint): string;
|
|
10
|
-
export declare function getDuckDBTimestampStringFromDaysAndMicroseconds(days: bigint, microsecondsInDay: bigint,
|
|
11
|
-
export declare function getDuckDBTimestampStringFromDaysAndNanoseconds(days: bigint, nanosecondsInDay: bigint
|
|
12
|
-
export declare function getDuckDBTimestampStringFromMicroseconds(microseconds: bigint,
|
|
13
|
-
export declare function getDuckDBTimestampStringFromSeconds(seconds: bigint
|
|
14
|
-
export declare function getDuckDBTimestampStringFromMilliseconds(milliseconds: bigint
|
|
15
|
-
export declare function getDuckDBTimestampStringFromNanoseconds(nanoseconds: bigint
|
|
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;
|
|
16
20
|
export declare function getDuckDBIntervalString(months: number, days: number, microseconds: bigint): string;
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDuckDBDateStringFromYearMonthDay = getDuckDBDateStringFromYearMonthDay;
|
|
4
4
|
exports.getDuckDBDateStringFromDays = getDuckDBDateStringFromDays;
|
|
5
|
+
exports.getTimezoneOffsetString = getTimezoneOffsetString;
|
|
6
|
+
exports.getAbsoluteOffsetStringFromParts = getAbsoluteOffsetStringFromParts;
|
|
7
|
+
exports.getOffsetStringFromAbsoluteSeconds = getOffsetStringFromAbsoluteSeconds;
|
|
8
|
+
exports.getOffsetStringFromSeconds = getOffsetStringFromSeconds;
|
|
5
9
|
exports.getDuckDBTimeStringFromParts = getDuckDBTimeStringFromParts;
|
|
6
10
|
exports.getDuckDBTimeStringFromPartsNS = getDuckDBTimeStringFromPartsNS;
|
|
7
11
|
exports.getDuckDBTimeStringFromPositiveMicroseconds = getDuckDBTimeStringFromPositiveMicroseconds;
|
|
@@ -56,6 +60,46 @@ function getDuckDBDateStringFromDays(days) {
|
|
|
56
60
|
const dayOfMonth = date.getUTCDate(); // getUTCDate returns one-indexed day-of-month
|
|
57
61
|
return getDuckDBDateStringFromYearMonthDay(year, month, dayOfMonth);
|
|
58
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
|
+
}
|
|
59
103
|
function getDuckDBTimeStringFromParts(hoursPart, minutesPart, secondsPart, microsecondsPart) {
|
|
60
104
|
const hoursStr = String(hoursPart).padStart(2, '0');
|
|
61
105
|
const minutesStr = String(minutesPart).padStart(2, '0');
|
|
@@ -110,23 +154,21 @@ function getDuckDBTimeStringFromMicroseconds(microseconds) {
|
|
|
110
154
|
const positiveString = getDuckDBTimeStringFromPositiveMicroseconds(positiveMicroseconds);
|
|
111
155
|
return negative ? `-${positiveString}` : positiveString;
|
|
112
156
|
}
|
|
113
|
-
function getDuckDBTimestampStringFromDaysAndMicroseconds(days, microsecondsInDay,
|
|
157
|
+
function getDuckDBTimestampStringFromDaysAndMicroseconds(days, microsecondsInDay, timezonePart) {
|
|
114
158
|
// This conversion of BigInt to Number is safe, because the largest absolute value that `days` can has is 106751991,
|
|
115
159
|
// which fits without loss of precision in a JS Number. (106751991 = (2^63-1) / MICROSECONDS_PER_DAY)
|
|
116
160
|
const dateStr = getDuckDBDateStringFromDays(Number(days));
|
|
117
161
|
const timeStr = getDuckDBTimeStringFromMicrosecondsInDay(microsecondsInDay);
|
|
118
|
-
|
|
119
|
-
return `${dateStr} ${timeStr}${timezoneStr}`;
|
|
162
|
+
return `${dateStr} ${timeStr}${timezonePart ?? ''}`;
|
|
120
163
|
}
|
|
121
|
-
function getDuckDBTimestampStringFromDaysAndNanoseconds(days, nanosecondsInDay
|
|
164
|
+
function getDuckDBTimestampStringFromDaysAndNanoseconds(days, nanosecondsInDay) {
|
|
122
165
|
// This conversion of BigInt to Number is safe, because the largest absolute value that `days` can has is 106751
|
|
123
166
|
// which fits without loss of precision in a JS Number. (106751 = (2^63-1) / NANOSECONDS_PER_DAY)
|
|
124
167
|
const dateStr = getDuckDBDateStringFromDays(Number(days));
|
|
125
168
|
const timeStr = getDuckDBTimeStringFromNanosecondsInDay(nanosecondsInDay);
|
|
126
|
-
|
|
127
|
-
return `${dateStr} ${timeStr}${timezoneStr}`;
|
|
169
|
+
return `${dateStr} ${timeStr}`;
|
|
128
170
|
}
|
|
129
|
-
function getDuckDBTimestampStringFromMicroseconds(microseconds,
|
|
171
|
+
function getDuckDBTimestampStringFromMicroseconds(microseconds, timezoneOffsetInMinutes) {
|
|
130
172
|
// Note that -infinity and infinity are only representable in TIMESTAMP (and TIMESTAMPTZ), not the other timestamp
|
|
131
173
|
// variants. This is by-design and matches DuckDB.
|
|
132
174
|
if (microseconds === NEGATIVE_INFINITY_TIMESTAMP) {
|
|
@@ -135,28 +177,34 @@ function getDuckDBTimestampStringFromMicroseconds(microseconds, timezone) {
|
|
|
135
177
|
if (microseconds === POSITIVE_INFINITY_TIMESTAMP) {
|
|
136
178
|
return 'infinity';
|
|
137
179
|
}
|
|
138
|
-
|
|
139
|
-
|
|
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;
|
|
140
188
|
if (microsecondsPart < 0) {
|
|
141
189
|
days--;
|
|
142
190
|
microsecondsPart += MICROSECONDS_PER_DAY;
|
|
143
191
|
}
|
|
144
|
-
return getDuckDBTimestampStringFromDaysAndMicroseconds(days, microsecondsPart,
|
|
192
|
+
return getDuckDBTimestampStringFromDaysAndMicroseconds(days, microsecondsPart, getTimezoneOffsetString(timezoneOffsetInMinutes));
|
|
145
193
|
}
|
|
146
|
-
function getDuckDBTimestampStringFromSeconds(seconds
|
|
147
|
-
return getDuckDBTimestampStringFromMicroseconds(seconds * MICROSECONDS_PER_SECOND
|
|
194
|
+
function getDuckDBTimestampStringFromSeconds(seconds) {
|
|
195
|
+
return getDuckDBTimestampStringFromMicroseconds(seconds * MICROSECONDS_PER_SECOND);
|
|
148
196
|
}
|
|
149
|
-
function getDuckDBTimestampStringFromMilliseconds(milliseconds
|
|
150
|
-
return getDuckDBTimestampStringFromMicroseconds(milliseconds * MICROSECONDS_PER_MILLISECOND
|
|
197
|
+
function getDuckDBTimestampStringFromMilliseconds(milliseconds) {
|
|
198
|
+
return getDuckDBTimestampStringFromMicroseconds(milliseconds * MICROSECONDS_PER_MILLISECOND);
|
|
151
199
|
}
|
|
152
|
-
function getDuckDBTimestampStringFromNanoseconds(nanoseconds
|
|
200
|
+
function getDuckDBTimestampStringFromNanoseconds(nanoseconds) {
|
|
153
201
|
let days = nanoseconds / NANOSECONDS_PER_DAY;
|
|
154
202
|
let nanosecondsPart = nanoseconds % NANOSECONDS_PER_DAY;
|
|
155
203
|
if (nanosecondsPart < 0) {
|
|
156
204
|
days--;
|
|
157
205
|
nanosecondsPart += NANOSECONDS_PER_DAY;
|
|
158
206
|
}
|
|
159
|
-
return getDuckDBTimestampStringFromDaysAndNanoseconds(days, nanosecondsPart
|
|
207
|
+
return getDuckDBTimestampStringFromDaysAndNanoseconds(days, nanosecondsPart);
|
|
160
208
|
}
|
|
161
209
|
// Assumes baseUnit can be pluralized by adding an 's'.
|
|
162
210
|
function numberAndUnit(value, baseUnit) {
|
|
@@ -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.convertValue(value, type)));
|
|
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[]>;
|
|
@@ -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.convertValue(value, type)));
|
|
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>[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertRowObjectsFromChunks = convertRowObjectsFromChunks;
|
|
4
|
+
function convertRowObjectsFromChunks(chunks, columnNames, converter) {
|
|
5
|
+
const rowObjects = [];
|
|
6
|
+
for (const chunk of chunks) {
|
|
7
|
+
const rowCount = chunk.rowCount;
|
|
8
|
+
for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
|
9
|
+
const rowObject = {};
|
|
10
|
+
chunk.visitRowValues(rowIndex, (value, _rowIndex, columnIndex, type) => {
|
|
11
|
+
rowObject[columnNames[columnIndex]] = converter.convertValue(value, type);
|
|
12
|
+
});
|
|
13
|
+
rowObjects.push(rowObject);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return rowObjects;
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertRowsFromChunks = convertRowsFromChunks;
|
|
4
|
+
function convertRowsFromChunks(chunks, converter) {
|
|
5
|
+
const rows = [];
|
|
6
|
+
for (const chunk of chunks) {
|
|
7
|
+
const rowCount = chunk.rowCount;
|
|
8
|
+
for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
|
9
|
+
rows.push(chunk.convertRowValues(rowIndex, converter));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return rows;
|
|
13
|
+
}
|
package/lib/createValue.js
CHANGED
|
@@ -116,11 +116,17 @@ function createValue(type, input) {
|
|
|
116
116
|
throw new Error(`not yet implemented for ENUM`); // TODO: implement when available in 1.2.0
|
|
117
117
|
case DuckDBTypeId_1.DuckDBTypeId.LIST:
|
|
118
118
|
if (input instanceof values_1.DuckDBListValue) {
|
|
119
|
+
if (type.valueType.typeId === DuckDBTypeId_1.DuckDBTypeId.ANY) {
|
|
120
|
+
throw new Error('Cannot create lists with item type of ANY. Specify a specific type.');
|
|
121
|
+
}
|
|
119
122
|
return node_bindings_1.default.create_list_value(type.valueType.toLogicalType().logical_type, input.items.map((item) => createValue(type.valueType, item)));
|
|
120
123
|
}
|
|
121
124
|
throw new Error(`input is not a DuckDBListValue`);
|
|
122
125
|
case DuckDBTypeId_1.DuckDBTypeId.STRUCT:
|
|
123
126
|
if (input instanceof values_1.DuckDBStructValue) {
|
|
127
|
+
if (type.entryTypes.find((type) => type.typeId === DuckDBTypeId_1.DuckDBTypeId.ANY)) {
|
|
128
|
+
throw new Error('Cannot create structs with an entry type of ANY. Specify a specific type.');
|
|
129
|
+
}
|
|
124
130
|
return node_bindings_1.default.create_struct_value(type.toLogicalType().logical_type, Object.values(input.entries).map((value, i) => createValue(type.entryTypes[i], value)));
|
|
125
131
|
}
|
|
126
132
|
throw new Error(`input is not a DuckDBStructValue`);
|
|
@@ -128,6 +134,9 @@ function createValue(type, input) {
|
|
|
128
134
|
throw new Error(`not yet implemented for MAP`); // TODO: implement when available, hopefully in 1.2.0
|
|
129
135
|
case DuckDBTypeId_1.DuckDBTypeId.ARRAY:
|
|
130
136
|
if (input instanceof values_1.DuckDBArrayValue) {
|
|
137
|
+
if (type.valueType.typeId === DuckDBTypeId_1.DuckDBTypeId.ANY) {
|
|
138
|
+
throw new Error('Cannot create arrays with item type of ANY. Specify a specific type.');
|
|
139
|
+
}
|
|
131
140
|
return node_bindings_1.default.create_array_value(type.valueType.toLogicalType().logical_type, input.items.map((item) => createValue(type.valueType, item)));
|
|
132
141
|
}
|
|
133
142
|
throw new Error(`input is not a DuckDBArrayValue`);
|
|
@@ -148,7 +157,7 @@ function createValue(type, input) {
|
|
|
148
157
|
}
|
|
149
158
|
throw new Error(`input is not a DuckDBTimestampTZValue`);
|
|
150
159
|
case DuckDBTypeId_1.DuckDBTypeId.ANY:
|
|
151
|
-
throw new Error(`
|
|
160
|
+
throw new Error(`Cannot create values of type ANY. Specify a specific type.`);
|
|
152
161
|
case DuckDBTypeId_1.DuckDBTypeId.VARINT:
|
|
153
162
|
throw new Error(`not yet implemented for VARINT`); // TODO: implement when available in 1.2.0
|
|
154
163
|
case DuckDBTypeId_1.DuckDBTypeId.SQLNULL:
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getColumnsFromChunks = getColumnsFromChunks;
|
|
4
|
+
function getColumnsFromChunks(chunks) {
|
|
5
|
+
const columns = [];
|
|
6
|
+
if (chunks.length === 0) {
|
|
7
|
+
return columns;
|
|
8
|
+
}
|
|
9
|
+
chunks[0].visitColumns((column) => columns.push(column));
|
|
10
|
+
for (let chunkIndex = 1; chunkIndex < chunks.length; chunkIndex++) {
|
|
11
|
+
for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) {
|
|
12
|
+
chunks[chunkIndex].visitColumnValues(columnIndex, (value) => columns[columnIndex].push(value));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return columns;
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getColumnsObjectFromChunks = getColumnsObjectFromChunks;
|
|
4
|
+
function getColumnsObjectFromChunks(chunks, columnNames) {
|
|
5
|
+
const columnsObject = {};
|
|
6
|
+
for (const columnName of columnNames) {
|
|
7
|
+
columnsObject[columnName] = [];
|
|
8
|
+
}
|
|
9
|
+
if (chunks.length === 0) {
|
|
10
|
+
return columnsObject;
|
|
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) => columnsObject[columnNames[columnIndex]].push(value));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return columnsObject;
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRowObjectsFromChunks = getRowObjectsFromChunks;
|
|
4
|
+
function getRowObjectsFromChunks(chunks, columnNames) {
|
|
5
|
+
const rowObjects = [];
|
|
6
|
+
for (const chunk of chunks) {
|
|
7
|
+
const rowCount = chunk.rowCount;
|
|
8
|
+
for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
|
9
|
+
const rowObject = {};
|
|
10
|
+
chunk.visitRowValues(rowIndex, (value, _, columnIndex) => {
|
|
11
|
+
rowObject[columnNames[columnIndex]] = value;
|
|
12
|
+
});
|
|
13
|
+
rowObjects.push(rowObject);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return rowObjects;
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRowsFromChunks = getRowsFromChunks;
|
|
4
|
+
function getRowsFromChunks(chunks) {
|
|
5
|
+
const rows = [];
|
|
6
|
+
for (const chunk of chunks) {
|
|
7
|
+
chunk.visitRows((row) => rows.push(row));
|
|
8
|
+
}
|
|
9
|
+
return rows;
|
|
10
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export * from './DuckDBPreparedStatement';
|
|
|
11
11
|
export * from './DuckDBResult';
|
|
12
12
|
export * from './DuckDBType';
|
|
13
13
|
export * from './DuckDBTypeId';
|
|
14
|
+
export * from './DuckDBValueConverter';
|
|
15
|
+
export * from './DuckDBValueToJsonConverter';
|
|
14
16
|
export * from './DuckDBVector';
|
|
15
17
|
export * from './configurationOptionDescriptions';
|
|
16
18
|
export * from './enums';
|
package/lib/index.js
CHANGED
|
@@ -32,6 +32,8 @@ __exportStar(require("./DuckDBPreparedStatement"), exports);
|
|
|
32
32
|
__exportStar(require("./DuckDBResult"), exports);
|
|
33
33
|
__exportStar(require("./DuckDBType"), exports);
|
|
34
34
|
__exportStar(require("./DuckDBTypeId"), exports);
|
|
35
|
+
__exportStar(require("./DuckDBValueConverter"), exports);
|
|
36
|
+
__exportStar(require("./DuckDBValueToJsonConverter"), exports);
|
|
35
37
|
__exportStar(require("./DuckDBVector"), exports);
|
|
36
38
|
__exportStar(require("./configurationOptionDescriptions"), exports);
|
|
37
39
|
__exportStar(require("./enums"), exports);
|
package/lib/typeForValue.js
CHANGED
|
@@ -12,7 +12,12 @@ function typeForValue(value) {
|
|
|
12
12
|
case 'boolean':
|
|
13
13
|
return DuckDBType_1.BOOLEAN;
|
|
14
14
|
case 'number':
|
|
15
|
-
|
|
15
|
+
if (Math.round(value) === value) {
|
|
16
|
+
return DuckDBType_1.INTEGER;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return DuckDBType_1.DOUBLE;
|
|
20
|
+
}
|
|
16
21
|
case 'bigint':
|
|
17
22
|
return DuckDBType_1.HUGEINT;
|
|
18
23
|
case 'string':
|
|
@@ -2,16 +2,16 @@ import { TimeTZ, TimeTZParts } from '@duckdb/node-bindings';
|
|
|
2
2
|
export type { TimeTZParts };
|
|
3
3
|
export declare class DuckDBTimeTZValue implements TimeTZ {
|
|
4
4
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
* 40 bits for micros, then 24 bits for encoded offset in seconds.
|
|
6
|
+
*
|
|
7
|
+
* Max absolute unencoded offset = 15:59:59 = 60 * (60 * 15 + 59) + 59 = 57599.
|
|
8
|
+
*
|
|
9
|
+
* Encoded offset is unencoded offset inverted then shifted (by +57599) to unsigned.
|
|
10
|
+
*
|
|
11
|
+
* Max unencoded offset = 57599 -> -57599 -> 0 encoded.
|
|
12
|
+
*
|
|
13
|
+
* Min unencoded offset = -57599 -> 57599 -> 115198 encoded.
|
|
14
|
+
*/
|
|
15
15
|
readonly bits: bigint;
|
|
16
16
|
/** Ranges from 0 to 86400000000 (= 24 * 60 * 60 * 1000 * 1000) */
|
|
17
17
|
readonly micros: bigint;
|
|
@@ -9,16 +9,16 @@ const node_bindings_1 = __importDefault(require("@duckdb/node-bindings"));
|
|
|
9
9
|
const dateTimeStringConversion_1 = require("../conversion/dateTimeStringConversion");
|
|
10
10
|
class DuckDBTimeTZValue {
|
|
11
11
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
* 40 bits for micros, then 24 bits for encoded offset in seconds.
|
|
13
|
+
*
|
|
14
|
+
* Max absolute unencoded offset = 15:59:59 = 60 * (60 * 15 + 59) + 59 = 57599.
|
|
15
|
+
*
|
|
16
|
+
* Encoded offset is unencoded offset inverted then shifted (by +57599) to unsigned.
|
|
17
|
+
*
|
|
18
|
+
* Max unencoded offset = 57599 -> -57599 -> 0 encoded.
|
|
19
|
+
*
|
|
20
|
+
* Min unencoded offset = -57599 -> 57599 -> 115198 encoded.
|
|
21
|
+
*/
|
|
22
22
|
bits;
|
|
23
23
|
/** Ranges from 0 to 86400000000 (= 24 * 60 * 60 * 1000 * 1000) */
|
|
24
24
|
micros;
|
|
@@ -30,8 +30,7 @@ class DuckDBTimeTZValue {
|
|
|
30
30
|
this.offset = offset;
|
|
31
31
|
}
|
|
32
32
|
toString() {
|
|
33
|
-
|
|
34
|
-
return (0, dateTimeStringConversion_1.getDuckDBTimeStringFromMicrosecondsInDay)(this.micros);
|
|
33
|
+
return `${(0, dateTimeStringConversion_1.getDuckDBTimeStringFromMicrosecondsInDay)(this.micros)}${(0, dateTimeStringConversion_1.getOffsetStringFromSeconds)(this.offset)}`;
|
|
35
34
|
}
|
|
36
35
|
toParts() {
|
|
37
36
|
return node_bindings_1.default.from_time_tz(this);
|
|
@@ -44,12 +43,14 @@ class DuckDBTimeTZValue {
|
|
|
44
43
|
static MinMicros = 0n;
|
|
45
44
|
static fromBits(bits) {
|
|
46
45
|
const micros = BigInt.asUintN(DuckDBTimeTZValue.TimeBits, bits >> BigInt(DuckDBTimeTZValue.OffsetBits));
|
|
47
|
-
const offset = DuckDBTimeTZValue.MaxOffset -
|
|
46
|
+
const offset = DuckDBTimeTZValue.MaxOffset -
|
|
47
|
+
Number(BigInt.asUintN(DuckDBTimeTZValue.OffsetBits, bits));
|
|
48
48
|
return new DuckDBTimeTZValue(bits, micros, offset);
|
|
49
49
|
}
|
|
50
50
|
static fromMicrosAndOffset(micros, offset) {
|
|
51
|
-
const bits = BigInt.asUintN(DuckDBTimeTZValue.TimeBits, micros) <<
|
|
52
|
-
|
|
51
|
+
const bits = (BigInt.asUintN(DuckDBTimeTZValue.TimeBits, micros) <<
|
|
52
|
+
BigInt(DuckDBTimeTZValue.OffsetBits)) |
|
|
53
|
+
BigInt.asUintN(DuckDBTimeTZValue.OffsetBits, BigInt(DuckDBTimeTZValue.MaxOffset - offset));
|
|
53
54
|
return new DuckDBTimeTZValue(bits, micros, offset);
|
|
54
55
|
}
|
|
55
56
|
static fromParts(parts) {
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { TimestampMilliseconds } from '@duckdb/node-bindings';
|
|
2
|
+
export declare class DuckDBTimestampMillisecondsValue implements TimestampMilliseconds {
|
|
3
|
+
readonly millis: bigint;
|
|
4
|
+
constructor(millis: bigint);
|
|
5
|
+
get isFinite(): boolean;
|
|
4
6
|
toString(): string;
|
|
5
7
|
static readonly Epoch: DuckDBTimestampMillisecondsValue;
|
|
6
8
|
static readonly Max: DuckDBTimestampMillisecondsValue;
|
|
7
9
|
static readonly Min: DuckDBTimestampMillisecondsValue;
|
|
10
|
+
static readonly PosInf: DuckDBTimestampMillisecondsValue;
|
|
11
|
+
static readonly NegInf: DuckDBTimestampMillisecondsValue;
|
|
8
12
|
}
|
|
9
|
-
export declare function timestampMillisValue(
|
|
13
|
+
export declare function timestampMillisValue(millis: bigint): DuckDBTimestampMillisecondsValue;
|