@malloydata/db-duckdb 0.0.103-dev231115200636 → 0.0.103
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.
|
@@ -17,7 +17,7 @@ export declare class DuckDBConnection extends DuckDBCommon {
|
|
|
17
17
|
rows: TableData;
|
|
18
18
|
totalRows: number;
|
|
19
19
|
}>;
|
|
20
|
-
runSQLStream(sql: string,
|
|
20
|
+
runSQLStream(sql: string, { rowLimit, abortSignal }?: RunSQLOptions): AsyncIterableIterator<QueryDataRow>;
|
|
21
21
|
createHash(sqlCommand: string): Promise<string>;
|
|
22
22
|
close(): Promise<void>;
|
|
23
23
|
}
|
|
@@ -113,7 +113,7 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
|
-
async *runSQLStream(sql,
|
|
116
|
+
async *runSQLStream(sql, { rowLimit, abortSignal } = {}) {
|
|
117
117
|
await this.setup();
|
|
118
118
|
if (!this.connection) {
|
|
119
119
|
throw new Error('Connection not open');
|
|
@@ -123,7 +123,13 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
123
123
|
await this.runDuckDBQuery(statements[0]);
|
|
124
124
|
statements.shift();
|
|
125
125
|
}
|
|
126
|
+
let index = 0;
|
|
126
127
|
for await (const row of this.connection.stream(statements[0])) {
|
|
128
|
+
if ((rowLimit !== undefined && index >= rowLimit) ||
|
|
129
|
+
(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
index++;
|
|
127
133
|
yield row;
|
|
128
134
|
}
|
|
129
135
|
}
|
|
@@ -21,11 +21,11 @@ export declare abstract class DuckDBWASMConnection extends DuckDBCommon {
|
|
|
21
21
|
get database(): duckdb.AsyncDuckDB | null;
|
|
22
22
|
loadExtension(ext: string): Promise<void>;
|
|
23
23
|
protected setup(): Promise<void>;
|
|
24
|
-
protected runDuckDBQuery(sql: string): Promise<{
|
|
24
|
+
protected runDuckDBQuery(sql: string, abortSignal?: AbortSignal): Promise<{
|
|
25
25
|
rows: QueryDataRow[];
|
|
26
26
|
totalRows: number;
|
|
27
27
|
}>;
|
|
28
|
-
runSQLStream(sql: string,
|
|
28
|
+
runSQLStream(sql: string, { rowLimit, abortSignal }?: RunSQLOptions): AsyncIterableIterator<QueryDataRow>;
|
|
29
29
|
private findTables;
|
|
30
30
|
fetchSchemaForSQLBlock(sqlRef: SQLBlock, options: FetchSchemaOptions): Promise<{
|
|
31
31
|
structDef: StructDef;
|
|
@@ -201,10 +201,16 @@ class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
201
201
|
}
|
|
202
202
|
await this.isSetup;
|
|
203
203
|
}
|
|
204
|
-
async runDuckDBQuery(sql) {
|
|
204
|
+
async runDuckDBQuery(sql, abortSignal) {
|
|
205
205
|
var _a;
|
|
206
|
+
const cancel = () => {
|
|
207
|
+
var _a;
|
|
208
|
+
(_a = this.connection) === null || _a === void 0 ? void 0 : _a.cancelSent();
|
|
209
|
+
};
|
|
210
|
+
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.addEventListener('abort', cancel);
|
|
206
211
|
const table = await ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.query(sql));
|
|
207
|
-
|
|
212
|
+
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener('abort', cancel);
|
|
213
|
+
if (!table) {
|
|
208
214
|
throw new Error('Table is undefined.');
|
|
209
215
|
}
|
|
210
216
|
if ((table === null || table === void 0 ? void 0 : table.numRows) !== null) {
|
|
@@ -220,21 +226,38 @@ class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
220
226
|
throw new Error('Boom');
|
|
221
227
|
}
|
|
222
228
|
}
|
|
223
|
-
async *runSQLStream(sql,
|
|
229
|
+
async *runSQLStream(sql, { rowLimit, abortSignal } = {}) {
|
|
224
230
|
if (!this.connection) {
|
|
225
231
|
throw new Error('duckdb-wasm not connected');
|
|
226
232
|
}
|
|
227
233
|
await this.setup();
|
|
228
234
|
const statements = sql.split('-- hack: split on this');
|
|
235
|
+
let done = false;
|
|
236
|
+
const cancel = () => {
|
|
237
|
+
var _a;
|
|
238
|
+
done = true;
|
|
239
|
+
(_a = this.connection) === null || _a === void 0 ? void 0 : _a.cancelSent();
|
|
240
|
+
};
|
|
241
|
+
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.addEventListener('abort', cancel);
|
|
229
242
|
while (statements.length > 1) {
|
|
230
|
-
await this.runDuckDBQuery(statements[0]);
|
|
243
|
+
await this.runDuckDBQuery(statements[0], abortSignal);
|
|
231
244
|
statements.shift();
|
|
232
245
|
}
|
|
246
|
+
let index = 0;
|
|
233
247
|
for await (const chunk of await this.connection.send(statements[0])) {
|
|
248
|
+
if (done) {
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
234
251
|
for (const row of chunk.toArray()) {
|
|
252
|
+
if ((rowLimit !== undefined && index >= rowLimit) ||
|
|
253
|
+
(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
235
256
|
yield unwrapRow(row);
|
|
257
|
+
index++;
|
|
236
258
|
}
|
|
237
259
|
}
|
|
260
|
+
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener('abort', cancel);
|
|
238
261
|
}
|
|
239
262
|
async findTables(tables, { refreshTimestamp }) {
|
|
240
263
|
const fetchRemoteFile = async (tablePath) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/db-duckdb",
|
|
3
|
-
"version": "0.0.103
|
|
3
|
+
"version": "0.0.103",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@malloydata/duckdb-wasm": "0.0.6",
|
|
44
|
-
"@malloydata/malloy": "^0.0.103
|
|
45
|
-
"@malloydata/malloy-interfaces": "^0.0.103
|
|
44
|
+
"@malloydata/malloy": "^0.0.103",
|
|
45
|
+
"@malloydata/malloy-interfaces": "^0.0.103",
|
|
46
46
|
"apache-arrow": "^13.0.0",
|
|
47
47
|
"duckdb": "0.9.2",
|
|
48
48
|
"web-worker": "^1.2.0"
|