8000 feat: duckdb-wasm query UI [DRAFT] by mattrothenberg · Pull Request #39 · githubocto/flat-viewer · GitHub
[go: up one dir, main page]

Skip to content

feat: duckdb-wasm query UI [DRAFT] #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
fix: conditionally insert CSV or JSON
  • Loading branch information
Matt Rothenberg committed May 16, 2022
commit 93c654f29334fbddf70c6b2dad0a46b23eed88bd
18 changes: 11 additions & 7 deletions src/components/db-explorer.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { sql } from "@codemirror/lang-sql";
import {
ErrorBoundary,
ErrorBoundaryProps,
FallbackProps,
} from "react-error-boundary";
import { ErrorBoundary, FallbackProps } from "react-error-boundary";

import { Grid } from "@githubocto/flat-ui";
import CodeMirror from "@uiw/react-codemirror";
Expand Down Expand Up @@ -68,6 +64,7 @@ function DBExplorerInner(props: DBExplorerInnerProps) {
if (!connectionRef.current) return;
const queryRes = await connectionRef.current.query(query);
const asArray = queryRes.toArray();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to convert the result to an array. Arrow tables already behave like arrays of objects if you iterate over them for for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@domoritz Fantastic! This felt kludgy and I suspected there was a better way.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map and forEach won't work so you may have to refactor your code a bit but it would be worth it since you avoid a lot of upfront conversion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@domoritz Good call. We're ultimately passing this data down to our flat-ui component , so it needs to be in a shape that this component understands (or we need to refactor the component)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may need to refactor the component. Shouldn't be a big deal, though, and would be great for interoperability anyway.


return {
numRows: queryRes.numRows,
numCols: queryRes.numCols,
Expand Down Expand Up @@ -109,10 +106,17 @@ function DBExplorerInner(props: DBExplorerInnerProps) {

try {
await db.registerFileText(filename, content);
await c.insertCSVFromPath(filename, { name: filenameWithoutExtension });
extension === "csv"
? await c.insertCSVFromPath(filename, {
name: filenameWithoutExtension,
})
: await c.insertJSONFromPath(filename, {
name: filenameWithoutExtension,
});
setDbStatus("success");
setQuery(`select * from '${filenameWithoutExtension}'`);
} catch {
} catch (e) {
console.error(e);
setDbStatus("error");
}
};
Expand Down
0