1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { fetch } from "https://esm.town/v/std/fetch";
import { getDuckDB } from "https://esm.town/v/tmcw/getDuckDB";
export const duckDbCsv = (async () => {
const db = await getDuckDB();
const r = await fetch(
"https://raw.githubusercontent.com/fivethirtyeight/data/master/san-andreas/earthquake_data.csv",
);
await db.registerFileBuffer(
"file.csv",
new Uint8Array(await r.arrayBuffer()),
);
const c = await db.connect();
const res = await c.query(`select * from "file.csv" LIMIT 5`);
c.close();
db.terminate();
return res.toArray().map((r) => r.toJSON());
})();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { fetch } from "https://esm.town/v/std/fetch";
import { insertDataIntoDuckDb } from "https://esm.town/v/neverstew/insertDataIntoDuckDb";
import { getDuckDB } from "https://esm.town/v/tmcw/getDuckDB?v=1";
export const duckDbJson = (async () => {
const db = await getDuckDB();
const r = await fetch("https://jsonplaceholder.typicode.com/todos");
await insertDataIntoDuckDb(db, await r.json());
const c = await db.connect();
const res = await c.query(`select * from data where completed`);
c.close();
db.terminate();
return res.toArray().map((r) => r.toJSON());
})();
// Forked from @tmcw.duckDbCsv

Query

Query anything with SQL! Your data is stored in the data table.

See the DuckDB documentation for possible functions etc.

1
2
3
4
5
6
7
8
9
10
11
12
import { insertDataIntoDuckDb } from "https://esm.town/v/neverstew/insertDataIntoDuckDb";
import { getDuckDB } from "https://esm.town/v/tmcw/getDuckDB?v=1";
export const query = async (data: object, query: string) => {
const db = await getDuckDB();
await insertDataIntoDuckDb(db, data);
const c = await db.connect();
const res = await c.query(query);
c.close();
db.terminate();
return res.toArray().map((r) => r.toJSON());
};
1
Next