Skip to content

Commit

Permalink
fix: playground csv loading (#3076)
Browse files Browse the repository at this point in the history
  • Loading branch information
aljazerzen authored Jul 25, 2023
1 parent 88064da commit c0d769a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
4 changes: 3 additions & 1 deletion web/playground/src/workbench/Workbench.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class Workbench extends React.Component {
componentDidMount() {
this.props.setCallables({ loadFile: (f, c) => this.loadFile(f, c) });

this.duckdb = duckdb.init();
if (!this.duckdb) {
this.duckdb = duckdb.init();
}
}

beforeEditorMount(monaco) {
Expand Down
18 changes: 6 additions & 12 deletions web/playground/src/workbench/duckdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,18 @@ export const CHINOOK_TABLES = [

async function registerChinook(db) {
const baseUrl = `${window.location.href}data/chinook`;
const http = duckdb.DuckDBDataProtocol.HTTP;

await Promise.all(
CHINOOK_TABLES.map((table) =>
db.registerFileURL(
`${table}.csv`,
`${baseUrl}/${table}.csv`,
http,
false,
),
),
CHINOOK_TABLES.map(async (table) => {
const res = await fetch(`${baseUrl}/${table}.csv`);

db.registerFileText(`${table}.csv`, res);
}),
);

const c = await db.connect();
for (const table of CHINOOK_TABLES) {
await c.query(`
CREATE TABLE ${table} AS SELECT * FROM read_csv_auto('${table}.csv');
`);
await c.insertCSVFromPath(`${table}.csv`, { name: table, detect: true });
}
c.close();
}

0 comments on commit c0d769a

Please sign in to comment.