@malloydata/db-duckdb 0.0.22-dev230207183024 → 0.0.22-dev230208210335
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as duckdb from "@duckdb/duckdb-wasm";
|
|
2
|
-
import { QueryDataRow, RunSQLOptions } from "@malloydata/malloy";
|
|
2
|
+
import { QueryDataRow, RunSQLOptions, StructDef } from "@malloydata/malloy";
|
|
3
3
|
import { DuckDBCommon, QueryOptionsReader } from "./duckdb_common";
|
|
4
|
+
declare type RemoteFileCallback = (tableName: string) => Promise<Uint8Array | undefined>;
|
|
4
5
|
export declare abstract class DuckDBWASMConnection extends DuckDBCommon {
|
|
5
6
|
readonly name: string;
|
|
6
7
|
private databasePath;
|
|
@@ -10,6 +11,8 @@ export declare abstract class DuckDBWASMConnection extends DuckDBCommon {
|
|
|
10
11
|
protected _database: duckdb.AsyncDuckDB | null;
|
|
11
12
|
protected isSetup: boolean;
|
|
12
13
|
private worker;
|
|
14
|
+
private remoteFileCallbacks;
|
|
15
|
+
private remoteFileStatus;
|
|
13
16
|
constructor(name: string, databasePath?: string | null, workingDirectory?: string, queryOptions?: QueryOptionsReader);
|
|
14
17
|
private init;
|
|
15
18
|
abstract getBundles(): duckdb.DuckDBBundles;
|
|
@@ -21,6 +24,12 @@ export declare abstract class DuckDBWASMConnection extends DuckDBCommon {
|
|
|
21
24
|
totalRows: number;
|
|
22
25
|
}>;
|
|
23
26
|
runSQLStream(sql: string, _options?: RunSQLOptions): AsyncIterableIterator<QueryDataRow>;
|
|
27
|
+
fetchSchemaForTables(tables: string[]): Promise<{
|
|
28
|
+
schemas: Record<string, StructDef>;
|
|
29
|
+
errors: Record<string, string>;
|
|
30
|
+
}>;
|
|
24
31
|
close(): Promise<void>;
|
|
32
|
+
registerRemoteTableCallback(callback: RemoteFileCallback): void;
|
|
25
33
|
registerRemoteTable(tableName: string, url: string): Promise<void>;
|
|
26
34
|
}
|
|
35
|
+
export {};
|
|
@@ -51,6 +51,7 @@ exports.DuckDBWASMConnection = void 0;
|
|
|
51
51
|
*/
|
|
52
52
|
const duckdb = __importStar(require("@duckdb/duckdb-wasm"));
|
|
53
53
|
const web_worker_1 = __importDefault(require("web-worker"));
|
|
54
|
+
const malloy_1 = require("@malloydata/malloy");
|
|
54
55
|
const apache_arrow_1 = require("apache-arrow");
|
|
55
56
|
const duckdb_common_1 = require("./duckdb_common");
|
|
56
57
|
/**
|
|
@@ -126,6 +127,8 @@ class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
126
127
|
this._database = null;
|
|
127
128
|
this.isSetup = false;
|
|
128
129
|
this.worker = null;
|
|
130
|
+
this.remoteFileCallbacks = [];
|
|
131
|
+
this.remoteFileStatus = {};
|
|
129
132
|
this.connecting = this.init();
|
|
130
133
|
}
|
|
131
134
|
async init() {
|
|
@@ -195,6 +198,28 @@ class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
195
198
|
}
|
|
196
199
|
}
|
|
197
200
|
}
|
|
201
|
+
async fetchSchemaForTables(tables) {
|
|
202
|
+
var _a;
|
|
203
|
+
await this.setup();
|
|
204
|
+
for (const tableUri of tables) {
|
|
205
|
+
const { tablePath } = (0, malloy_1.parseTableURI)(tableUri);
|
|
206
|
+
if (tablePath.match(/^https?:\/\//)) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (this.remoteFileStatus[tablePath]) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
for (const callback of this.remoteFileCallbacks) {
|
|
213
|
+
this.remoteFileStatus[tablePath] = true;
|
|
214
|
+
const data = await callback(tablePath);
|
|
215
|
+
if (data) {
|
|
216
|
+
await ((_a = this.database) === null || _a === void 0 ? void 0 : _a.registerFileBuffer(tablePath, data));
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return super.fetchSchemaForTables(tables);
|
|
222
|
+
}
|
|
198
223
|
async close() {
|
|
199
224
|
if (this._connection) {
|
|
200
225
|
await this._connection.close();
|
|
@@ -209,6 +234,9 @@ class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
209
234
|
this.worker = null;
|
|
210
235
|
}
|
|
211
236
|
}
|
|
237
|
+
registerRemoteTableCallback(callback) {
|
|
238
|
+
this.remoteFileCallbacks.push(callback);
|
|
239
|
+
}
|
|
212
240
|
async registerRemoteTable(tableName, url) {
|
|
213
241
|
var _a;
|
|
214
242
|
(_a = this.database) === null || _a === void 0 ? void 0 : _a.registerFileURL(tableName, url, duckdb.DuckDBDataProtocol.HTTP, true);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/db-duckdb",
|
|
3
|
-
"version": "0.0.22-
|
|
3
|
+
"version": "0.0.22-dev230208210335",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@duckdb/duckdb-wasm": "^1.20.0",
|
|
41
|
-
"@malloydata/malloy": "^0.0.22-
|
|
41
|
+
"@malloydata/malloy": "^0.0.22-dev230208210335",
|
|
42
42
|
"duckdb": "0.6.1",
|
|
43
43
|
"web-worker": "^1.2.0"
|
|
44
44
|
}
|