@malloydata/db-duckdb 0.0.24-dev230224184907 → 0.0.24-dev230228224434
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_common.d.ts +1 -1
- package/dist/duckdb_common.js +69 -69
- package/dist/duckdb_connection.d.ts +3 -3
- package/dist/duckdb_connection.js +10 -9
- package/dist/duckdb_wasm_connection.d.ts +3 -3
- package/dist/duckdb_wasm_connection.js +15 -12
- package/dist/duckdb_wasm_connection_browser.d.ts +2 -2
- package/dist/duckdb_wasm_connection_browser.js +3 -3
- package/dist/duckdb_wasm_connection_node.d.ts +2 -2
- package/dist/duckdb_wasm_connection_node.js +11 -11
- package/dist/index.d.ts +1 -1
- package/package.json +6 -2
package/dist/duckdb_common.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Connection, MalloyQueryData, PersistSQLResults, PooledConnection, QueryDataRow, RunSQLOptions, SQLBlock, StreamingConnection, StructDef } from
|
|
1
|
+
import { Connection, MalloyQueryData, PersistSQLResults, PooledConnection, QueryDataRow, RunSQLOptions, SQLBlock, StreamingConnection, StructDef } from '@malloydata/malloy';
|
|
2
2
|
export interface DuckDBQueryOptions {
|
|
3
3
|
rowLimit: number;
|
|
4
4
|
}
|
package/dist/duckdb_common.js
CHANGED
|
@@ -25,25 +25,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.DuckDBCommon = void 0;
|
|
26
26
|
const malloy_1 = require("@malloydata/malloy");
|
|
27
27
|
const duckDBToMalloyTypes = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
BIGINT: 'number',
|
|
29
|
+
DOUBLE: 'number',
|
|
30
|
+
VARCHAR: 'string',
|
|
31
|
+
DATE: 'date',
|
|
32
|
+
TIMESTAMP: 'timestamp',
|
|
33
|
+
TIME: 'string',
|
|
34
|
+
DECIMAL: 'number',
|
|
35
|
+
BOOLEAN: 'boolean',
|
|
36
|
+
INTEGER: 'number',
|
|
37
37
|
};
|
|
38
38
|
class DuckDBCommon {
|
|
39
39
|
constructor(queryOptions) {
|
|
40
40
|
this.queryOptions = queryOptions;
|
|
41
41
|
this.schemaCache = new Map();
|
|
42
42
|
this.sqlSchemaCache = new Map();
|
|
43
|
-
this.name =
|
|
43
|
+
this.name = 'duckdb_common';
|
|
44
44
|
}
|
|
45
45
|
get dialectName() {
|
|
46
|
-
return
|
|
46
|
+
return 'duckdb';
|
|
47
47
|
}
|
|
48
48
|
readQueryOptions() {
|
|
49
49
|
const options = DuckDBCommon.DEFAULT_QUERY_OPTIONS;
|
|
@@ -73,7 +73,7 @@ class DuckDBCommon {
|
|
|
73
73
|
var _a;
|
|
74
74
|
const defaultOptions = this.readQueryOptions();
|
|
75
75
|
const rowLimit = (_a = options.rowLimit) !== null && _a !== void 0 ? _a : defaultOptions.rowLimit;
|
|
76
|
-
const statements = sql.split(
|
|
76
|
+
const statements = sql.split('-- hack: split on this');
|
|
77
77
|
while (statements.length > 1) {
|
|
78
78
|
await this.runRawSQL(statements[0]);
|
|
79
79
|
statements.shift();
|
|
@@ -83,23 +83,23 @@ class DuckDBCommon {
|
|
|
83
83
|
if (result.length > rowLimit) {
|
|
84
84
|
result = result.slice(0, rowLimit);
|
|
85
85
|
}
|
|
86
|
-
return {
|
|
86
|
+
return { rows: result, totalRows: result.length };
|
|
87
87
|
}
|
|
88
88
|
async getSQLBlockSchema(sqlRef) {
|
|
89
89
|
const structDef = {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
90
|
+
type: 'struct',
|
|
91
|
+
dialect: 'duckdb',
|
|
92
|
+
name: sqlRef.name,
|
|
93
|
+
structSource: {
|
|
94
|
+
type: 'sql',
|
|
95
|
+
method: 'subquery',
|
|
96
|
+
sqlBlock: sqlRef,
|
|
97
97
|
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
structRelationship: {
|
|
99
|
+
type: 'basetable',
|
|
100
|
+
connectionName: this.name,
|
|
101
101
|
},
|
|
102
|
-
|
|
102
|
+
fields: [],
|
|
103
103
|
};
|
|
104
104
|
await this.schemaFromQuery(`DESCRIBE SELECT * FROM (${sqlRef.selectStr})`, structDef);
|
|
105
105
|
return structDef;
|
|
@@ -117,27 +117,27 @@ class DuckDBCommon {
|
|
|
117
117
|
splitColumns(s) {
|
|
118
118
|
const columns = [];
|
|
119
119
|
let parens = 0;
|
|
120
|
-
let column =
|
|
120
|
+
let column = '';
|
|
121
121
|
let eatSpaces = true;
|
|
122
122
|
for (let idx = 0; idx < s.length; idx++) {
|
|
123
123
|
const c = s.charAt(idx);
|
|
124
|
-
if (eatSpaces && c ===
|
|
124
|
+
if (eatSpaces && c === ' ') {
|
|
125
125
|
// Eat space
|
|
126
126
|
}
|
|
127
127
|
else {
|
|
128
128
|
eatSpaces = false;
|
|
129
|
-
if (!parens && c ===
|
|
129
|
+
if (!parens && c === ',') {
|
|
130
130
|
columns.push(column);
|
|
131
|
-
column =
|
|
131
|
+
column = '';
|
|
132
132
|
eatSpaces = true;
|
|
133
133
|
}
|
|
134
134
|
else {
|
|
135
135
|
column += c;
|
|
136
136
|
}
|
|
137
|
-
if (c ===
|
|
137
|
+
if (c === '(') {
|
|
138
138
|
parens += 1;
|
|
139
139
|
}
|
|
140
|
-
else if (c ===
|
|
140
|
+
else if (c === ')') {
|
|
141
141
|
parens -= 1;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
@@ -152,7 +152,7 @@ class DuckDBCommon {
|
|
|
152
152
|
//const [name, type] = c.split(" ", 1);
|
|
153
153
|
const columnMatch = c.match(/^(?<name>[^\s]+) (?<type>.*)$/);
|
|
154
154
|
if (columnMatch && columnMatch.groups) {
|
|
155
|
-
ret[columnMatch.groups[
|
|
155
|
+
ret[columnMatch.groups['name']] = columnMatch.groups['type'];
|
|
156
156
|
}
|
|
157
157
|
else {
|
|
158
158
|
throw new Error(`Badly form Structure definition ${s}`);
|
|
@@ -164,26 +164,26 @@ class DuckDBCommon {
|
|
|
164
164
|
for (const name in typeMap) {
|
|
165
165
|
let duckDBType = typeMap[name];
|
|
166
166
|
// Remove DECIMAL(x,y) precision to simplify lookup
|
|
167
|
-
duckDBType = duckDBType.replace(/^DECIMAL\(\d+,\d+\)/g,
|
|
167
|
+
duckDBType = duckDBType.replace(/^DECIMAL\(\d+,\d+\)/g, 'DECIMAL');
|
|
168
168
|
let malloyType = duckDBToMalloyTypes[duckDBType];
|
|
169
169
|
const arrayMatch = duckDBType.match(/(?<duckDBType>.*)\[\]$/);
|
|
170
170
|
if (arrayMatch && arrayMatch.groups) {
|
|
171
|
-
duckDBType = arrayMatch.groups[
|
|
171
|
+
duckDBType = arrayMatch.groups['duckDBType'];
|
|
172
172
|
}
|
|
173
173
|
const structMatch = duckDBType.match(/^STRUCT\((?<fields>.*)\)$/);
|
|
174
174
|
if (structMatch && structMatch.groups) {
|
|
175
|
-
const newTypeMap = this.stringToTypeMap(structMatch.groups[
|
|
175
|
+
const newTypeMap = this.stringToTypeMap(structMatch.groups['fields']);
|
|
176
176
|
const innerStructDef = {
|
|
177
|
-
|
|
177
|
+
type: 'struct',
|
|
178
178
|
name,
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
179
|
+
dialect: this.dialectName,
|
|
180
|
+
structSource: { type: arrayMatch ? 'nested' : 'inline' },
|
|
181
|
+
structRelationship: {
|
|
182
|
+
type: arrayMatch ? 'nested' : 'inline',
|
|
183
|
+
field: name,
|
|
184
|
+
isArray: false,
|
|
185
185
|
},
|
|
186
|
-
|
|
186
|
+
fields: [],
|
|
187
187
|
};
|
|
188
188
|
this.fillStructDefFromTypeMap(innerStructDef, newTypeMap);
|
|
189
189
|
structDef.fields.push(innerStructDef);
|
|
@@ -192,28 +192,28 @@ class DuckDBCommon {
|
|
|
192
192
|
if (arrayMatch) {
|
|
193
193
|
malloyType = duckDBToMalloyTypes[duckDBType];
|
|
194
194
|
const innerStructDef = {
|
|
195
|
-
|
|
195
|
+
type: 'struct',
|
|
196
196
|
name,
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
197
|
+
dialect: this.dialectName,
|
|
198
|
+
structSource: { type: 'nested' },
|
|
199
|
+
structRelationship: {
|
|
200
|
+
type: 'nested',
|
|
201
|
+
field: name,
|
|
202
|
+
isArray: true,
|
|
203
203
|
},
|
|
204
|
-
|
|
204
|
+
fields: [{ type: malloyType, name: 'value' }],
|
|
205
205
|
};
|
|
206
206
|
structDef.fields.push(innerStructDef);
|
|
207
207
|
}
|
|
208
208
|
else {
|
|
209
209
|
if (malloyType) {
|
|
210
|
-
structDef.fields.push({
|
|
210
|
+
structDef.fields.push({ type: malloyType, name });
|
|
211
211
|
}
|
|
212
212
|
else {
|
|
213
213
|
structDef.fields.push({
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
name
|
|
214
|
+
type: 'unsupported',
|
|
215
|
+
rawType: duckDBType.toLowerCase(),
|
|
216
|
+
name,
|
|
217
217
|
});
|
|
218
218
|
}
|
|
219
219
|
}
|
|
@@ -224,7 +224,7 @@ class DuckDBCommon {
|
|
|
224
224
|
const typeMap = {};
|
|
225
225
|
const result = await this.runRawSQL(infoQuery);
|
|
226
226
|
for (const row of result.rows) {
|
|
227
|
-
typeMap[row[
|
|
227
|
+
typeMap[row['column_name']] = row['column_type'];
|
|
228
228
|
}
|
|
229
229
|
this.fillStructDefFromTypeMap(structDef, typeMap);
|
|
230
230
|
}
|
|
@@ -234,11 +234,11 @@ class DuckDBCommon {
|
|
|
234
234
|
if (!inCache) {
|
|
235
235
|
try {
|
|
236
236
|
inCache = {
|
|
237
|
-
|
|
237
|
+
structDef: await this.getSQLBlockSchema(sqlRef),
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
240
|
catch (error) {
|
|
241
|
-
inCache = {
|
|
241
|
+
inCache = { error: error.message };
|
|
242
242
|
}
|
|
243
243
|
this.sqlSchemaCache.set(key, inCache);
|
|
244
244
|
}
|
|
@@ -252,12 +252,12 @@ class DuckDBCommon {
|
|
|
252
252
|
if (!inCache) {
|
|
253
253
|
try {
|
|
254
254
|
inCache = {
|
|
255
|
-
|
|
255
|
+
schema: await this.getTableSchema(tableURL),
|
|
256
256
|
};
|
|
257
257
|
this.schemaCache.set(tableURL, inCache);
|
|
258
258
|
}
|
|
259
259
|
catch (error) {
|
|
260
|
-
inCache = {
|
|
260
|
+
inCache = { error: error.message };
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
if (inCache.schema !== undefined) {
|
|
@@ -272,15 +272,15 @@ class DuckDBCommon {
|
|
|
272
272
|
async getTableSchema(tableURL) {
|
|
273
273
|
const { tablePath } = (0, malloy_1.parseTableURI)(tableURL);
|
|
274
274
|
const structDef = {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
275
|
+
type: 'struct',
|
|
276
|
+
name: tablePath,
|
|
277
|
+
dialect: 'duckdb',
|
|
278
|
+
structSource: { type: 'table', tablePath },
|
|
279
|
+
structRelationship: {
|
|
280
|
+
type: 'basetable',
|
|
281
|
+
connectionName: this.name,
|
|
282
282
|
},
|
|
283
|
-
|
|
283
|
+
fields: [],
|
|
284
284
|
};
|
|
285
285
|
const quotedTablePath = tablePath.match(/[:*/]/)
|
|
286
286
|
? `'${tablePath}'`
|
|
@@ -293,7 +293,7 @@ class DuckDBCommon {
|
|
|
293
293
|
return true;
|
|
294
294
|
}
|
|
295
295
|
async test() {
|
|
296
|
-
await this.runRawSQL(
|
|
296
|
+
await this.runRawSQL('SELECT 1');
|
|
297
297
|
}
|
|
298
298
|
async manifestTemporaryTable(sqlCommand) {
|
|
299
299
|
const hash = await this.createHash(sqlCommand);
|
|
@@ -306,6 +306,6 @@ class DuckDBCommon {
|
|
|
306
306
|
}
|
|
307
307
|
exports.DuckDBCommon = DuckDBCommon;
|
|
308
308
|
DuckDBCommon.DEFAULT_QUERY_OPTIONS = {
|
|
309
|
-
|
|
309
|
+
rowLimit: 10,
|
|
310
310
|
};
|
|
311
311
|
//# sourceMappingURL=duckdb_common.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DuckDBCommon, QueryOptionsReader } from
|
|
2
|
-
import { Connection, Database, Row } from
|
|
3
|
-
import { QueryDataRow, RunSQLOptions } from
|
|
1
|
+
import { DuckDBCommon, QueryOptionsReader } from './duckdb_common';
|
|
2
|
+
import { Connection, Database, Row } from 'duckdb';
|
|
3
|
+
import { QueryDataRow, RunSQLOptions } from '@malloydata/malloy';
|
|
4
4
|
export declare class DuckDBConnection extends DuckDBCommon {
|
|
5
5
|
readonly name: string;
|
|
6
6
|
private databasePath;
|
|
@@ -30,7 +30,7 @@ const crypto_1 = __importDefault(require("crypto"));
|
|
|
30
30
|
const duckdb_common_1 = require("./duckdb_common");
|
|
31
31
|
const duckdb_1 = require("duckdb");
|
|
32
32
|
class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
|
|
33
|
-
constructor(name, databasePath =
|
|
33
|
+
constructor(name, databasePath = ':memory:', workingDirectory = '.', queryOptions) {
|
|
34
34
|
super(queryOptions);
|
|
35
35
|
this.name = name;
|
|
36
36
|
this.databasePath = databasePath;
|
|
@@ -42,7 +42,8 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
42
42
|
async init() {
|
|
43
43
|
return new Promise((resolve, reject) => {
|
|
44
44
|
this.database = new duckdb_1.Database(this.databasePath, duckdb_1.OPEN_READWRITE, // databasePath === ":memory:" ? OPEN_READWRITE : OPEN_READONLY,
|
|
45
|
-
|
|
45
|
+
// databasePath === ":memory:" ? OPEN_READWRITE : OPEN_READONLY,
|
|
46
|
+
err => {
|
|
46
47
|
if (err) {
|
|
47
48
|
reject(err);
|
|
48
49
|
}
|
|
@@ -62,7 +63,7 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
62
63
|
}
|
|
63
64
|
catch (error) {
|
|
64
65
|
// eslint-disable-next-line no-console
|
|
65
|
-
console.error(
|
|
66
|
+
console.error('Unable to load json extension', error);
|
|
66
67
|
}
|
|
67
68
|
try {
|
|
68
69
|
await this.runDuckDBQuery("INSTALL 'httpfs'");
|
|
@@ -70,7 +71,7 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
70
71
|
}
|
|
71
72
|
catch (error) {
|
|
72
73
|
// eslint-disable-next-line no-console
|
|
73
|
-
console.error(
|
|
74
|
+
console.error('Unable to load httpfs extension', error);
|
|
74
75
|
}
|
|
75
76
|
};
|
|
76
77
|
await this.connecting;
|
|
@@ -89,22 +90,22 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
89
90
|
else {
|
|
90
91
|
resolve({
|
|
91
92
|
rows,
|
|
92
|
-
|
|
93
|
+
totalRows: rows.length,
|
|
93
94
|
});
|
|
94
95
|
}
|
|
95
96
|
});
|
|
96
97
|
}
|
|
97
98
|
else {
|
|
98
|
-
reject(new Error(
|
|
99
|
+
reject(new Error('Connection not open'));
|
|
99
100
|
}
|
|
100
101
|
});
|
|
101
102
|
}
|
|
102
103
|
async *runSQLStream(sql, _options = {}) {
|
|
103
104
|
await this.setup();
|
|
104
105
|
if (!this.connection) {
|
|
105
|
-
throw new Error(
|
|
106
|
+
throw new Error('Connection not open');
|
|
106
107
|
}
|
|
107
|
-
const statements = sql.split(
|
|
108
|
+
const statements = sql.split('-- hack: split on this');
|
|
108
109
|
while (statements.length > 1) {
|
|
109
110
|
await this.runDuckDBQuery(statements[0]);
|
|
110
111
|
statements.shift();
|
|
@@ -114,7 +115,7 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
117
|
async createHash(sqlCommand) {
|
|
117
|
-
return crypto_1.default.createHash(
|
|
118
|
+
return crypto_1.default.createHash('md5').update(sqlCommand).digest('hex');
|
|
118
119
|
}
|
|
119
120
|
async close() {
|
|
120
121
|
if (this.connection) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as duckdb from
|
|
2
|
-
import { QueryDataRow, RunSQLOptions, StructDef } from
|
|
3
|
-
import { DuckDBCommon, QueryOptionsReader } from
|
|
1
|
+
import * as duckdb from '@duckdb/duckdb-wasm';
|
|
2
|
+
import { QueryDataRow, RunSQLOptions, StructDef } from '@malloydata/malloy';
|
|
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 {
|
|
6
6
|
readonly name: string;
|
|
@@ -73,10 +73,10 @@ const unwrapArrow = (value) => {
|
|
|
73
73
|
else if (value instanceof Date) {
|
|
74
74
|
return value;
|
|
75
75
|
}
|
|
76
|
-
else if (typeof value ===
|
|
76
|
+
else if (typeof value === 'bigint') {
|
|
77
77
|
return Number(value);
|
|
78
78
|
}
|
|
79
|
-
else if (typeof value ===
|
|
79
|
+
else if (typeof value === 'object') {
|
|
80
80
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
81
|
const obj = value;
|
|
82
82
|
// DecimalBigNums appear as Uint32Arrays, but can be identified
|
|
@@ -116,9 +116,9 @@ const unwrapRow = (row) => {
|
|
|
116
116
|
const unwrapTable = (table) => {
|
|
117
117
|
return table.toArray().map(unwrapRow);
|
|
118
118
|
};
|
|
119
|
-
const isNode = () => typeof navigator ===
|
|
119
|
+
const isNode = () => typeof navigator === 'undefined';
|
|
120
120
|
class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
|
|
121
|
-
constructor(name, databasePath = null, workingDirectory =
|
|
121
|
+
constructor(name, databasePath = null, workingDirectory = '/', queryOptions) {
|
|
122
122
|
super(queryOptions);
|
|
123
123
|
this.name = name;
|
|
124
124
|
this.databasePath = databasePath;
|
|
@@ -138,7 +138,7 @@ class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
138
138
|
const workerUrl = isNode()
|
|
139
139
|
? bundle.mainWorker
|
|
140
140
|
: URL.createObjectURL(new Blob([`importScripts("${bundle.mainWorker}");`], {
|
|
141
|
-
|
|
141
|
+
type: 'text/javascript',
|
|
142
142
|
}));
|
|
143
143
|
// Instantiate the asynchronous version of DuckDB-wasm
|
|
144
144
|
this.worker = new web_worker_1.default(workerUrl);
|
|
@@ -147,14 +147,14 @@ class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
147
147
|
await this._database.instantiate(bundle.mainModule, bundle.pthreadWorker);
|
|
148
148
|
if (this.databasePath) {
|
|
149
149
|
await this._database.open({
|
|
150
|
-
|
|
150
|
+
path: this.databasePath,
|
|
151
151
|
});
|
|
152
152
|
}
|
|
153
153
|
URL.revokeObjectURL(workerUrl);
|
|
154
154
|
this._connection = await this._database.connect();
|
|
155
155
|
}
|
|
156
156
|
else {
|
|
157
|
-
throw new Error(
|
|
157
|
+
throw new Error('Unable to instantiate duckdb-wasm');
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
get connection() {
|
|
@@ -169,25 +169,28 @@ class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
|
|
|
169
169
|
async runDuckDBQuery(sql) {
|
|
170
170
|
var _a;
|
|
171
171
|
const table = await ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.query(sql));
|
|
172
|
-
if (
|
|
172
|
+
if (table === undefined) {
|
|
173
|
+
throw new Error('Table is undefined.');
|
|
174
|
+
}
|
|
175
|
+
if ((table === null || table === void 0 ? void 0 : table.numRows) !== null) {
|
|
173
176
|
const rows = unwrapTable(table);
|
|
174
177
|
// console.log(rows);
|
|
175
178
|
return {
|
|
176
179
|
// Normalize the data from its default proxied form
|
|
177
180
|
rows,
|
|
178
|
-
|
|
181
|
+
totalRows: table.numRows,
|
|
179
182
|
};
|
|
180
183
|
}
|
|
181
184
|
else {
|
|
182
|
-
throw new Error(
|
|
185
|
+
throw new Error('Boom');
|
|
183
186
|
}
|
|
184
187
|
}
|
|
185
188
|
async *runSQLStream(sql, _options = {}) {
|
|
186
189
|
if (!this.connection) {
|
|
187
|
-
throw new Error(
|
|
190
|
+
throw new Error('duckdb-wasm not connected');
|
|
188
191
|
}
|
|
189
192
|
await this.setup();
|
|
190
|
-
const statements = sql.split(
|
|
193
|
+
const statements = sql.split('-- hack: split on this');
|
|
191
194
|
while (statements.length > 1) {
|
|
192
195
|
await this.runDuckDBQuery(statements[0]);
|
|
193
196
|
statements.shift();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as duckdb from
|
|
2
|
-
import { DuckDBWASMConnection as DuckDBWASMConnectionBase } from
|
|
1
|
+
import * as duckdb from '@duckdb/duckdb-wasm';
|
|
2
|
+
import { DuckDBWASMConnection as DuckDBWASMConnectionBase } from './duckdb_wasm_connection';
|
|
3
3
|
export declare class DuckDBWASMConnection extends DuckDBWASMConnectionBase {
|
|
4
4
|
getBundles(): duckdb.DuckDBBundles;
|
|
5
5
|
createHash(sqlCommand: string): Promise<string>;
|
|
@@ -54,11 +54,11 @@ class DuckDBWASMConnection extends duckdb_wasm_connection_1.DuckDBWASMConnection
|
|
|
54
54
|
}
|
|
55
55
|
async createHash(sqlCommand) {
|
|
56
56
|
const msgUint8 = new TextEncoder().encode(sqlCommand);
|
|
57
|
-
const hashBuffer = await crypto.subtle.digest(
|
|
57
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8);
|
|
58
58
|
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
59
59
|
const hashHex = hashArray
|
|
60
|
-
.map(
|
|
61
|
-
.join(
|
|
60
|
+
.map(b => b.toString(16).padStart(2, '0'))
|
|
61
|
+
.join('');
|
|
62
62
|
return hashHex;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DuckDBBundles } from
|
|
2
|
-
import { DuckDBWASMConnection as DuckDBWASMConnectionBase } from
|
|
1
|
+
import { DuckDBBundles } from '@duckdb/duckdb-wasm';
|
|
2
|
+
import { DuckDBWASMConnection as DuckDBWASMConnectionBase } from './duckdb_wasm_connection';
|
|
3
3
|
export declare class DuckDBWASMConnection extends DuckDBWASMConnectionBase {
|
|
4
4
|
getBundles(): DuckDBBundles;
|
|
5
5
|
createHash(sqlCommand: string): Promise<string>;
|
|
@@ -30,28 +30,28 @@ 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('@duckdb/duckdb-wasm');
|
|
34
34
|
if (!resolvePath) {
|
|
35
|
-
throw new Error(
|
|
35
|
+
throw new Error('Unable to resolve @duckdb/duckdb-wasm path');
|
|
36
36
|
}
|
|
37
37
|
const distMatch = resolvePath.match(/^.*\/dist\//);
|
|
38
38
|
if (!distMatch) {
|
|
39
|
-
throw new Error(
|
|
39
|
+
throw new Error('Unable to resolve @duckdb/duckdb-wasm dist path');
|
|
40
40
|
}
|
|
41
41
|
const dist = distMatch[0];
|
|
42
42
|
return {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
mvp: {
|
|
44
|
+
mainModule: `${dist}/duckdb-mvp.wasm`,
|
|
45
|
+
mainWorker: `${dist}/duckdb-node-mvp.worker.cjs`,
|
|
46
|
+
},
|
|
47
|
+
eh: {
|
|
48
|
+
mainModule: `${dist}/duckdb-eh.wasm`,
|
|
49
|
+
mainWorker: `${dist}/duckdb-node-eh.worker.cjs`,
|
|
46
50
|
},
|
|
47
|
-
"eh": {
|
|
48
|
-
"mainModule": `${dist}/duckdb-eh.wasm`,
|
|
49
|
-
"mainWorker": `${dist}/duckdb-node-eh.worker.cjs`
|
|
50
|
-
}
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
async createHash(sqlCommand) {
|
|
54
|
-
return crypto_1.default.createHash(
|
|
54
|
+
return crypto_1.default.createHash('md5').update(sqlCommand).digest('hex');
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
exports.DuckDBWASMConnection = DuckDBWASMConnection;
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { DuckDBConnection } from
|
|
1
|
+
export { DuckDBConnection } from './duckdb_connection';
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/db-duckdb",
|
|
3
|
-
"version": "0.0.24-
|
|
3
|
+
"version": "0.0.24-dev230228224434",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=11"
|
|
9
|
+
},
|
|
7
10
|
"exports": {
|
|
8
11
|
".": "./dist/index.js",
|
|
9
12
|
"./package.json": "./package.json",
|
|
@@ -38,7 +41,8 @@
|
|
|
38
41
|
},
|
|
39
42
|
"dependencies": {
|
|
40
43
|
"@duckdb/duckdb-wasm": "^1.20.0",
|
|
41
|
-
"@malloydata/malloy": "^0.0.24-
|
|
44
|
+
"@malloydata/malloy": "^0.0.24-dev230228224434",
|
|
45
|
+
"apache-arrow": "^9.0.0",
|
|
42
46
|
"duckdb": "0.6.1",
|
|
43
47
|
"web-worker": "^1.2.0"
|
|
44
48
|
}
|