query riferimenti, in progress
This commit is contained in:
parent
a68d31bea9
commit
93f8b57af0
|
@ -0,0 +1,68 @@
|
|||
import * as duckdb from 'https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/+esm';
|
||||
//import * as arrow from 'https://cdn.skypack.dev/apache-arrow@9'
|
||||
|
||||
|
||||
var rif_commentatori=[];
|
||||
var rif_autori=[];
|
||||
var rif_areetematiche=[];
|
||||
|
||||
const JSDELIVR_BUNDLES = duckdb.getJsDelivrBundles();
|
||||
|
||||
// Select a bundle based on browser checks
|
||||
const bundle = await duckdb.selectBundle(JSDELIVR_BUNDLES);
|
||||
|
||||
const worker_url = URL.createObjectURL(
|
||||
new Blob([`importScripts("${bundle.mainWorker}");`], {type: 'text/javascript'})
|
||||
);
|
||||
|
||||
// Instantiate the asynchronus version of DuckDB-wasm
|
||||
const worker = new Worker(worker_url);
|
||||
const logger = new duckdb.ConsoleLogger();
|
||||
const db = new duckdb.AsyncDuckDB(logger, worker);
|
||||
await db.instantiate(bundle.mainModule, bundle.pthreadWorker);
|
||||
URL.revokeObjectURL(worker_url);
|
||||
|
||||
console.log ('datamgr init done')
|
||||
|
||||
|
||||
//await db.registerFileURL('remote.parquet', 'http://localhost:8000/js/data/riferimenti_3.parquet', DuckDBDataProtocol.HTTP, false);
|
||||
|
||||
/*const res = await fetch('http://localhost:8000/js/data/riferimenti_3.parquet');
|
||||
|
||||
await db.registerFileBuffer('buffer.parquet', new Uint8Array(await res.arrayBuffer()));*/
|
||||
|
||||
const conn = await db.connect();
|
||||
|
||||
await conn.query(`
|
||||
CREATE TABLE riferimenti AS
|
||||
SELECT * FROM "https://lida.dantenetwork.it/js/data/riferimenti_3.parquet";
|
||||
CREATE table commentatori as select distinct Com from riferimenti;
|
||||
CREATE table autori as select distinct Aut from riferimenti order by Aut;
|
||||
Create table areatematica as select distinct CA from riferimenti order by CA;
|
||||
`);
|
||||
|
||||
var table=await conn.query(`
|
||||
SELECT * FROM autori
|
||||
`);
|
||||
const result = table.toArray().map((row) => row.toJSON());
|
||||
rif_autori=result.map((x) => x['Aut']);
|
||||
console.log(rif_autori)
|
||||
await conn.close();
|
||||
const conn2 = await db.connect();
|
||||
var table=await conn2.query(`
|
||||
SELECT * FROM commentatori
|
||||
`);
|
||||
const result2 = table.toArray().map((row) => row.toJSON());
|
||||
rif_commentatori=result2.map((x) => x['Com']);;
|
||||
console.log(rif_commentatori)
|
||||
|
||||
var table=await conn2.query(`
|
||||
SELECT * FROM areatematica
|
||||
`);
|
||||
const result3 = table.toArray().map((row) => row.toJSON());
|
||||
|
||||
rif_areetematiche= result3.map((x) => x['CA']);
|
||||
console.log(rif_areetematiche)
|
||||
await conn2.close();
|
||||
|
||||
console.log('done')
|
Loading…
Reference in New Issue