@uwdata/mosaic-duckdb 0.10.0 → 0.12.0
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/package.json +6 -5
- package/src/DuckDB.js +1 -1
- package/src/data-server.js +3 -2
- package/src/load/bundle.js +2 -2
- package/src/load/csv.js +2 -6
- package/src/load/json.js +2 -6
- package/src/load/parquet.js +2 -4
- package/src/load/create-table.js +0 -6
- package/src/load/parameters.js +0 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uwdata/mosaic-duckdb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "A Promise-based DuckDB API and Node.js data server.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"duckdb",
|
|
@@ -26,12 +26,13 @@
|
|
|
26
26
|
"scripts": {
|
|
27
27
|
"lint": "eslint src test",
|
|
28
28
|
"server": "node bin/run-server.js",
|
|
29
|
-
"test": "
|
|
29
|
+
"test": "vitest run",
|
|
30
30
|
"prepublishOnly": "npm run test && npm run lint"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"
|
|
34
|
-
"
|
|
33
|
+
"@uwdata/mosaic-sql": "^0.12.0",
|
|
34
|
+
"duckdb": "^1.1.3",
|
|
35
|
+
"ws": "^8.18.0"
|
|
35
36
|
},
|
|
36
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "523b1afe2a0880291c92f81e4a7b91829362d285"
|
|
37
38
|
}
|
package/src/DuckDB.js
CHANGED
|
@@ -114,7 +114,7 @@ export class DuckDBStatement {
|
|
|
114
114
|
|
|
115
115
|
arrowBuffer(params) {
|
|
116
116
|
return new Promise((resolve, reject) => {
|
|
117
|
-
this.
|
|
117
|
+
this.statement.arrowIPCAll(...params, (err, result) => {
|
|
118
118
|
if (err) {
|
|
119
119
|
reject(err);
|
|
120
120
|
} else {
|
package/src/data-server.js
CHANGED
|
@@ -19,10 +19,11 @@ export function dataServer(db, {
|
|
|
19
19
|
const app = createHTTPServer(handleQuery, rest);
|
|
20
20
|
if (socket) createSocketServer(app, handleQuery);
|
|
21
21
|
|
|
22
|
-
app.listen(port);
|
|
22
|
+
const server = app.listen(port);
|
|
23
23
|
console.log(`Data server running on port ${port}`);
|
|
24
24
|
if (rest) console.log(` http://localhost:${port}/`);
|
|
25
25
|
if (socket) console.log(` ws://localhost:${port}/`);
|
|
26
|
+
return server;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
function createHTTPServer(handleQuery, rest) {
|
|
@@ -103,7 +104,7 @@ export function queryHandler(db, queryCache) {
|
|
|
103
104
|
|
|
104
105
|
try {
|
|
105
106
|
const { sql, type = 'json' } = query;
|
|
106
|
-
console.log(`> ${type.toUpperCase()}${sql ?
|
|
107
|
+
console.log(`> ${type.toUpperCase()}${sql ? ` ${sql}` : ''}`);
|
|
107
108
|
|
|
108
109
|
// process query and return result
|
|
109
110
|
switch (type) {
|
package/src/load/bundle.js
CHANGED
|
@@ -67,9 +67,9 @@ export async function loadBundle(db, cache, dir) {
|
|
|
67
67
|
cache.set(key, json ? JSON.parse(data) : data);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
// load precomputed
|
|
70
|
+
// load precomputed tables into the database
|
|
71
71
|
for (const table of manifest.tables) {
|
|
72
72
|
const file = path.resolve(dir, `${table}.parquet`);
|
|
73
|
-
await db.exec(`CREATE
|
|
73
|
+
await db.exec(`CREATE TABLE IF NOT EXISTS ${table} AS SELECT * FROM '${file}'`);
|
|
74
74
|
}
|
|
75
75
|
}
|
package/src/load/csv.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { parameters } from './parameters.js';
|
|
1
|
+
import { loadCSV as loadCSVSQL } from '@uwdata/mosaic-sql';
|
|
3
2
|
|
|
4
3
|
export function loadCSV(db, tableName, fileName, options = {}) {
|
|
5
|
-
|
|
6
|
-
const params = parameters({ auto_detect: true, sample_size: -1, ...csvOptions });
|
|
7
|
-
const query = `SELECT ${select.join(', ')} FROM read_csv('${fileName}', ${params})`;
|
|
8
|
-
return createTable(db, tableName, query, { temp, replace });
|
|
4
|
+
return db.exec(loadCSVSQL(tableName, fileName, options));
|
|
9
5
|
}
|
package/src/load/json.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { parameters } from './parameters.js';
|
|
1
|
+
import { loadJSON as loadJSONSQL } from '@uwdata/mosaic-sql';
|
|
3
2
|
|
|
4
3
|
export function loadJSON(db, tableName, fileName, options = {}) {
|
|
5
|
-
|
|
6
|
-
const params = parameters({ auto_detect: true, json_format: 'auto', ...jsonOptions });
|
|
7
|
-
const query = `SELECT ${select.join(', ')} FROM read_json('${fileName}', ${params})`;
|
|
8
|
-
return createTable(db, tableName, query, { temp, replace });
|
|
4
|
+
return db.exec(loadJSONSQL(tableName, fileName, options));
|
|
9
5
|
}
|
package/src/load/parquet.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { loadParquet as loadParquetSQL } from '@uwdata/mosaic-sql';
|
|
2
2
|
|
|
3
3
|
export function loadParquet(db, tableName, fileName, options = {}) {
|
|
4
|
-
|
|
5
|
-
const query = `SELECT ${select.join(', ')} FROM read_parquet('${fileName}')`;
|
|
6
|
-
return createTable(db, tableName, query, tableOptions);
|
|
4
|
+
return db.exec(loadParquetSQL(tableName, fileName, options));
|
|
7
5
|
}
|
package/src/load/create-table.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export function createTable(db, name, as, options = {}) {
|
|
2
|
-
const { temp, replace } = options;
|
|
3
|
-
const create = `CREATE${replace ? ' OR REPLACE' : ''}`;
|
|
4
|
-
const type = `${temp ? 'TEMP ' : ''}TABLE${replace ? '' : ' IF NOT EXISTS'}`;
|
|
5
|
-
return db.exec(`${create} ${type} ${name} AS ${as}`);
|
|
6
|
-
}
|
package/src/load/parameters.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export function parameters(options) {
|
|
2
|
-
return Object.entries(options)
|
|
3
|
-
.map(([key, value]) => {
|
|
4
|
-
const t = typeof value;
|
|
5
|
-
const v = t === 'boolean' ? String(value)
|
|
6
|
-
: t === 'string' ? `'${value}'`
|
|
7
|
-
: value;
|
|
8
|
-
return `${key}=${v}`;
|
|
9
|
-
})
|
|
10
|
-
.join(', ');
|
|
11
|
-
}
|