Skip to content

Commit c0d769a

Browse files
authored
fix: playground csv loading (#3076)
1 parent 88064da commit c0d769a

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

web/playground/src/workbench/Workbench.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ class Workbench extends React.Component {
4040
componentDidMount() {
4141
this.props.setCallables({ loadFile: (f, c) => this.loadFile(f, c) });
4242

43-
this.duckdb = duckdb.init();
43+
if (!this.duckdb) {
44+
this.duckdb = duckdb.init();
45+
}
4446
}
4547

4648
beforeEditorMount(monaco) {

web/playground/src/workbench/duckdb.js

+6-12
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,18 @@ export const CHINOOK_TABLES = [
4040

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

4544
await Promise.all(
46-
CHINOOK_TABLES.map((table) =>
47-
db.registerFileURL(
48-
`${table}.csv`,
49-
`${baseUrl}/${table}.csv`,
50-
http,
51-
false,
52-
),
53-
),
45+
CHINOOK_TABLES.map(async (table) => {
46+
const res = await fetch(`${baseUrl}/${table}.csv`);
47+
48+
db.registerFileText(`${table}.csv`, res);
49+
}),
5450
);
5551

5652
const c = await db.connect();
5753
for (const table of CHINOOK_TABLES) {
58-
await c.query(`
59-
CREATE TABLE ${table} AS SELECT * FROM read_csv_auto('${table}.csv');
60-
`);
54+
await c.insertCSVFromPath(`${table}.csv`, { name: table, detect: true });
6155
}
6256
c.close();
6357
}

0 commit comments

Comments
 (0)