@uwdata/mosaic-duckdb 0.11.0 → 0.12.1
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/README.md +2 -0
- package/package.json +4 -3
- package/src/data-server.js +2 -1
- 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/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# mosaic-duckdb
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@uwdata/mosaic-duckdb)
|
|
4
|
+
|
|
3
5
|
A Promise-based Node.js API to DuckDB, along with a data server that supports transfer of [Apache Arrow](https://arrow.apache.org/) and JSON data over either Web Sockets or HTTP.
|
|
4
6
|
|
|
5
7
|
_Warning_: Due to persistent quality issues involving the Node.js DuckDB client and Arrow extension, we recommend using the Python-based [`duckdb-server`](https://github.com/uwdata/mosaic/tree/main/packages/duckdb-server) package instead. However, we retain this package for both backwards compatibility and potential future use as quality issues improve.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uwdata/mosaic-duckdb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "A Promise-based DuckDB API and Node.js data server.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"duckdb",
|
|
@@ -30,8 +30,9 @@
|
|
|
30
30
|
"prepublishOnly": "npm run test && npm run lint"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"
|
|
33
|
+
"@uwdata/mosaic-sql": "^0.12.1",
|
|
34
|
+
"duckdb": "^1.1.3",
|
|
34
35
|
"ws": "^8.18.0"
|
|
35
36
|
},
|
|
36
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "fe3a7c34352da54ec36a1ebf557846f46a649782"
|
|
37
38
|
}
|
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) {
|
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, ...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
|
-
}
|