@uwdata/mosaic-duckdb 0.11.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uwdata/mosaic-duckdb",
3
- "version": "0.11.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",
@@ -30,8 +30,9 @@
30
30
  "prepublishOnly": "npm run test && npm run lint"
31
31
  },
32
32
  "dependencies": {
33
- "duckdb": "^1.0.0",
33
+ "@uwdata/mosaic-sql": "^0.12.0",
34
+ "duckdb": "^1.1.3",
34
35
  "ws": "^8.18.0"
35
36
  },
36
- "gitHead": "861d616f39926a1d2aee83b59dbdd70b0b3caf12"
37
+ "gitHead": "523b1afe2a0880291c92f81e4a7b91829362d285"
37
38
  }
@@ -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) {
@@ -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 temp tables into the database
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 TEMP TABLE IF NOT EXISTS ${table} AS SELECT * FROM '${file}'`);
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 { createTable } from './create-table.js';
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
- const { select = ['*'], temp, replace, ...csvOptions } = options;
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 { createTable } from './create-table.js';
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
- const { select = ['*'], temp, replace, ...jsonOptions } = options;
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
  }
@@ -1,7 +1,5 @@
1
- import { createTable } from './create-table.js';
1
+ import { loadParquet as loadParquetSQL } from '@uwdata/mosaic-sql';
2
2
 
3
3
  export function loadParquet(db, tableName, fileName, options = {}) {
4
- const { select = ['*'], ...tableOptions } = options;
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
  }
@@ -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
- }
@@ -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
- }