@duckdb/node-api 1.3.1-alpha.22 → 1.3.2-alpha.24
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 +0 -1
- package/lib/DuckDBAppender.d.ts +4 -2
- package/lib/DuckDBAppender.js +6 -2
- package/lib/DuckDBConnection.d.ts +1 -0
- package/lib/DuckDBConnection.js +20 -4
- package/lib/DuckDBPreparedStatement.d.ts +4 -2
- package/lib/DuckDBPreparedStatement.js +6 -1
- package/lib/createValue.js +19 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -18,7 +18,6 @@ available separately as [@duckdb/node-bindings](https://www.npmjs.com/package/@d
|
|
|
18
18
|
### Roadmap
|
|
19
19
|
|
|
20
20
|
Some features are not yet complete:
|
|
21
|
-
* Binding and appending the MAP and UNION data types
|
|
22
21
|
* Appending default values row-by-row
|
|
23
22
|
* User-defined types & functions
|
|
24
23
|
* Profiling info
|
package/lib/DuckDBAppender.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import duckdb from '@duckdb/node-bindings';
|
|
2
2
|
import { DuckDBDataChunk } from './DuckDBDataChunk';
|
|
3
|
-
import { DuckDBArrayType, DuckDBEnumType, DuckDBListType, DuckDBStructType, DuckDBType } from './DuckDBType';
|
|
4
|
-
import { DuckDBArrayValue, DuckDBBitValue, DuckDBDateValue, DuckDBDecimalValue, DuckDBIntervalValue, DuckDBListValue, DuckDBStructValue, DuckDBTimestampMillisecondsValue, DuckDBTimestampNanosecondsValue, DuckDBTimestampSecondsValue, DuckDBTimestampTZValue, DuckDBTimestampValue, DuckDBTimeTZValue, DuckDBTimeValue, DuckDBUUIDValue, DuckDBValue } from './values';
|
|
3
|
+
import { DuckDBArrayType, DuckDBEnumType, DuckDBListType, DuckDBMapType, DuckDBStructType, DuckDBType, DuckDBUnionType } from './DuckDBType';
|
|
4
|
+
import { DuckDBArrayValue, DuckDBBitValue, DuckDBDateValue, DuckDBDecimalValue, DuckDBIntervalValue, DuckDBListValue, DuckDBMapValue, DuckDBStructValue, DuckDBTimestampMillisecondsValue, DuckDBTimestampNanosecondsValue, DuckDBTimestampSecondsValue, DuckDBTimestampTZValue, DuckDBTimestampValue, DuckDBTimeTZValue, DuckDBTimeValue, DuckDBUnionValue, DuckDBUUIDValue, DuckDBValue } from './values';
|
|
5
5
|
export declare class DuckDBAppender {
|
|
6
6
|
private readonly appender;
|
|
7
7
|
constructor(appender: duckdb.Appender);
|
|
@@ -39,7 +39,9 @@ export declare class DuckDBAppender {
|
|
|
39
39
|
appendEnum(value: string, type: DuckDBEnumType): void;
|
|
40
40
|
appendList(value: DuckDBListValue | readonly DuckDBValue[], type?: DuckDBListType): void;
|
|
41
41
|
appendStruct(value: DuckDBStructValue | Readonly<Record<string, DuckDBValue>>, type?: DuckDBStructType): void;
|
|
42
|
+
appendMap(value: DuckDBMapValue, type?: DuckDBMapType): void;
|
|
42
43
|
appendArray(value: DuckDBArrayValue | readonly DuckDBValue[], type?: DuckDBArrayType): void;
|
|
44
|
+
appendUnion(value: DuckDBUnionValue, type?: DuckDBUnionType): void;
|
|
43
45
|
appendUUID(value: DuckDBUUIDValue): void;
|
|
44
46
|
appendBit(value: DuckDBBitValue): void;
|
|
45
47
|
appendVarInt(value: bigint): void;
|
package/lib/DuckDBAppender.js
CHANGED
|
@@ -118,11 +118,15 @@ class DuckDBAppender {
|
|
|
118
118
|
appendStruct(value, type) {
|
|
119
119
|
this.appendValue(value instanceof values_1.DuckDBStructValue ? value : (0, values_1.structValue)(value), type);
|
|
120
120
|
}
|
|
121
|
-
|
|
121
|
+
appendMap(value, type) {
|
|
122
|
+
this.appendValue(value, type);
|
|
123
|
+
}
|
|
122
124
|
appendArray(value, type) {
|
|
123
125
|
this.appendValue(value instanceof values_1.DuckDBArrayValue ? value : (0, values_1.arrayValue)(value), type);
|
|
124
126
|
}
|
|
125
|
-
|
|
127
|
+
appendUnion(value, type) {
|
|
128
|
+
this.appendValue(value, type);
|
|
129
|
+
}
|
|
126
130
|
appendUUID(value) {
|
|
127
131
|
this.appendValue(value, DuckDBType_1.UUID);
|
|
128
132
|
}
|
|
@@ -32,5 +32,6 @@ export declare class DuckDBConnection {
|
|
|
32
32
|
prepare(sql: string): Promise<DuckDBPreparedStatement>;
|
|
33
33
|
private createPrepared;
|
|
34
34
|
extractStatements(sql: string): Promise<DuckDBExtractedStatements>;
|
|
35
|
+
private runUntilLast;
|
|
35
36
|
createAppender(table: string, schema?: string | null, catalog?: string | null): Promise<DuckDBAppender>;
|
|
36
37
|
}
|
package/lib/DuckDBConnection.js
CHANGED
|
@@ -41,7 +41,7 @@ class DuckDBConnection {
|
|
|
41
41
|
}
|
|
42
42
|
async run(sql, values, types) {
|
|
43
43
|
if (values) {
|
|
44
|
-
const prepared = await this.
|
|
44
|
+
const prepared = await this.runUntilLast(sql);
|
|
45
45
|
try {
|
|
46
46
|
prepared.bind(values, types);
|
|
47
47
|
const result = await prepared.run();
|
|
@@ -69,7 +69,7 @@ class DuckDBConnection {
|
|
|
69
69
|
return reader;
|
|
70
70
|
}
|
|
71
71
|
async stream(sql, values, types) {
|
|
72
|
-
const prepared = await this.
|
|
72
|
+
const prepared = await this.runUntilLast(sql);
|
|
73
73
|
try {
|
|
74
74
|
if (values) {
|
|
75
75
|
prepared.bind(values, types);
|
|
@@ -95,7 +95,7 @@ class DuckDBConnection {
|
|
|
95
95
|
return reader;
|
|
96
96
|
}
|
|
97
97
|
async start(sql, values, types) {
|
|
98
|
-
const prepared = await this.
|
|
98
|
+
const prepared = await this.runUntilLast(sql);
|
|
99
99
|
try {
|
|
100
100
|
if (values) {
|
|
101
101
|
prepared.bind(values, types);
|
|
@@ -107,7 +107,7 @@ class DuckDBConnection {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
async startStream(sql, values, types) {
|
|
110
|
-
const prepared = await this.
|
|
110
|
+
const prepared = await this.runUntilLast(sql);
|
|
111
111
|
try {
|
|
112
112
|
if (values) {
|
|
113
113
|
prepared.bind(values, types);
|
|
@@ -133,6 +133,22 @@ class DuckDBConnection {
|
|
|
133
133
|
}
|
|
134
134
|
return new DuckDBExtractedStatements_1.DuckDBExtractedStatements(this.connection, extracted_statements, statement_count, this.preparedStatements);
|
|
135
135
|
}
|
|
136
|
+
async runUntilLast(sql) {
|
|
137
|
+
const extractedStatements = await this.extractStatements(sql);
|
|
138
|
+
const statementCount = extractedStatements.count;
|
|
139
|
+
if (statementCount > 1) {
|
|
140
|
+
for (let i = 0; i < statementCount - 1; i++) {
|
|
141
|
+
const prepared = await extractedStatements.prepare(i);
|
|
142
|
+
try {
|
|
143
|
+
await prepared.run();
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
prepared.destroySync();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return extractedStatements.prepare(statementCount - 1);
|
|
151
|
+
}
|
|
136
152
|
async createAppender(table, schema, catalog) {
|
|
137
153
|
return new DuckDBAppender_1.DuckDBAppender(node_bindings_1.default.appender_create_ext(this.connection, catalog ?? null, schema ?? null, table));
|
|
138
154
|
}
|
|
@@ -3,10 +3,10 @@ import { DuckDBMaterializedResult } from './DuckDBMaterializedResult';
|
|
|
3
3
|
import { DuckDBPendingResult } from './DuckDBPendingResult';
|
|
4
4
|
import { DuckDBResult } from './DuckDBResult';
|
|
5
5
|
import { DuckDBResultReader } from './DuckDBResultReader';
|
|
6
|
-
import { DuckDBArrayType, DuckDBEnumType, DuckDBListType, DuckDBStructType, DuckDBType } from './DuckDBType';
|
|
6
|
+
import { DuckDBArrayType, DuckDBEnumType, DuckDBListType, DuckDBMapType, DuckDBStructType, DuckDBType, DuckDBUnionType } from './DuckDBType';
|
|
7
7
|
import { DuckDBTypeId } from './DuckDBTypeId';
|
|
8
8
|
import { StatementType } from './enums';
|
|
9
|
-
import { DuckDBArrayValue, DuckDBBitValue, DuckDBDateValue, DuckDBDecimalValue, DuckDBIntervalValue, DuckDBListValue, DuckDBStructValue, DuckDBTimestampMillisecondsValue, DuckDBTimestampNanosecondsValue, DuckDBTimestampSecondsValue, DuckDBTimestampTZValue, DuckDBTimestampValue, DuckDBTimeTZValue, DuckDBTimeValue, DuckDBUUIDValue, DuckDBValue } from './values';
|
|
9
|
+
import { DuckDBArrayValue, DuckDBBitValue, DuckDBDateValue, DuckDBDecimalValue, DuckDBIntervalValue, DuckDBListValue, DuckDBMapValue, DuckDBStructValue, DuckDBTimestampMillisecondsValue, DuckDBTimestampNanosecondsValue, DuckDBTimestampSecondsValue, DuckDBTimestampTZValue, DuckDBTimestampValue, DuckDBTimeTZValue, DuckDBTimeValue, DuckDBUnionValue, DuckDBUUIDValue, DuckDBValue } from './values';
|
|
10
10
|
export declare class DuckDBPreparedStatement {
|
|
11
11
|
private readonly prepared_statement;
|
|
12
12
|
constructor(prepared_statement: duckdb.PreparedStatement);
|
|
@@ -48,6 +48,8 @@ export declare class DuckDBPreparedStatement {
|
|
|
48
48
|
bindArray(parameterIndex: number, value: DuckDBArrayValue | readonly DuckDBValue[], type?: DuckDBArrayType): void;
|
|
49
49
|
bindList(parameterIndex: number, value: DuckDBListValue | readonly DuckDBValue[], type?: DuckDBListType): void;
|
|
50
50
|
bindStruct(parameterIndex: number, value: DuckDBStructValue | Readonly<Record<string, DuckDBValue>>, type?: DuckDBStructType): void;
|
|
51
|
+
bindMap(parameterIndex: number, value: DuckDBMapValue, type?: DuckDBMapType): void;
|
|
52
|
+
bindUnion(parameterIndex: number, value: DuckDBUnionValue, type?: DuckDBUnionType): void;
|
|
51
53
|
bindUUID(parameterIndex: number, value: DuckDBUUIDValue): void;
|
|
52
54
|
bindBit(parameterIndex: number, value: DuckDBBitValue): void;
|
|
53
55
|
bindNull(parameterIndex: number): void;
|
|
@@ -133,7 +133,12 @@ class DuckDBPreparedStatement {
|
|
|
133
133
|
bindStruct(parameterIndex, value, type) {
|
|
134
134
|
this.bindValue(parameterIndex, value instanceof values_1.DuckDBStructValue ? value : (0, values_1.structValue)(value), type);
|
|
135
135
|
}
|
|
136
|
-
|
|
136
|
+
bindMap(parameterIndex, value, type) {
|
|
137
|
+
this.bindValue(parameterIndex, value, type);
|
|
138
|
+
}
|
|
139
|
+
bindUnion(parameterIndex, value, type) {
|
|
140
|
+
this.bindValue(parameterIndex, value, type);
|
|
141
|
+
}
|
|
137
142
|
bindUUID(parameterIndex, value) {
|
|
138
143
|
this.bindValue(parameterIndex, value, DuckDBType_1.UUID);
|
|
139
144
|
}
|
package/lib/createValue.js
CHANGED
|
@@ -150,7 +150,16 @@ function createValue(type, input) {
|
|
|
150
150
|
}
|
|
151
151
|
throw new Error(`input is not a DuckDBStructValue`);
|
|
152
152
|
case DuckDBTypeId_1.DuckDBTypeId.MAP:
|
|
153
|
-
|
|
153
|
+
if (input instanceof values_1.DuckDBMapValue) {
|
|
154
|
+
if (type.keyType.typeId === DuckDBTypeId_1.DuckDBTypeId.ANY) {
|
|
155
|
+
throw new Error('Cannot create maps with key type of ANY. Specify a specific type.');
|
|
156
|
+
}
|
|
157
|
+
if (type.valueType.typeId === DuckDBTypeId_1.DuckDBTypeId.ANY) {
|
|
158
|
+
throw new Error('Cannot create maps with value type of ANY. Specify a specific type.');
|
|
159
|
+
}
|
|
160
|
+
return node_bindings_1.default.create_map_value(type.toLogicalType().logical_type, input.entries.map((entry) => createValue(type.keyType, entry.key)), input.entries.map((entry) => createValue(type.valueType, entry.value)));
|
|
161
|
+
}
|
|
162
|
+
throw new Error(`input is not a DuckDBMapValue`);
|
|
154
163
|
case DuckDBTypeId_1.DuckDBTypeId.ARRAY:
|
|
155
164
|
if (input instanceof values_1.DuckDBArrayValue) {
|
|
156
165
|
if (type.valueType.typeId === DuckDBTypeId_1.DuckDBTypeId.ANY) {
|
|
@@ -165,7 +174,15 @@ function createValue(type, input) {
|
|
|
165
174
|
}
|
|
166
175
|
throw new Error(`input is not a bigint`);
|
|
167
176
|
case DuckDBTypeId_1.DuckDBTypeId.UNION:
|
|
168
|
-
|
|
177
|
+
if (input instanceof values_1.DuckDBUnionValue) {
|
|
178
|
+
const tagIndex = type.memberIndexForTag(input.tag);
|
|
179
|
+
const memberType = type.memberTypes[tagIndex];
|
|
180
|
+
if (memberType.typeId === DuckDBTypeId_1.DuckDBTypeId.ANY) {
|
|
181
|
+
throw new Error('Cannot create union values with type of ANY.');
|
|
182
|
+
}
|
|
183
|
+
return node_bindings_1.default.create_union_value(type.toLogicalType().logical_type, tagIndex, createValue(memberType, input.value));
|
|
184
|
+
}
|
|
185
|
+
throw new Error(`input is not a DuckDBUnionValue`);
|
|
169
186
|
case DuckDBTypeId_1.DuckDBTypeId.BIT:
|
|
170
187
|
if (input instanceof values_1.DuckDBBitValue) {
|
|
171
188
|
return node_bindings_1.default.create_bit(input.data);
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@duckdb/node-api",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2-alpha.24",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@duckdb/node-bindings": "1.3.
|
|
8
|
+
"@duckdb/node-bindings": "1.3.2-alpha.24"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|