From 84cea03d50babf69555863db6deb1b7ff6a16918 Mon Sep 17 00:00:00 2001 From: ZhuchkaTriplesix Date: Sun, 15 Nov 2026 07:01:20 +0300 Subject: [PATCH] feat(frontend): SQLite object tree with expandable columns Wire db_list_tables / db_list_columns into a sidebar OBJECTS pane that loads on active connection and expands tables to show column meta. --- apps/tauri/src/api/connection.ts | 44 ++++- apps/tauri/src/stores/objectTree.ts | 106 ++++++++++ apps/tauri/src/ui/ConnectionsPanel.vue | 2 + apps/tauri/src/ui/SqliteObjectTree.vue | 255 +++++++++++++++++++++++++ 4 files changed, 405 insertions(+), 2 deletions(-) create mode 100644 apps/tauri/src/stores/objectTree.ts create mode 100644 apps/tauri/src/ui/SqliteObjectTree.vue diff --git a/apps/tauri/src/api/connection.ts b/apps/tauri/src/api/connection.ts index 037c2f13..35f71156 100644 --- a/apps/tauri/src/api/connection.ts +++ b/apps/tauri/src/api/connection.ts @@ -1,5 +1,29 @@ import { invoke } from "@tauri-apps/api/core"; +export type SchemaObjectKind = "table" | "view"; + +export type SchemaObject = { + name: string; + kind: SchemaObjectKind; + schema?: string | null; +}; + +export type ColumnMeta = { + name: string; + data_type: string; + is_nullable: boolean; + is_primary_key: boolean; + primary_key_position?: number | null; + default_value?: string | null; +}; + +export type TableSchema = { + table_name: string; + schema?: string | null; + columns: ColumnMeta[]; + primary_keys: string[]; +}; + export async function dbConnectSqlite(path: string): Promise { return invoke("db_connect_sqlite", { path }); } @@ -12,13 +36,29 @@ export async function dbIsConnected(id: string): Promise { return invoke("db_is_connected", { id }); } +export async function dbListSchemas(id: string): Promise { + return invoke("db_list_schemas", { id }); +} + +export async function dbListTables(id: string): Promise { + return invoke("db_list_tables", { id }); +} + +export async function dbListColumns( + id: string, + table: string, +): Promise { + return invoke("db_list_columns", { id, table }); +} + export function formatConnectionError(err: unknown): string { if (typeof err === "string") return err; if (err && typeof err === "object") { const e = err as Record; if (typeof e.kind === "string") { - const parts = [e.kind, e.driver, e.message, e.id] - .filter((v): v is string => typeof v === "string" && v.length > 0); + const parts = [e.kind, e.driver, e.message, e.id].filter( + (v): v is string => typeof v === "string" && v.length > 0, + ); return parts.join(": "); } if (typeof e.message === "string") return e.message; diff --git a/apps/tauri/src/stores/objectTree.ts b/apps/tauri/src/stores/objectTree.ts new file mode 100644 index 00000000..2948e6ae --- /dev/null +++ b/apps/tauri/src/stores/objectTree.ts @@ -0,0 +1,106 @@ +import { defineStore } from "pinia"; +import { ref, watch } from "vue"; +import { + dbListColumns, + dbListTables, + formatConnectionError, + type ColumnMeta, + type SchemaObject, +} from "../api/connection"; +import { useConnectionsStore } from "./connections"; +import { useShellStatusStore } from "./shellStatus"; + +export type TreeTableNode = SchemaObject & { + expanded: boolean; + loadingColumns: boolean; + columns: ColumnMeta[] | null; + error: string | null; +}; + +/** SQLite object tree for the active connection. */ +export const useObjectTreeStore = defineStore("objectTree", () => { + const connectionId = ref(null); + const objects = ref([]); + const loading = ref(false); + const error = ref(null); + const filter = ref(""); + + async function loadFor(id: string | null) { + connectionId.value = id; + objects.value = []; + error.value = null; + filter.value = ""; + if (!id) return; + + loading.value = true; + try { + const list = await dbListTables(id); + objects.value = list.map((o) => ({ + ...o, + expanded: false, + loadingColumns: false, + columns: null, + error: null, + })); + } catch (err) { + error.value = formatConnectionError(err); + } finally { + loading.value = false; + } + } + + async function toggleTable(name: string) { + const id = connectionId.value; + const node = objects.value.find((o) => o.name === name); + if (!id || !node) return; + + if (node.expanded) { + node.expanded = false; + return; + } + + node.expanded = true; + if (node.columns) return; + + node.loadingColumns = true; + node.error = null; + try { + const schema = await dbListColumns(id, name); + node.columns = schema.columns; + } catch (err) { + node.error = formatConnectionError(err); + const status = useShellStatusStore(); + status.setQueryMetrics({ + message: node.error, + busy: false, + }); + } finally { + node.loadingColumns = false; + } + } + + function refresh() { + return loadFor(connectionId.value); + } + + // Keep tree in sync with active connection. + const connections = useConnectionsStore(); + watch( + () => connections.activeId, + (id) => { + void loadFor(id); + }, + { immediate: true }, + ); + + return { + connectionId, + objects, + loading, + error, + filter, + loadFor, + toggleTable, + refresh, + }; +}); diff --git a/apps/tauri/src/ui/ConnectionsPanel.vue b/apps/tauri/src/ui/ConnectionsPanel.vue index d3e6ee26..1542f07a 100644 --- a/apps/tauri/src/ui/ConnectionsPanel.vue +++ b/apps/tauri/src/ui/ConnectionsPanel.vue @@ -5,6 +5,7 @@ import { useShellStore } from "../stores/shell"; import { useConnectionsStore } from "../stores/connections"; import { useQueryaMotion } from "../motion"; import SplitHandle from "./SplitHandle.vue"; +import SqliteObjectTree from "./SqliteObjectTree.vue"; const emit = defineEmits<{ openSqlite: []; @@ -115,6 +116,7 @@ onUnmounted(() => { Open a SQLite file to start the vertical slice.

+