Skip to content
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

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

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
12 changes: 4 additions & 8 deletions src/components/db-explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const VALID_EXTENSIONS = ["csv", "json"];

function DBExplorerInner(props: DBExplorerInnerProps) {
const { content, extension, filename, sha } = props;
const filenameWithoutExtension = filename.split(".").slice(0, -1).join(".");
const connectionRef = useRef<duckdb.AsyncDuckDBConnection | null>(null);
const [query, setQuery] = useState("");
const [debouncedQuery] = useDebounce(query, 500);
Expand Down Expand Up @@ -84,15 +85,10 @@ function DBExplorerInner(props: DBExplorerInnerProps) {
connectionRef.current = c;

try {
if (extension === "csv") {
await db.registerFileText(`data.csv`, content);
await c.insertCSVFromPath(`data.csv`, { name: "data" });
} else if (extension === "json") {
await db.registerFileText(`data.json`, content);
await c.insertJSONFromPath("data.json", { name: "data" });
}
await db.registerFileText(filename, content);
await c.insertCSVFromPath(filename, { name: filenameWithoutExtension });
setDbStatus("success");
setQuery("select * from data");
setQuery(`select * from '${filenameWithoutExtension}'`);
mattrothenberg marked this conversation as resolved.
Show resolved Hide resolved
} catch {
setDbStatus("error");
}
Expand Down