Skip to content

Commit a55b8ac

Browse files
Merge pull request #1927 from QueryaHub/issue/1870-sqlite-commands
feat(tauri): commands db_connect_sqlite / db_disconnect
2 parents 5a58f01 + 510646d commit a55b8ac

12 files changed

Lines changed: 377 additions & 17 deletions

File tree

‎apps/tauri/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pnpm install
5454
pnpm tauri dev
5555
```
5656

57-
You should get an empty Querya splash window and an `app_info` IPC line in the UI.
57+
You should get the shell chrome and an `app_info` status line. **Open SQLite…** uses the native file dialog and `db_connect_sqlite` IPC (live connection list in the sidebar).
5858

5959
### Scripts
6060

‎apps/tauri/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"dependencies": {
1414
"@tauri-apps/api": "^2",
15+
"@tauri-apps/plugin-dialog": "^2.8.4",
1516
"@tauri-apps/plugin-opener": "^2",
1617
"pinia": "^3.0.3",
1718
"vue": "^3.5.13"

‎apps/tauri/pnpm-lock.yaml‎

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎apps/tauri/src-tauri/Cargo.lock‎

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎apps/tauri/src-tauri/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ tauri-build = { version = "2", features = [] }
1515
[dependencies]
1616
tauri = { version = "2", features = [] }
1717
tauri-plugin-opener = "2"
18+
tauri-plugin-dialog = "2"
1819
serde = { version = "1", features = ["derive"] }
1920
serde_json = "1"
2021
uuid = { version = "1", features = ["v4", "serde"] }

‎apps/tauri/src-tauri/capabilities/default.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"permissions": [
77
"core:default",
88
"opener:default",
9+
"dialog:default",
10+
"dialog:allow-open",
911
"core:window:allow-close",
1012
"core:window:allow-minimize",
1113
"core:window:allow-maximize",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use crate::connection::{
2+
ConnectionConfig, ConnectionError, ConnectionId, ConnectionManager, ConnectionRegistry,
3+
};
4+
use tauri::State;
5+
6+
#[tauri::command]
7+
pub fn db_connect_sqlite(
8+
path: String,
9+
registry: State<'_, ConnectionRegistry>,
10+
) -> Result<ConnectionId, ConnectionError> {
11+
registry.connect(ConnectionConfig::Sqlite { path })
12+
}
13+
14+
#[tauri::command]
15+
pub fn db_disconnect(
16+
id: ConnectionId,
17+
registry: State<'_, ConnectionRegistry>,
18+
) -> Result<(), ConnectionError> {
19+
registry.disconnect(&id)
20+
}
21+
22+
#[tauri::command]
23+
pub fn db_is_connected(
24+
id: ConnectionId,
25+
registry: State<'_, ConnectionRegistry>,
26+
) -> bool {
27+
registry.is_connected(&id)
28+
}

‎apps/tauri/src-tauri/src/lib.rs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
mod commands;
12
mod connection;
23

34
pub use connection::{
45
ConnectionConfig, ConnectionError, ConnectionId, ConnectionManager, ConnectionRegistry,
56
DriverKind,
67
};
78

9+
use commands::{db_connect_sqlite, db_disconnect, db_is_connected};
10+
811
#[tauri::command]
912
fn app_info() -> serde_json::Value {
1013
serde_json::json!({
@@ -30,8 +33,15 @@ fn host_platform() -> String {
3033
pub fn run() {
3134
tauri::Builder::default()
3235
.plugin(tauri_plugin_opener::init())
36+
.plugin(tauri_plugin_dialog::init())
3337
.manage(ConnectionRegistry::new())
34-
.invoke_handler(tauri::generate_handler![app_info, host_platform])
38+
.invoke_handler(tauri::generate_handler![
39+
app_info,
40+
host_platform,
41+
db_connect_sqlite,
42+
db_disconnect,
43+
db_is_connected,
44+
])
3545
.run(tauri::generate_context!())
3646
.expect("error while running tauri application");
3747
}

‎apps/tauri/src/App.vue‎

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<script setup lang="ts">
22
import { computed, onMounted, onUnmounted } from "vue";
33
import { invoke } from "@tauri-apps/api/core";
4+
import { open } from "@tauri-apps/plugin-dialog";
45
import { storeToRefs } from "pinia";
56
import { useShellStore } from "./stores/shell";
67
import { useShellStatusStore } from "./stores/shellStatus";
78
import { useWorkspaceStore } from "./stores/workspace";
9+
import { useConnectionsStore } from "./stores/connections";
810
import { initTheme } from "./theme/queryaTheme";
911
import { provideQueryaMotion } from "./motion";
1012
import TitleBar from "./ui/TitleBar.vue";
@@ -17,19 +19,32 @@ import QueryaDivider from "./ui/QueryaDivider.vue";
1719
const shell = useShellStore();
1820
const status = useShellStatusStore();
1921
const workspace = useWorkspaceStore();
22+
const connections = useConnectionsStore();
2023
const { activeTab } = storeToRefs(workspace);
2124
provideQueryaMotion();
2225
2326
const showEmpty = computed(
24-
() => !status.connectionName && activeTab.value?.kind === "welcome",
27+
() => !connections.active && activeTab.value?.kind === "welcome",
2528
);
2629
27-
function onOpenSqlite() {
28-
status.setQueryMetrics({
29-
message: "SQLite open will land with #1873",
30-
busy: false,
31-
});
32-
workspace.addTab({ title: "SQLite", kind: "sql" });
30+
async function onOpenSqlite() {
31+
try {
32+
const selected = await open({
33+
multiple: false,
34+
directory: false,
35+
title: "Open SQLite database",
36+
filters: [
37+
{ name: "SQLite", extensions: ["db", "sqlite", "sqlite3"] },
38+
{ name: "All files", extensions: ["*"] },
39+
],
40+
});
41+
if (!selected || Array.isArray(selected)) return;
42+
const conn = await connections.connectSqlite(selected);
43+
workspace.addTab({ title: conn.name, kind: "sql" });
44+
} catch (err) {
45+
// Status already set by connections store on connect failure.
46+
if (String(err).includes("cancel")) return;
47+
}
3348
}
3449
3550
function onNewConnection() {
@@ -46,7 +61,6 @@ function onOpenTour() {
4661
function onKeydown(e: KeyboardEvent) {
4762
const mod = e.metaKey || e.ctrlKey;
4863
if (!mod) return;
49-
// Ctrl/Cmd+B — Flutter main_screen_shortcuts sidebar toggle
5064
if (e.key.toLowerCase() === "b") {
5165
e.preventDefault();
5266
shell.toggleSidebar();
@@ -98,7 +112,10 @@ onUnmounted(() => {
98112
/>
99113
<div v-else class="tab-placeholder" data-testid="tab-placeholder">
100114
<h2>{{ activeTab?.title }}</h2>
101-
<p>Kind: {{ activeTab?.kind }} — editor/grid land in the SQLite slice.</p>
115+
<p v-if="connections.active">
116+
Connected: {{ connections.active.path }}
117+
</p>
118+
<p>Kind: {{ activeTab?.kind }} — editor/grid land next in the slice.</p>
102119
</div>
103120
</div>
104121
</main>

‎apps/tauri/src/api/connection.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { invoke } from "@tauri-apps/api/core";
2+
3+
export async function dbConnectSqlite(path: string): Promise<string> {
4+
return invoke<string>("db_connect_sqlite", { path });
5+
}
6+
7+
export async function dbDisconnect(id: string): Promise<void> {
8+
await invoke("db_disconnect", { id });
9+
}
10+
11+
export async function dbIsConnected(id: string): Promise<boolean> {
12+
return invoke<boolean>("db_is_connected", { id });
13+
}
14+
15+
export function formatConnectionError(err: unknown): string {
16+
if (typeof err === "string") return err;
17+
if (err && typeof err === "object") {
18+
const e = err as Record<string, unknown>;
19+
if (typeof e.kind === "string") {
20+
const parts = [e.kind, e.driver, e.message, e.id]
21+
.filter((v): v is string => typeof v === "string" && v.length > 0);
22+
return parts.join(": ");
23+
}
24+
if (typeof e.message === "string") return e.message;
25+
}
26+
return String(err);
27+
}

0 commit comments

Comments
 (0)