@malloydata/db-duckdb 0.0.29-dev230329215340 → 0.0.29-dev230330224139
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/dist/duckdb_connection.d.ts +1 -0
- package/dist/duckdb_connection.js +12 -15
- package/dist/duckdb_wasm_connection.d.ts +11 -3
- package/dist/duckdb_wasm_connection.js +20 -5
- package/dist/duckdb_wasm_connection_browser.d.ts +1 -1
- package/dist/duckdb_wasm_connection_browser.js +1 -1
- package/dist/duckdb_wasm_connection_node.d.ts +1 -1
- package/dist/duckdb_wasm_connection_node.js +3 -3
- package/package.json +3 -3
|
@@ -11,6 +11,7 @@ export declare class DuckDBConnection extends DuckDBCommon {
|
|
|
11
11
|
protected isSetup: Promise<void> | undefined;
|
|
12
12
|
constructor(name: string, databasePath?: string, workingDirectory?: string, queryOptions?: QueryOptionsReader);
|
|
13
13
|
private init;
|
|
14
|
+
loadExtension(ext: string): Promise<void>;
|
|
14
15
|
protected setup(): Promise<void>;
|
|
15
16
|
protected runDuckDBQuery(sql: string): Promise<{
|
|
16
17
|
rows: Row[];
|
|
@@ -52,26 +52,23 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
52
52
|
resolve();
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
+
async loadExtension(ext) {
|
|
56
|
+
try {
|
|
57
|
+
await this.runDuckDBQuery(`INSTALL '${ext}'`);
|
|
58
|
+
await this.runDuckDBQuery(`LOAD '${ext}'`);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
// eslint-disable-next-line no-console
|
|
62
|
+
console.error('Unable to load ${ext} extension', error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
55
65
|
async setup() {
|
|
56
66
|
const doSetup = async () => {
|
|
57
67
|
if (this.workingDirectory) {
|
|
58
68
|
await this.runDuckDBQuery(`SET FILE_SEARCH_PATH='${this.workingDirectory}'`);
|
|
59
69
|
}
|
|
60
|
-
|
|
61
|
-
await this.
|
|
62
|
-
await this.runDuckDBQuery("LOAD 'json'");
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
// eslint-disable-next-line no-console
|
|
66
|
-
console.error('Unable to load json extension', error);
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
await this.runDuckDBQuery("INSTALL 'httpfs'");
|
|
70
|
-
await this.runDuckDBQuery("LOAD 'httpfs'");
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
// eslint-disable-next-line no-console
|
|
74
|
-
console.error('Unable to load httpfs extension', error);
|
|
70
|
+
for (const ext of ['json', 'httpfs', 'icu']) {
|
|
71
|
+
await this.loadExtension(ext);
|
|
75
72
|
}
|
|
76
73
|
};
|
|
77
74
|
await this.connecting;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as duckdb from '@
|
|
2
|
-
import { QueryDataRow, RunSQLOptions, StructDef } from '@malloydata/malloy';
|
|
1
|
+
import * as duckdb from '@malloydata/duckdb-wasm';
|
|
2
|
+
import { QueryDataRow, RunSQLOptions, StructDef, SQLBlock } from '@malloydata/malloy';
|
|
3
3
|
import { DuckDBCommon, QueryOptionsReader } from './duckdb_common';
|
|
4
4
|
declare type RemoteFileCallback = (tableName: string) => Promise<Uint8Array | undefined>;
|
|
5
5
|
export declare abstract class DuckDBWASMConnection extends DuckDBCommon {
|
|
@@ -24,7 +24,15 @@ export declare abstract class DuckDBWASMConnection extends DuckDBCommon {
|
|
|
24
24
|
totalRows: number;
|
|
25
25
|
}>;
|
|
26
26
|
runSQLStream(sql: string, _options?: RunSQLOptions): AsyncIterableIterator<QueryDataRow>;
|
|
27
|
-
|
|
27
|
+
private findTables;
|
|
28
|
+
fetchSchemaForSQLBlock(sqlRef: SQLBlock): Promise<{
|
|
29
|
+
structDef: StructDef;
|
|
30
|
+
error?: undefined;
|
|
31
|
+
} | {
|
|
32
|
+
error: string;
|
|
33
|
+
structDef?: undefined;
|
|
34
|
+
}>;
|
|
35
|
+
fetchSchemaForTables(tableUris: string[]): Promise<{
|
|
28
36
|
schemas: Record<string, StructDef>;
|
|
29
37
|
errors: Record<string, string>;
|
|
30
38
|
}>;
|
|
@@ -49,11 +49,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
49
49
|
};
|
|
50
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
51
|
exports.DuckDBWASMConnection = void 0;
|
|
52
|
-
const duckdb = __importStar(require("@
|
|
52
|
+
const duckdb = __importStar(require("@malloydata/duckdb-wasm"));
|
|
53
53
|
const web_worker_1 = __importDefault(require("web-worker"));
|
|
54
54
|
const malloy_1 = require("@malloydata/malloy");
|
|
55
55
|
const apache_arrow_1 = require("apache-arrow");
|
|
56
56
|
const duckdb_common_1 = require("./duckdb_common");
|
|
57
|
+
const TABLE_MATCH = /FROM\s*'(.*)'/gi;
|
|
57
58
|
/**
|
|
58
59
|
* Arrow's toJSON() doesn't really do what I'd expect, since
|
|
59
60
|
* it still includes Arrow objects like DecimalBigNums and Vectors,
|
|
@@ -201,7 +202,7 @@ class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
201
202
|
}
|
|
202
203
|
}
|
|
203
204
|
}
|
|
204
|
-
async
|
|
205
|
+
async findTables(tables) {
|
|
205
206
|
const fetchRemoteFile = async (tablePath) => {
|
|
206
207
|
var _a;
|
|
207
208
|
for (const callback of this.remoteFileCallbacks) {
|
|
@@ -214,8 +215,7 @@ class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
214
215
|
return true;
|
|
215
216
|
};
|
|
216
217
|
await this.setup();
|
|
217
|
-
for (const
|
|
218
|
-
const { tablePath } = (0, malloy_1.parseTableURI)(tableUri);
|
|
218
|
+
for (const tablePath of tables) {
|
|
219
219
|
// http and s3 urls are handled by duckdb-wasm
|
|
220
220
|
if (tablePath.match(/^https?:\/\//)) {
|
|
221
221
|
continue;
|
|
@@ -230,7 +230,22 @@ class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
230
230
|
// Wait for response
|
|
231
231
|
await this.remoteFileStatus[tablePath];
|
|
232
232
|
}
|
|
233
|
-
|
|
233
|
+
}
|
|
234
|
+
async fetchSchemaForSQLBlock(sqlRef) {
|
|
235
|
+
const tables = [];
|
|
236
|
+
for (const match of sqlRef.selectStr.matchAll(TABLE_MATCH)) {
|
|
237
|
+
tables.push(match[1]);
|
|
238
|
+
}
|
|
239
|
+
await this.findTables(tables);
|
|
240
|
+
return super.fetchSchemaForSQLBlock(sqlRef);
|
|
241
|
+
}
|
|
242
|
+
async fetchSchemaForTables(tableUris) {
|
|
243
|
+
const tables = tableUris.map(tableUri => {
|
|
244
|
+
const { tablePath } = (0, malloy_1.parseTableURI)(tableUri);
|
|
245
|
+
return tablePath;
|
|
246
|
+
});
|
|
247
|
+
await this.findTables(tables);
|
|
248
|
+
return super.fetchSchemaForTables(tableUris);
|
|
234
249
|
}
|
|
235
250
|
async close() {
|
|
236
251
|
if (this._connection) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as duckdb from '@
|
|
1
|
+
import * as duckdb from '@malloydata/duckdb-wasm';
|
|
2
2
|
import { DuckDBWASMConnection as DuckDBWASMConnectionBase } from './duckdb_wasm_connection';
|
|
3
3
|
export declare class DuckDBWASMConnection extends DuckDBWASMConnectionBase {
|
|
4
4
|
getBundles(): duckdb.DuckDBBundles;
|
|
@@ -46,7 +46,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
46
46
|
};
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
48
|
exports.DuckDBWASMConnection = void 0;
|
|
49
|
-
const duckdb = __importStar(require("@
|
|
49
|
+
const duckdb = __importStar(require("@malloydata/duckdb-wasm"));
|
|
50
50
|
const duckdb_wasm_connection_1 = require("./duckdb_wasm_connection");
|
|
51
51
|
class DuckDBWASMConnection extends duckdb_wasm_connection_1.DuckDBWASMConnection {
|
|
52
52
|
getBundles() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DuckDBBundles } from '@
|
|
1
|
+
import { DuckDBBundles } from '@malloydata/duckdb-wasm';
|
|
2
2
|
import { DuckDBWASMConnection as DuckDBWASMConnectionBase } from './duckdb_wasm_connection';
|
|
3
3
|
export declare class DuckDBWASMConnection extends DuckDBWASMConnectionBase {
|
|
4
4
|
getBundles(): DuckDBBundles;
|
|
@@ -30,13 +30,13 @@ const crypto_1 = __importDefault(require("crypto"));
|
|
|
30
30
|
const duckdb_wasm_connection_1 = require("./duckdb_wasm_connection");
|
|
31
31
|
class DuckDBWASMConnection extends duckdb_wasm_connection_1.DuckDBWASMConnection {
|
|
32
32
|
getBundles() {
|
|
33
|
-
const resolvePath = require.resolve('@
|
|
33
|
+
const resolvePath = require.resolve('@malloydata/duckdb-wasm');
|
|
34
34
|
if (!resolvePath) {
|
|
35
|
-
throw new Error('Unable to resolve @
|
|
35
|
+
throw new Error('Unable to resolve @malloydata/duckdb-wasm path');
|
|
36
36
|
}
|
|
37
37
|
const distMatch = resolvePath.match(/^.*\/dist\//);
|
|
38
38
|
if (!distMatch) {
|
|
39
|
-
throw new Error('Unable to resolve @
|
|
39
|
+
throw new Error('Unable to resolve @malloydata/duckdb-wasm dist path');
|
|
40
40
|
}
|
|
41
41
|
const dist = distMatch[0];
|
|
42
42
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/db-duckdb",
|
|
3
|
-
"version": "0.0.29-
|
|
3
|
+
"version": "0.0.29-dev230330224139",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"prepublishOnly": "npm run build"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@
|
|
44
|
-
"@malloydata/malloy": "^0.0.29-
|
|
43
|
+
"@malloydata/duckdb-wasm": "0.0.1",
|
|
44
|
+
"@malloydata/malloy": "^0.0.29-dev230330224139",
|
|
45
45
|
"apache-arrow": "^11.0.0",
|
|
46
46
|
"duckdb": "0.7.1",
|
|
47
47
|
"web-worker": "^1.2.0"
|