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/auto browser and bad query fallback #9

Merged
merged 4 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ tokio-rusqlite = "0.5.1"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
warp = "0.3.7"
open = "3.2.0"

[profile.release]
strip = true
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::{collections::HashMap, path::Path, sync::Arc};

use clap::Parser;
use color_eyre::eyre::OptionExt;
use open::that;
use tokio_rusqlite::{Connection, OpenFlags};
use warp::Filter;

const ROWS_PER_PAGE: i32 = 50;
const SAMPLE_DB: &[u8] = include_bytes!("../sample.sqlite3");

Expand Down Expand Up @@ -144,7 +144,7 @@ impl TheDB {
.await?;

tracing::info!("found {tables} tables in {path}");

that("http://127.0.0.1:3030").expect("Failed to open browser");
Ok(Self {
path,
conn: Arc::new(conn),
Expand Down
68 changes: 34 additions & 34 deletions ui/src/routeTree.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,60 @@

// This file is auto-generated by TanStack Router

import { createFileRoute } from "@tanstack/react-router";
import { createFileRoute } from '@tanstack/react-router'

// Import Routes

import { Route as rootRoute } from "./routes/__root";
import { Route as rootRoute } from './routes/__root'

// Create Virtual Routes

const TablesLazyImport = createFileRoute("/tables")();
const QueryLazyImport = createFileRoute("/query")();
const IndexLazyImport = createFileRoute("/")();
const TablesLazyImport = createFileRoute('/tables')()
const QueryLazyImport = createFileRoute('/query')()
const IndexLazyImport = createFileRoute('/')()

// Create/Update Routes

const TablesLazyRoute = TablesLazyImport.update({
path: "/tables",
path: '/tables',
getParentRoute: () => rootRoute,
} as any).lazy(() => import("./routes/tables.lazy").then((d) => d.Route));
} as any).lazy(() => import('./routes/tables.lazy').then((d) => d.Route))

const QueryLazyRoute = QueryLazyImport.update({
path: "/query",
path: '/query',
getParentRoute: () => rootRoute,
} as any).lazy(() => import("./routes/query.lazy").then((d) => d.Route));
} as any).lazy(() => import('./routes/query.lazy').then((d) => d.Route))

const IndexLazyRoute = IndexLazyImport.update({
path: "/",
path: '/',
getParentRoute: () => rootRoute,
} as any).lazy(() => import("./routes/index.lazy").then((d) => d.Route));
} as any).lazy(() => import('./routes/index.lazy').then((d) => d.Route))

// Populate the FileRoutesByPath interface

declare module "@tanstack/react-router" {
declare module '@tanstack/react-router' {
interface FileRoutesByPath {
"/": {
id: "/";
path: "/";
fullPath: "/";
preLoaderRoute: typeof IndexLazyImport;
parentRoute: typeof rootRoute;
};
"/query": {
id: "/query";
path: "/query";
fullPath: "/query";
preLoaderRoute: typeof QueryLazyImport;
parentRoute: typeof rootRoute;
};
"/tables": {
id: "/tables";
path: "/tables";
fullPath: "/tables";
preLoaderRoute: typeof TablesLazyImport;
parentRoute: typeof rootRoute;
};
'/': {
id: '/'
path: '/'
fullPath: '/'
preLoaderRoute: typeof IndexLazyImport
parentRoute: typeof rootRoute
}
'/query': {
id: '/query'
path: '/query'
fullPath: '/query'
preLoaderRoute: typeof QueryLazyImport
parentRoute: typeof rootRoute
}
'/tables': {
id: '/tables'
path: '/tables'
fullPath: '/tables'
preLoaderRoute: typeof TablesLazyImport
parentRoute: typeof rootRoute
}
}
}

Expand All @@ -71,7 +71,7 @@ export const routeTree = rootRoute.addChildren({
IndexLazyRoute,
QueryLazyRoute,
TablesLazyRoute,
});
})

/* prettier-ignore-end */

Expand Down
7 changes: 3 additions & 4 deletions ui/src/routes/query.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ export const Route = createLazyRoute("/query")({
function Query() {
const [code, setCode] = useState("select 1 + 1");

const { data } = useQuery({
const { data, error } = useQuery({
queryKey: ["query", code],
queryFn: () => fetchQuery(code),
});

const grid = !data ? (
<Skeleton className="w-full h-[300px]" />
!error && <Skeleton className="w-full h-[300px]" />
) : (
<DataGrid
columns={data.columns.map((col) => ({ key: col, name: col }))}
rows={data.rows.map((row) =>
row.reduce((acc, curr, i) => {
acc[data.columns[i]] = curr;
return acc;
}, {}),
}, {})
)}
className="rdg-light"
/>
Expand Down