From 17e51e51882941a9b5786e48e54aebce19c5168e Mon Sep 17 00:00:00 2001 From: Kinfe123 Date: Mon, 17 Jun 2024 17:56:17 +0300 Subject: [PATCH 1/2] feat: automatic browser open & failed fallback for queries --- Cargo.lock | 74 ++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 4 +- ui/src/routeTree.gen.ts | 68 ++++++++++++++++----------------- ui/src/routes/query.lazy.tsx | 16 ++++++-- 5 files changed, 123 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3abab0..637c9ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -822,6 +822,16 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "open" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2078c0039e6a54a0c42c28faa984e115fb4c2d5bf2208f77d1961002df8576f8" +dependencies = [ + "pathdiff", + "windows-sys 0.42.0", +] + [[package]] name = "overload" version = "0.1.1" @@ -857,6 +867,12 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "pathdiff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" + [[package]] name = "percent-encoding" version = "2.3.1" @@ -1157,6 +1173,7 @@ dependencies = [ "clap", "color-eyre", "include_dir", + "open", "rusqlite", "serde", "serde_json", @@ -1604,6 +1621,21 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -1653,6 +1685,12 @@ dependencies = [ "windows_x86_64_msvc 0.52.5", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" @@ -1665,6 +1703,12 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" @@ -1677,6 +1721,12 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + [[package]] name = "windows_i686_gnu" version = "0.48.5" @@ -1695,6 +1745,12 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + [[package]] name = "windows_i686_msvc" version = "0.48.5" @@ -1707,6 +1763,12 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" @@ -1719,6 +1781,12 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" @@ -1731,6 +1799,12 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" diff --git a/Cargo.toml b/Cargo.toml index e8e27b7..f0e6480 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/src/main.rs b/src/main.rs index 4854aab..f20ef21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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"); @@ -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), diff --git a/ui/src/routeTree.gen.ts b/ui/src/routeTree.gen.ts index 16ec80c..4be1bc8 100644 --- a/ui/src/routeTree.gen.ts +++ b/ui/src/routeTree.gen.ts @@ -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 + } } } @@ -71,7 +71,7 @@ export const routeTree = rootRoute.addChildren({ IndexLazyRoute, QueryLazyRoute, TablesLazyRoute, -}); +}) /* prettier-ignore-end */ diff --git a/ui/src/routes/query.lazy.tsx b/ui/src/routes/query.lazy.tsx index 84542c7..a4f7bd1 100644 --- a/ui/src/routes/query.lazy.tsx +++ b/ui/src/routes/query.lazy.tsx @@ -16,13 +16,21 @@ 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 ? ( - + error ? ( +
+ {/* We can have stacktrace displayed here based on the response from backend */} +

+ No such resource returned from this query :({" "} +

+
+ ) : ( + + ) ) : ( ({ key: col, name: col }))} @@ -30,7 +38,7 @@ function Query() { row.reduce((acc, curr, i) => { acc[data.columns[i]] = curr; return acc; - }, {}), + }, {}) )} className="rdg-light" /> From e97817dee0eadf7dcb147865fe648c361f55b85d Mon Sep 17 00:00:00 2001 From: Kinfe123 Date: Mon, 17 Jun 2024 20:29:52 +0300 Subject: [PATCH 2/2] fix: returns nothing for query fails --- ui/src/routes/query.lazy.tsx | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/ui/src/routes/query.lazy.tsx b/ui/src/routes/query.lazy.tsx index a4f7bd1..278b2b6 100644 --- a/ui/src/routes/query.lazy.tsx +++ b/ui/src/routes/query.lazy.tsx @@ -21,16 +21,7 @@ function Query() { queryFn: () => fetchQuery(code), }); const grid = !data ? ( - error ? ( -
- {/* We can have stacktrace displayed here based on the response from backend */} -

- No such resource returned from this query :({" "} -

-
- ) : ( - - ) + !error && ) : ( ({ key: col, name: col }))}