@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
package/lib/DuckDBDataChunk.js
CHANGED
|
@@ -13,7 +13,7 @@ class DuckDBDataChunk {
|
|
|
13
13
|
this.chunk = chunk;
|
|
14
14
|
}
|
|
15
15
|
static create(types, rowCount) {
|
|
16
|
-
const chunk = new DuckDBDataChunk(node_bindings_1.default.create_data_chunk(types.map(t => t.toLogicalType().logical_type)));
|
|
16
|
+
const chunk = new DuckDBDataChunk(node_bindings_1.default.create_data_chunk(types.map((t) => t.toLogicalType().logical_type)));
|
|
17
17
|
if (rowCount != undefined) {
|
|
18
18
|
chunk.rowCount = rowCount;
|
|
19
19
|
}
|
|
@@ -25,6 +25,12 @@ class DuckDBDataChunk {
|
|
|
25
25
|
get columnCount() {
|
|
26
26
|
return node_bindings_1.default.data_chunk_get_column_count(this.chunk);
|
|
27
27
|
}
|
|
28
|
+
get rowCount() {
|
|
29
|
+
return node_bindings_1.default.data_chunk_get_size(this.chunk);
|
|
30
|
+
}
|
|
31
|
+
set rowCount(count) {
|
|
32
|
+
node_bindings_1.default.data_chunk_set_size(this.chunk, count);
|
|
33
|
+
}
|
|
28
34
|
getColumnVector(columnIndex) {
|
|
29
35
|
if (this.vectors[columnIndex]) {
|
|
30
36
|
return this.vectors[columnIndex];
|
|
@@ -33,8 +39,23 @@ class DuckDBDataChunk {
|
|
|
33
39
|
this.vectors[columnIndex] = vector;
|
|
34
40
|
return vector;
|
|
35
41
|
}
|
|
42
|
+
visitColumnValues(columnIndex, visitValue) {
|
|
43
|
+
const vector = this.getColumnVector(columnIndex);
|
|
44
|
+
const type = vector.type;
|
|
45
|
+
for (let rowIndex = 0; rowIndex < vector.itemCount; rowIndex++) {
|
|
46
|
+
visitValue(vector.getItem(rowIndex), rowIndex, columnIndex, type);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
36
49
|
getColumnValues(columnIndex) {
|
|
37
|
-
|
|
50
|
+
const values = [];
|
|
51
|
+
this.visitColumnValues(columnIndex, (value) => values.push(value));
|
|
52
|
+
return values;
|
|
53
|
+
}
|
|
54
|
+
convertColumnValues(columnIndex, converter) {
|
|
55
|
+
const convertedValues = [];
|
|
56
|
+
const type = this.getColumnVector(columnIndex).type;
|
|
57
|
+
this.visitColumnValues(columnIndex, (value) => convertedValues.push(converter.convertValue(value, type)));
|
|
58
|
+
return convertedValues;
|
|
38
59
|
}
|
|
39
60
|
setColumnValues(columnIndex, values) {
|
|
40
61
|
const vector = this.getColumnVector(columnIndex);
|
|
@@ -46,13 +67,24 @@ class DuckDBDataChunk {
|
|
|
46
67
|
}
|
|
47
68
|
vector.flush();
|
|
48
69
|
}
|
|
70
|
+
visitColumns(visitColumn) {
|
|
71
|
+
const columnCount = this.columnCount;
|
|
72
|
+
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
73
|
+
visitColumn(this.getColumnValues(columnIndex), columnIndex, this.getColumnVector(columnIndex).type);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
49
76
|
getColumns() {
|
|
50
77
|
const columns = [];
|
|
78
|
+
this.visitColumns((column) => columns.push(column));
|
|
79
|
+
return columns;
|
|
80
|
+
}
|
|
81
|
+
convertColumns(converter) {
|
|
82
|
+
const convertedColumns = [];
|
|
51
83
|
const columnCount = this.columnCount;
|
|
52
84
|
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
53
|
-
|
|
85
|
+
convertedColumns.push(this.convertColumnValues(columnIndex, converter));
|
|
54
86
|
}
|
|
55
|
-
return
|
|
87
|
+
return convertedColumns;
|
|
56
88
|
}
|
|
57
89
|
setColumns(columns) {
|
|
58
90
|
if (columns.length > 0) {
|
|
@@ -62,23 +94,48 @@ class DuckDBDataChunk {
|
|
|
62
94
|
this.setColumnValues(columnIndex, columns[columnIndex]);
|
|
63
95
|
}
|
|
64
96
|
}
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
97
|
+
visitColumnMajor(visitValue) {
|
|
98
|
+
const columnCount = this.columnCount;
|
|
99
|
+
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
100
|
+
this.visitColumnValues(columnIndex, visitValue);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
visitRowValues(rowIndex, visitValue) {
|
|
68
104
|
const columnCount = this.columnCount;
|
|
69
105
|
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
70
|
-
|
|
106
|
+
const vector = this.getColumnVector(columnIndex);
|
|
107
|
+
visitValue(vector.getItem(rowIndex), rowIndex, columnIndex, vector.type);
|
|
71
108
|
}
|
|
109
|
+
}
|
|
110
|
+
getRowValues(rowIndex) {
|
|
111
|
+
const values = [];
|
|
112
|
+
this.visitRowValues(rowIndex, (value) => values.push(value));
|
|
113
|
+
return values;
|
|
114
|
+
}
|
|
115
|
+
convertRowValues(rowIndex, converter) {
|
|
116
|
+
const convertedValues = [];
|
|
117
|
+
this.visitRowValues(rowIndex, (value, _, columnIndex) => convertedValues.push(converter.convertValue(value, this.getColumnVector(columnIndex).type)));
|
|
118
|
+
return convertedValues;
|
|
119
|
+
}
|
|
120
|
+
visitRows(visitRow) {
|
|
72
121
|
const rowCount = this.rowCount;
|
|
73
122
|
for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
|
74
|
-
|
|
75
|
-
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
76
|
-
row.push(vectors[columnIndex].getItem(rowIndex));
|
|
77
|
-
}
|
|
78
|
-
rows.push(row);
|
|
123
|
+
visitRow(this.getRowValues(rowIndex), rowIndex);
|
|
79
124
|
}
|
|
125
|
+
}
|
|
126
|
+
getRows() {
|
|
127
|
+
const rows = [];
|
|
128
|
+
this.visitRows((row) => rows.push(row));
|
|
80
129
|
return rows;
|
|
81
130
|
}
|
|
131
|
+
convertRows(converter) {
|
|
132
|
+
const convertedRows = [];
|
|
133
|
+
const rowCount = this.rowCount;
|
|
134
|
+
for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
|
135
|
+
convertedRows.push(this.convertRowValues(rowIndex, converter));
|
|
136
|
+
}
|
|
137
|
+
return convertedRows;
|
|
138
|
+
}
|
|
82
139
|
setRows(rows) {
|
|
83
140
|
this.rowCount = rows.length;
|
|
84
141
|
const columnCount = this.columnCount;
|
|
@@ -90,11 +147,15 @@ class DuckDBDataChunk {
|
|
|
90
147
|
vector.flush();
|
|
91
148
|
}
|
|
92
149
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
150
|
+
visitRowMajor(visitValue) {
|
|
151
|
+
const rowCount = this.rowCount;
|
|
152
|
+
const columnCount = this.columnCount;
|
|
153
|
+
for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
|
154
|
+
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
155
|
+
const vector = this.getColumnVector(columnIndex);
|
|
156
|
+
visitValue(vector.getItem(rowIndex), rowIndex, columnIndex, vector.type);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
98
159
|
}
|
|
99
160
|
}
|
|
100
161
|
exports.DuckDBDataChunk = DuckDBDataChunk;
|
|
@@ -14,7 +14,7 @@ export declare class DuckDBLogicalType {
|
|
|
14
14
|
static createUnion(memberTags: readonly string[], memberLogicalTypes: readonly DuckDBLogicalType[]): DuckDBUnionLogicalType;
|
|
15
15
|
get typeId(): DuckDBTypeId;
|
|
16
16
|
get alias(): string | undefined;
|
|
17
|
-
set alias(newAlias: string);
|
|
17
|
+
set alias(newAlias: string | null | undefined);
|
|
18
18
|
asType(): DuckDBType;
|
|
19
19
|
}
|
|
20
20
|
export declare class DuckDBDecimalLogicalType extends DuckDBLogicalType {
|
package/lib/DuckDBLogicalType.js
CHANGED
|
@@ -82,7 +82,7 @@ class DuckDBLogicalType {
|
|
|
82
82
|
return node_bindings_1.default.logical_type_get_alias(this.logical_type) || undefined;
|
|
83
83
|
}
|
|
84
84
|
set alias(newAlias) {
|
|
85
|
-
node_bindings_1.default.logical_type_set_alias(this.logical_type, newAlias);
|
|
85
|
+
node_bindings_1.default.logical_type_set_alias(this.logical_type, newAlias || '');
|
|
86
86
|
}
|
|
87
87
|
asType() {
|
|
88
88
|
const alias = this.alias;
|
|
@@ -14,6 +14,7 @@ export declare class DuckDBPreparedStatement {
|
|
|
14
14
|
get parameterCount(): number;
|
|
15
15
|
parameterName(parameterIndex: number): string;
|
|
16
16
|
parameterTypeId(parameterIndex: number): DuckDBTypeId;
|
|
17
|
+
parameterType(parameterIndex: number): DuckDBType;
|
|
17
18
|
clearBindings(): void;
|
|
18
19
|
parameterIndex(parameterName: string): number;
|
|
19
20
|
bindBoolean(parameterIndex: number, value: boolean): void;
|
|
@@ -43,7 +44,7 @@ export declare class DuckDBPreparedStatement {
|
|
|
43
44
|
bindStruct(parameterIndex: number, value: DuckDBStructValue, type: DuckDBStructType): void;
|
|
44
45
|
bindNull(parameterIndex: number): void;
|
|
45
46
|
bindValue(parameterIndex: number, value: DuckDBValue, type: DuckDBType): void;
|
|
46
|
-
bind(values: DuckDBValue[] | Record<string, DuckDBValue>, types?: DuckDBType[] | Record<string, DuckDBType>): void;
|
|
47
|
+
bind(values: DuckDBValue[] | Record<string, DuckDBValue>, types?: DuckDBType[] | Record<string, DuckDBType | undefined>): void;
|
|
47
48
|
run(): Promise<DuckDBMaterializedResult>;
|
|
48
49
|
runAndRead(): Promise<DuckDBResultReader>;
|
|
49
50
|
runAndReadAll(): Promise<DuckDBResultReader>;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.DuckDBPreparedStatement = void 0;
|
|
7
7
|
const node_bindings_1 = __importDefault(require("@duckdb/node-bindings"));
|
|
8
8
|
const createValue_1 = require("./createValue");
|
|
9
|
+
const DuckDBLogicalType_1 = require("./DuckDBLogicalType");
|
|
9
10
|
const DuckDBMaterializedResult_1 = require("./DuckDBMaterializedResult");
|
|
10
11
|
const DuckDBPendingResult_1 = require("./DuckDBPendingResult");
|
|
11
12
|
const DuckDBResult_1 = require("./DuckDBResult");
|
|
@@ -29,6 +30,9 @@ class DuckDBPreparedStatement {
|
|
|
29
30
|
parameterTypeId(parameterIndex) {
|
|
30
31
|
return node_bindings_1.default.param_type(this.prepared_statement, parameterIndex);
|
|
31
32
|
}
|
|
33
|
+
parameterType(parameterIndex) {
|
|
34
|
+
return DuckDBLogicalType_1.DuckDBLogicalType.create(node_bindings_1.default.param_logical_type(this.prepared_statement, parameterIndex)).asType();
|
|
35
|
+
}
|
|
32
36
|
clearBindings() {
|
|
33
37
|
node_bindings_1.default.clear_bindings(this.prepared_statement);
|
|
34
38
|
}
|
|
@@ -132,7 +136,11 @@ class DuckDBPreparedStatement {
|
|
|
132
136
|
const typesIsRecord = types && !Array.isArray(types);
|
|
133
137
|
for (const key in values) {
|
|
134
138
|
const index = this.parameterIndex(key);
|
|
135
|
-
|
|
139
|
+
let type = typesIsRecord ? types[key] : undefined;
|
|
140
|
+
if (type === undefined) {
|
|
141
|
+
type = (0, typeForValue_1.typeForValue)(values[key]);
|
|
142
|
+
}
|
|
143
|
+
this.bindValue(index, values[key], type);
|
|
136
144
|
}
|
|
137
145
|
}
|
|
138
146
|
}
|
package/lib/DuckDBResult.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { DuckDBDataChunk } from './DuckDBDataChunk';
|
|
|
3
3
|
import { DuckDBLogicalType } from './DuckDBLogicalType';
|
|
4
4
|
import { DuckDBType } from './DuckDBType';
|
|
5
5
|
import { DuckDBTypeId } from './DuckDBTypeId';
|
|
6
|
+
import { Json } from './DuckDBValueToJsonConverter';
|
|
6
7
|
import { ResultReturnType, StatementType } from './enums';
|
|
7
8
|
import { DuckDBValue } from './values';
|
|
8
9
|
export declare class DuckDBResult {
|
|
@@ -13,6 +14,7 @@ export declare class DuckDBResult {
|
|
|
13
14
|
get columnCount(): number;
|
|
14
15
|
columnName(columnIndex: number): string;
|
|
15
16
|
columnNames(): string[];
|
|
17
|
+
deduplicatedColumnNames(): string[];
|
|
16
18
|
columnTypeId(columnIndex: number): DuckDBTypeId;
|
|
17
19
|
columnLogicalType(columnIndex: number): DuckDBLogicalType;
|
|
18
20
|
columnType(columnIndex: number): DuckDBType;
|
|
@@ -22,5 +24,11 @@ export declare class DuckDBResult {
|
|
|
22
24
|
fetchChunk(): Promise<DuckDBDataChunk | null>;
|
|
23
25
|
fetchAllChunks(): Promise<DuckDBDataChunk[]>;
|
|
24
26
|
getColumns(): Promise<DuckDBValue[][]>;
|
|
27
|
+
getColumnsJson(): Promise<Json[][]>;
|
|
28
|
+
getColumnsObject(): Promise<Record<string, DuckDBValue[]>>;
|
|
29
|
+
getColumnsObjectJson(): Promise<Record<string, Json[]>>;
|
|
25
30
|
getRows(): Promise<DuckDBValue[][]>;
|
|
31
|
+
getRowsJson(): Promise<Json[][]>;
|
|
32
|
+
getRowObjects(): Promise<Record<string, DuckDBValue>[]>;
|
|
33
|
+
getRowObjectsJson(): Promise<Record<string, Json>[]>;
|
|
26
34
|
}
|
package/lib/DuckDBResult.js
CHANGED
|
@@ -7,6 +7,15 @@ exports.DuckDBResult = void 0;
|
|
|
7
7
|
const node_bindings_1 = __importDefault(require("@duckdb/node-bindings"));
|
|
8
8
|
const DuckDBDataChunk_1 = require("./DuckDBDataChunk");
|
|
9
9
|
const DuckDBLogicalType_1 = require("./DuckDBLogicalType");
|
|
10
|
+
const DuckDBValueToJsonConverter_1 = require("./DuckDBValueToJsonConverter");
|
|
11
|
+
const convertColumnsFromChunks_1 = require("./convertColumnsFromChunks");
|
|
12
|
+
const convertColumnsObjectFromChunks_1 = require("./convertColumnsObjectFromChunks");
|
|
13
|
+
const convertRowObjectsFromChunks_1 = require("./convertRowObjectsFromChunks");
|
|
14
|
+
const convertRowsFromChunks_1 = require("./convertRowsFromChunks");
|
|
15
|
+
const getColumnsFromChunks_1 = require("./getColumnsFromChunks");
|
|
16
|
+
const getColumnsObjectFromChunks_1 = require("./getColumnsObjectFromChunks");
|
|
17
|
+
const getRowObjectsFromChunks_1 = require("./getRowObjectsFromChunks");
|
|
18
|
+
const getRowsFromChunks_1 = require("./getRowsFromChunks");
|
|
10
19
|
class DuckDBResult {
|
|
11
20
|
result;
|
|
12
21
|
constructor(result) {
|
|
@@ -32,6 +41,23 @@ class DuckDBResult {
|
|
|
32
41
|
}
|
|
33
42
|
return columnNames;
|
|
34
43
|
}
|
|
44
|
+
deduplicatedColumnNames() {
|
|
45
|
+
const outputColumnNames = [];
|
|
46
|
+
const columnCount = this.columnCount;
|
|
47
|
+
const columnNameCount = {};
|
|
48
|
+
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
49
|
+
const inputColumnName = this.columnName(columnIndex);
|
|
50
|
+
const nameCount = (columnNameCount[inputColumnName] || 0) + 1;
|
|
51
|
+
columnNameCount[inputColumnName] = nameCount;
|
|
52
|
+
if (nameCount > 1) {
|
|
53
|
+
outputColumnNames.push(`${inputColumnName}:${nameCount - 1}`);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
outputColumnNames.push(inputColumnName);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return outputColumnNames;
|
|
60
|
+
}
|
|
35
61
|
columnTypeId(columnIndex) {
|
|
36
62
|
return node_bindings_1.default.column_type(this.result, columnIndex);
|
|
37
63
|
}
|
|
@@ -71,44 +97,35 @@ class DuckDBResult {
|
|
|
71
97
|
}
|
|
72
98
|
async getColumns() {
|
|
73
99
|
const chunks = await this.fetchAllChunks();
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
columns[columnIndex].push(vector.getItem(itemIndex));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return columns;
|
|
100
|
+
return (0, getColumnsFromChunks_1.getColumnsFromChunks)(chunks);
|
|
101
|
+
}
|
|
102
|
+
async getColumnsJson() {
|
|
103
|
+
const chunks = await this.fetchAllChunks();
|
|
104
|
+
return (0, convertColumnsFromChunks_1.convertColumnsFromChunks)(chunks, DuckDBValueToJsonConverter_1.DuckDBValueToJsonConverter.default);
|
|
105
|
+
}
|
|
106
|
+
async getColumnsObject() {
|
|
107
|
+
const chunks = await this.fetchAllChunks();
|
|
108
|
+
return (0, getColumnsObjectFromChunks_1.getColumnsObjectFromChunks)(chunks, this.deduplicatedColumnNames());
|
|
109
|
+
}
|
|
110
|
+
async getColumnsObjectJson() {
|
|
111
|
+
const chunks = await this.fetchAllChunks();
|
|
112
|
+
return (0, convertColumnsObjectFromChunks_1.convertColumnsObjectFromChunks)(chunks, this.deduplicatedColumnNames(), DuckDBValueToJsonConverter_1.DuckDBValueToJsonConverter.default);
|
|
92
113
|
}
|
|
93
114
|
async getRows() {
|
|
94
115
|
const chunks = await this.fetchAllChunks();
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
rows.push(row);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return rows;
|
|
116
|
+
return (0, getRowsFromChunks_1.getRowsFromChunks)(chunks);
|
|
117
|
+
}
|
|
118
|
+
async getRowsJson() {
|
|
119
|
+
const chunks = await this.fetchAllChunks();
|
|
120
|
+
return (0, convertRowsFromChunks_1.convertRowsFromChunks)(chunks, DuckDBValueToJsonConverter_1.DuckDBValueToJsonConverter.default);
|
|
121
|
+
}
|
|
122
|
+
async getRowObjects() {
|
|
123
|
+
const chunks = await this.fetchAllChunks();
|
|
124
|
+
return (0, getRowObjectsFromChunks_1.getRowObjectsFromChunks)(chunks, this.deduplicatedColumnNames());
|
|
125
|
+
}
|
|
126
|
+
async getRowObjectsJson() {
|
|
127
|
+
const chunks = await this.fetchAllChunks();
|
|
128
|
+
return (0, convertRowObjectsFromChunks_1.convertRowObjectsFromChunks)(chunks, this.deduplicatedColumnNames(), DuckDBValueToJsonConverter_1.DuckDBValueToJsonConverter.default);
|
|
112
129
|
}
|
|
113
130
|
}
|
|
114
131
|
exports.DuckDBResult = DuckDBResult;
|
|
@@ -2,6 +2,7 @@ import { DuckDBLogicalType } from './DuckDBLogicalType';
|
|
|
2
2
|
import { DuckDBResult } from './DuckDBResult';
|
|
3
3
|
import { DuckDBType } from './DuckDBType';
|
|
4
4
|
import { DuckDBTypeId } from './DuckDBTypeId';
|
|
5
|
+
import { Json } from './DuckDBValueToJsonConverter';
|
|
5
6
|
import { ResultReturnType, StatementType } from './enums';
|
|
6
7
|
import { DuckDBValue } from './values';
|
|
7
8
|
export declare class DuckDBResultReader {
|
|
@@ -16,6 +17,7 @@ export declare class DuckDBResultReader {
|
|
|
16
17
|
get columnCount(): number;
|
|
17
18
|
columnName(columnIndex: number): string;
|
|
18
19
|
columnNames(): string[];
|
|
20
|
+
deduplicatedColumnNames(): string[];
|
|
19
21
|
columnTypeId(columnIndex: number): DuckDBTypeId;
|
|
20
22
|
columnLogicalType(columnIndex: number): DuckDBLogicalType;
|
|
21
23
|
columnType(columnIndex: number): DuckDBType;
|
|
@@ -42,5 +44,11 @@ export declare class DuckDBResultReader {
|
|
|
42
44
|
private fetchChunks;
|
|
43
45
|
private updateChunkSizeRuns;
|
|
44
46
|
getColumns(): DuckDBValue[][];
|
|
47
|
+
getColumnsJson(): Json[][];
|
|
48
|
+
getColumnsObject(): Record<string, DuckDBValue[]>;
|
|
49
|
+
getColumnsObjectJson(): Record<string, Json[]>;
|
|
45
50
|
getRows(): DuckDBValue[][];
|
|
51
|
+
getRowsJson(): Json[][];
|
|
52
|
+
getRowObjects(): Record<string, DuckDBValue>[];
|
|
53
|
+
getRowObjectsJson(): Record<string, Json>[];
|
|
46
54
|
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DuckDBResultReader = void 0;
|
|
4
|
+
const convertColumnsFromChunks_1 = require("./convertColumnsFromChunks");
|
|
5
|
+
const convertColumnsObjectFromChunks_1 = require("./convertColumnsObjectFromChunks");
|
|
6
|
+
const convertRowObjectsFromChunks_1 = require("./convertRowObjectsFromChunks");
|
|
7
|
+
const convertRowsFromChunks_1 = require("./convertRowsFromChunks");
|
|
8
|
+
const DuckDBValueToJsonConverter_1 = require("./DuckDBValueToJsonConverter");
|
|
9
|
+
const getColumnsFromChunks_1 = require("./getColumnsFromChunks");
|
|
10
|
+
const getColumnsObjectFromChunks_1 = require("./getColumnsObjectFromChunks");
|
|
11
|
+
const getRowObjectsFromChunks_1 = require("./getRowObjectsFromChunks");
|
|
12
|
+
const getRowsFromChunks_1 = require("./getRowsFromChunks");
|
|
4
13
|
class DuckDBResultReader {
|
|
5
14
|
result;
|
|
6
15
|
chunks;
|
|
@@ -29,6 +38,9 @@ class DuckDBResultReader {
|
|
|
29
38
|
columnNames() {
|
|
30
39
|
return this.result.columnNames();
|
|
31
40
|
}
|
|
41
|
+
deduplicatedColumnNames() {
|
|
42
|
+
return this.result.deduplicatedColumnNames();
|
|
43
|
+
}
|
|
32
44
|
columnTypeId(columnIndex) {
|
|
33
45
|
return this.result.columnTypeId(columnIndex);
|
|
34
46
|
}
|
|
@@ -96,7 +108,8 @@ class DuckDBResultReader {
|
|
|
96
108
|
}
|
|
97
109
|
async fetchChunks(targetRowCount) {
|
|
98
110
|
while (!(this.done_ ||
|
|
99
|
-
(targetRowCount !== undefined &&
|
|
111
|
+
(targetRowCount !== undefined &&
|
|
112
|
+
this.currentRowCount_ >= targetRowCount))) {
|
|
100
113
|
const chunk = await this.result.fetchChunk();
|
|
101
114
|
if (chunk && chunk.rowCount > 0) {
|
|
102
115
|
this.updateChunkSizeRuns(chunk);
|
|
@@ -126,43 +139,28 @@ class DuckDBResultReader {
|
|
|
126
139
|
});
|
|
127
140
|
}
|
|
128
141
|
getColumns() {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
140
|
-
const vector = this.chunks[chunkIndex].getColumnVector(columnIndex);
|
|
141
|
-
for (let itemIndex = 0; itemIndex < vector.itemCount; itemIndex++) {
|
|
142
|
-
columns[columnIndex].push(vector.getItem(itemIndex));
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return columns;
|
|
142
|
+
return (0, getColumnsFromChunks_1.getColumnsFromChunks)(this.chunks);
|
|
143
|
+
}
|
|
144
|
+
getColumnsJson() {
|
|
145
|
+
return (0, convertColumnsFromChunks_1.convertColumnsFromChunks)(this.chunks, DuckDBValueToJsonConverter_1.DuckDBValueToJsonConverter.default);
|
|
146
|
+
}
|
|
147
|
+
getColumnsObject() {
|
|
148
|
+
return (0, getColumnsObjectFromChunks_1.getColumnsObjectFromChunks)(this.chunks, this.deduplicatedColumnNames());
|
|
149
|
+
}
|
|
150
|
+
getColumnsObjectJson() {
|
|
151
|
+
return (0, convertColumnsObjectFromChunks_1.convertColumnsObjectFromChunks)(this.chunks, this.deduplicatedColumnNames(), DuckDBValueToJsonConverter_1.DuckDBValueToJsonConverter.default);
|
|
147
152
|
}
|
|
148
153
|
getRows() {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
|
160
|
-
row.push(chunkVectors[columnIndex].getItem(rowIndex));
|
|
161
|
-
}
|
|
162
|
-
rows.push(row);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return rows;
|
|
154
|
+
return (0, getRowsFromChunks_1.getRowsFromChunks)(this.chunks);
|
|
155
|
+
}
|
|
156
|
+
getRowsJson() {
|
|
157
|
+
return (0, convertRowsFromChunks_1.convertRowsFromChunks)(this.chunks, DuckDBValueToJsonConverter_1.DuckDBValueToJsonConverter.default);
|
|
158
|
+
}
|
|
159
|
+
getRowObjects() {
|
|
160
|
+
return (0, getRowObjectsFromChunks_1.getRowObjectsFromChunks)(this.chunks, this.deduplicatedColumnNames());
|
|
161
|
+
}
|
|
162
|
+
getRowObjectsJson() {
|
|
163
|
+
return (0, convertRowObjectsFromChunks_1.convertRowObjectsFromChunks)(this.chunks, this.deduplicatedColumnNames(), DuckDBValueToJsonConverter_1.DuckDBValueToJsonConverter.default);
|
|
166
164
|
}
|
|
167
165
|
}
|
|
168
166
|
exports.DuckDBResultReader = DuckDBResultReader;
|
package/lib/DuckDBType.d.ts
CHANGED
|
@@ -200,6 +200,8 @@ export declare class DuckDBTimestampSecondsType extends BaseDuckDBType<DuckDBTyp
|
|
|
200
200
|
get epoch(): DuckDBTimestampSecondsValue;
|
|
201
201
|
get max(): DuckDBTimestampSecondsValue;
|
|
202
202
|
get min(): DuckDBTimestampSecondsValue;
|
|
203
|
+
get posInf(): DuckDBTimestampSecondsValue;
|
|
204
|
+
get negInf(): DuckDBTimestampSecondsValue;
|
|
203
205
|
}
|
|
204
206
|
export declare const TIMESTAMP_S: DuckDBTimestampSecondsType;
|
|
205
207
|
export declare class DuckDBTimestampMillisecondsType extends BaseDuckDBType<DuckDBTypeId.TIMESTAMP_MS> {
|
|
@@ -209,6 +211,8 @@ export declare class DuckDBTimestampMillisecondsType extends BaseDuckDBType<Duck
|
|
|
209
211
|
get epoch(): DuckDBTimestampMillisecondsValue;
|
|
210
212
|
get max(): DuckDBTimestampMillisecondsValue;
|
|
211
213
|
get min(): DuckDBTimestampMillisecondsValue;
|
|
214
|
+
get posInf(): DuckDBTimestampMillisecondsValue;
|
|
215
|
+
get negInf(): DuckDBTimestampMillisecondsValue;
|
|
212
216
|
}
|
|
213
217
|
export declare const TIMESTAMP_MS: DuckDBTimestampMillisecondsType;
|
|
214
218
|
export declare class DuckDBTimestampNanosecondsType extends BaseDuckDBType<DuckDBTypeId.TIMESTAMP_NS> {
|
|
@@ -218,6 +222,8 @@ export declare class DuckDBTimestampNanosecondsType extends BaseDuckDBType<DuckD
|
|
|
218
222
|
get epoch(): DuckDBTimestampNanosecondsValue;
|
|
219
223
|
get max(): DuckDBTimestampNanosecondsValue;
|
|
220
224
|
get min(): DuckDBTimestampNanosecondsValue;
|
|
225
|
+
get posInf(): DuckDBTimestampNanosecondsValue;
|
|
226
|
+
get negInf(): DuckDBTimestampNanosecondsValue;
|
|
221
227
|
}
|
|
222
228
|
export declare const TIMESTAMP_NS: DuckDBTimestampNanosecondsType;
|
|
223
229
|
export declare class DuckDBEnumType extends BaseDuckDBType<DuckDBTypeId.ENUM> {
|
|
@@ -243,8 +249,11 @@ export declare function LIST(valueType: DuckDBType, alias?: string): DuckDBListT
|
|
|
243
249
|
export declare class DuckDBStructType extends BaseDuckDBType<DuckDBTypeId.STRUCT> {
|
|
244
250
|
readonly entryNames: readonly string[];
|
|
245
251
|
readonly entryTypes: readonly DuckDBType[];
|
|
252
|
+
readonly entryIndexes: Readonly<Record<string, number>>;
|
|
246
253
|
constructor(entryNames: readonly string[], entryTypes: readonly DuckDBType[], alias?: string);
|
|
247
254
|
get entryCount(): number;
|
|
255
|
+
indexForEntry(entryName: string): number;
|
|
256
|
+
typeForEntry(entryName: string): DuckDBType;
|
|
248
257
|
toString(): string;
|
|
249
258
|
toLogicalType(): DuckDBLogicalType;
|
|
250
259
|
}
|
|
@@ -279,6 +288,7 @@ export declare class DuckDBUnionType extends BaseDuckDBType<DuckDBTypeId.UNION>
|
|
|
279
288
|
readonly memberTypes: readonly DuckDBType[];
|
|
280
289
|
constructor(memberTags: readonly string[], memberTypes: readonly DuckDBType[], alias?: string);
|
|
281
290
|
memberIndexForTag(tag: string): number;
|
|
291
|
+
memberTypeForTag(tag: string): DuckDBType;
|
|
282
292
|
get memberCount(): number;
|
|
283
293
|
toString(): string;
|
|
284
294
|
toLogicalType(): DuckDBLogicalType;
|
package/lib/DuckDBType.js
CHANGED
|
@@ -434,6 +434,12 @@ class DuckDBTimestampSecondsType extends BaseDuckDBType {
|
|
|
434
434
|
get min() {
|
|
435
435
|
return values_1.DuckDBTimestampSecondsValue.Min;
|
|
436
436
|
}
|
|
437
|
+
get posInf() {
|
|
438
|
+
return values_1.DuckDBTimestampSecondsValue.PosInf;
|
|
439
|
+
}
|
|
440
|
+
get negInf() {
|
|
441
|
+
return values_1.DuckDBTimestampSecondsValue.NegInf;
|
|
442
|
+
}
|
|
437
443
|
}
|
|
438
444
|
exports.DuckDBTimestampSecondsType = DuckDBTimestampSecondsType;
|
|
439
445
|
exports.TIMESTAMP_S = DuckDBTimestampSecondsType.instance;
|
|
@@ -456,6 +462,12 @@ class DuckDBTimestampMillisecondsType extends BaseDuckDBType {
|
|
|
456
462
|
get min() {
|
|
457
463
|
return values_1.DuckDBTimestampMillisecondsValue.Min;
|
|
458
464
|
}
|
|
465
|
+
get posInf() {
|
|
466
|
+
return values_1.DuckDBTimestampMillisecondsValue.PosInf;
|
|
467
|
+
}
|
|
468
|
+
get negInf() {
|
|
469
|
+
return values_1.DuckDBTimestampMillisecondsValue.NegInf;
|
|
470
|
+
}
|
|
459
471
|
}
|
|
460
472
|
exports.DuckDBTimestampMillisecondsType = DuckDBTimestampMillisecondsType;
|
|
461
473
|
exports.TIMESTAMP_MS = DuckDBTimestampMillisecondsType.instance;
|
|
@@ -478,6 +490,12 @@ class DuckDBTimestampNanosecondsType extends BaseDuckDBType {
|
|
|
478
490
|
get min() {
|
|
479
491
|
return values_1.DuckDBTimestampNanosecondsValue.Min;
|
|
480
492
|
}
|
|
493
|
+
get posInf() {
|
|
494
|
+
return values_1.DuckDBTimestampNanosecondsValue.PosInf;
|
|
495
|
+
}
|
|
496
|
+
get negInf() {
|
|
497
|
+
return values_1.DuckDBTimestampNanosecondsValue.NegInf;
|
|
498
|
+
}
|
|
481
499
|
}
|
|
482
500
|
exports.DuckDBTimestampNanosecondsType = DuckDBTimestampNanosecondsType;
|
|
483
501
|
exports.TIMESTAMP_NS = DuckDBTimestampNanosecondsType.instance;
|
|
@@ -557,6 +575,7 @@ function LIST(valueType, alias) {
|
|
|
557
575
|
class DuckDBStructType extends BaseDuckDBType {
|
|
558
576
|
entryNames;
|
|
559
577
|
entryTypes;
|
|
578
|
+
entryIndexes;
|
|
560
579
|
constructor(entryNames, entryTypes, alias) {
|
|
561
580
|
super(DuckDBTypeId_1.DuckDBTypeId.STRUCT, alias);
|
|
562
581
|
if (entryNames.length !== entryTypes.length) {
|
|
@@ -565,10 +584,21 @@ class DuckDBStructType extends BaseDuckDBType {
|
|
|
565
584
|
}
|
|
566
585
|
this.entryNames = entryNames;
|
|
567
586
|
this.entryTypes = entryTypes;
|
|
587
|
+
const entryIndexes = {};
|
|
588
|
+
for (let i = 0; i < entryNames.length; i++) {
|
|
589
|
+
entryIndexes[entryNames[i]] = i;
|
|
590
|
+
}
|
|
591
|
+
this.entryIndexes = entryIndexes;
|
|
568
592
|
}
|
|
569
593
|
get entryCount() {
|
|
570
594
|
return this.entryNames.length;
|
|
571
595
|
}
|
|
596
|
+
indexForEntry(entryName) {
|
|
597
|
+
return this.entryIndexes[entryName];
|
|
598
|
+
}
|
|
599
|
+
typeForEntry(entryName) {
|
|
600
|
+
return this.entryTypes[this.entryIndexes[entryName]];
|
|
601
|
+
}
|
|
572
602
|
toString() {
|
|
573
603
|
const parts = [];
|
|
574
604
|
for (let i = 0; i < this.entryNames.length; i++) {
|
|
@@ -674,6 +704,9 @@ class DuckDBUnionType extends BaseDuckDBType {
|
|
|
674
704
|
memberIndexForTag(tag) {
|
|
675
705
|
return this.tagMemberIndexes[tag];
|
|
676
706
|
}
|
|
707
|
+
memberTypeForTag(tag) {
|
|
708
|
+
return this.memberTypes[this.tagMemberIndexes[tag]];
|
|
709
|
+
}
|
|
677
710
|
get memberCount() {
|
|
678
711
|
return this.memberTags.length;
|
|
679
712
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DuckDBType } from './DuckDBType';
|
|
2
|
+
import { DuckDBValueConverter } from './DuckDBValueConverter';
|
|
3
|
+
import { DuckDBValue } from './values';
|
|
4
|
+
export type Json = null | boolean | number | string | Json[] | {
|
|
5
|
+
[key: string]: Json;
|
|
6
|
+
};
|
|
7
|
+
export declare class DuckDBValueToJsonConverter implements DuckDBValueConverter<Json> {
|
|
8
|
+
static readonly default: DuckDBValueToJsonConverter;
|
|
9
|
+
convertValue(value: DuckDBValue, type: DuckDBType): Json;
|
|
10
|
+
}
|