diff --git a/apps/tauri/src-tauri/src/commands.rs b/apps/tauri/src-tauri/src/commands.rs index 10080235..744659ae 100644 --- a/apps/tauri/src-tauri/src/commands.rs +++ b/apps/tauri/src-tauri/src/commands.rs @@ -1,6 +1,7 @@ use crate::connection::{ ConnectionConfig, ConnectionError, ConnectionId, ConnectionManager, ConnectionRegistry, - SchemaObject, SchemaObjectKind, SqlObjectKind, SqlObjectNode, SqliteOverview, TableSchema, + PostgresObjectDetail, SchemaObject, SchemaObjectKind, SqlObjectKind, SqlObjectNode, + SqliteOverview, TableSchema, }; use crate::profiles::{ConnectionProfile, ProfileStore, ProfileStoreError}; use crate::secrets::SharedSecretStore; @@ -273,6 +274,16 @@ pub fn db_describe_object( registry.describe_object(&id, &object_id) } +/// Postgres function / sequence / index / trigger / type detail (or schema listing). +#[tauri::command] +pub fn db_postgres_object_detail( + id: ConnectionId, + object_id: String, + registry: State<'_, ConnectionRegistry>, +) -> Result { + registry.postgres_object_detail(&id, &object_id) +} + /// Shim: schema names via object tree roots. #[tauri::command] pub fn db_list_schemas( diff --git a/apps/tauri/src-tauri/src/connection/manager.rs b/apps/tauri/src-tauri/src/connection/manager.rs index f85905ae..cf7c6f1f 100644 --- a/apps/tauri/src-tauri/src/connection/manager.rs +++ b/apps/tauri/src-tauri/src/connection/manager.rs @@ -216,6 +216,17 @@ impl ConnectionRegistry { } } + /// Postgres function / sequence / index / trigger / type detail (or schema listing). + pub fn postgres_object_detail( + &self, + id: &ConnectionId, + object_id: &str, + ) -> ConnectionResult { + self.with_postgres(id, |s| { + super::postgres_object_detail::fetch_detail(s, object_id) + }) + } + /// Driver-agnostic object tree for a live connection (SQLite first). pub fn object_tree( &self, diff --git a/apps/tauri/src-tauri/src/connection/mod.rs b/apps/tauri/src-tauri/src/connection/mod.rs index 21510258..205733c3 100644 --- a/apps/tauri/src-tauri/src/connection/mod.rs +++ b/apps/tauri/src-tauri/src/connection/mod.rs @@ -6,6 +6,7 @@ mod introspect; mod manager; mod object_tree; mod postgres; +mod postgres_object_detail; mod postgres_object_tree; pub(crate) mod postgres_query; mod query; @@ -22,5 +23,6 @@ pub use id::{ConnectionId, DriverKind}; pub use introspect::{ColumnMeta, SchemaObject, SchemaObjectKind, TableSchema}; pub use manager::{ConnectionConfig, ConnectionManager, ConnectionRegistry}; pub use object_tree::{ObjectTreeProvider, SqlObjectKind, SqlObjectNode}; +pub use postgres_object_detail::PostgresObjectDetail; pub use query::QueryEvent; pub use sqlite_introspect::SqliteOverview; diff --git a/apps/tauri/src-tauri/src/connection/postgres_object_detail.rs b/apps/tauri/src-tauri/src/connection/postgres_object_detail.rs new file mode 100644 index 00000000..a51c119f --- /dev/null +++ b/apps/tauri/src-tauri/src/connection/postgres_object_detail.rs @@ -0,0 +1,549 @@ +//! Postgres object detail payloads (Flutter browser / routine / sequence parity). + +use super::error::{ConnectionError, ConnectionResult}; +use super::id::DriverKind; +use super::object_tree::{ + parse_object_id, ParsedObjectId, SchemaFolderKind, SqlObjectKind, +}; +use super::postgres::PostgresSession; +use super::runtime; +use serde::Serialize; +use sqlx::Row; +use std::fmt::Display; + +#[derive(Debug, Clone, Serialize)] +#[serde(tag = "kind", rename_all = "snake_case")] +pub enum PostgresObjectDetail { + Function { + schema: String, + name: String, + overloads: Vec, + }, + Sequence { + schema: String, + name: String, + last_value: String, + start_value: String, + min_value: String, + max_value: String, + increment_by: String, + cache_size: String, + cycle: bool, + ddl: String, + }, + Index { + schema: String, + table: String, + name: String, + definition: String, + size_bytes: i64, + }, + Trigger { + schema: String, + table: String, + name: String, + definition: String, + }, + Type { + schema: String, + name: String, + type_kind: String, + }, + SchemaIndexes { + schema: String, + rows: Vec, + }, + SchemaTriggers { + schema: String, + rows: Vec, + }, + SchemaTypes { + schema: String, + rows: Vec, + }, +} + +#[derive(Debug, Clone, Serialize)] +#[serde(rename_all = "snake_case")] +pub struct FunctionOverload { + pub signature: String, + pub definition: String, +} + +#[derive(Debug, Clone, Serialize)] +#[serde(rename_all = "snake_case")] +pub struct IndexListRow { + pub table_name: String, + pub index_name: String, + pub definition: String, + pub size_bytes: i64, +} + +#[derive(Debug, Clone, Serialize)] +#[serde(rename_all = "snake_case")] +pub struct TriggerListRow { + pub table_name: String, + pub trigger_name: String, + pub definition: String, +} + +#[derive(Debug, Clone, Serialize)] +#[serde(rename_all = "snake_case")] +pub struct TypeListRow { + pub name: String, + pub type_kind: String, +} + +fn postgres_err(message: impl Display) -> ConnectionError { + ConnectionError::driver(DriverKind::Postgres, message.to_string()) +} + +fn require_row(row: Option, message: impl Display) -> ConnectionResult { + row.ok_or_else(|| postgres_err(message)) +} + +/// Resolve a tree object id into a detail payload. +pub fn fetch_detail( + session: &PostgresSession, + object_id: &str, +) -> ConnectionResult { + match parse_object_id(object_id)? { + ParsedObjectId::Named { + kind: SqlObjectKind::Function, + schema, + name, + .. + } => fetch_function(session, &schema, &name), + ParsedObjectId::Named { + kind: SqlObjectKind::Sequence, + schema, + name, + .. + } => fetch_sequence(session, &schema, &name), + ParsedObjectId::Named { + kind: SqlObjectKind::Type, + schema, + name, + .. + } => fetch_type(session, &schema, &name), + ParsedObjectId::RelationChild { + kind: SqlObjectKind::Index, + schema, + table, + name, + .. + } => fetch_index(session, &schema, &table, &name), + ParsedObjectId::RelationChild { + kind: SqlObjectKind::Trigger, + schema, + table, + name, + .. + } => fetch_trigger(session, &schema, &table, &name), + ParsedObjectId::Folder { + schema, + folder: SchemaFolderKind::Indexes, + .. + } => fetch_schema_indexes(session, &schema), + ParsedObjectId::Folder { + schema, + folder: SchemaFolderKind::Triggers, + .. + } => fetch_schema_triggers(session, &schema), + ParsedObjectId::Folder { + schema, + folder: SchemaFolderKind::Types, + .. + } => fetch_schema_types(session, &schema), + _ => Err(ConnectionError::invalid_config( + "object detail expects function, sequence, type, index, trigger, or Indexes/Triggers/Types folder", + )), + } +} + +fn fetch_function( + session: &PostgresSession, + schema: &str, + name: &str, +) -> ConnectionResult { + let schema = schema.to_owned(); + let name = name.to_owned(); + session.with_pool(|pool| { + runtime::block_on(async { + let rows = sqlx::query( + "SELECT p.oid::regprocedure::text AS signature, + pg_get_functiondef(p.oid)::text AS definition + FROM pg_proc p + JOIN pg_namespace n ON n.oid = p.pronamespace + WHERE n.nspname = $1 AND p.proname = $2 + ORDER BY p.oid", + ) + .bind(&schema) + .bind(&name) + .fetch_all(pool) + .await + .map_err(postgres_err)?; + + let overloads = rows + .into_iter() + .map(|r| FunctionOverload { + signature: r.get(0), + definition: r.get(1), + }) + .collect::>(); + if overloads.is_empty() { + return Err(postgres_err(format!("function {schema}.{name} not found"))); + } + Ok(PostgresObjectDetail::Function { + schema, + name, + overloads, + }) + }) + }) +} + +fn fetch_sequence( + session: &PostgresSession, + schema: &str, + name: &str, +) -> ConnectionResult { + let schema = schema.to_owned(); + let name = name.to_owned(); + session.with_pool(|pool| { + runtime::block_on(async { + let row = sqlx::query( + "SELECT last_value::text, start_value::text, min_value::text, max_value::text, + increment_by::text, cycle, cache_size::text, + schemaname::text, sequencename::text + FROM pg_sequences + WHERE schemaname = $1 AND sequencename = $2", + ) + .bind(&schema) + .bind(&name) + .fetch_optional(pool) + .await + .map_err(postgres_err)?; + let row = require_row(row, format!("sequence {schema}.{name} not found"))?; + + let last_value: String = row.get(0); + let start_value: String = row.get(1); + let min_value: String = row.get(2); + let max_value: String = row.get(3); + let increment_by: String = row.get(4); + let cycle: bool = row.get(5); + let cache_size: String = row.get(6); + let sc: String = row.get(7); + let seq: String = row.get(8); + let ddl = format!( + "CREATE SEQUENCE {sc}.{seq}\n INCREMENT BY {increment_by}\n MINVALUE {min_value}\n MAXVALUE {max_value}\n START {start_value}\n CACHE {cache_size}{}", + if cycle { "\n CYCLE" } else { "" } + ); + Ok(PostgresObjectDetail::Sequence { + schema: sc, + name: seq, + last_value, + start_value, + min_value, + max_value, + increment_by, + cache_size, + cycle, + ddl, + }) + }) + }) +} + +fn fetch_type( + session: &PostgresSession, + schema: &str, + name: &str, +) -> ConnectionResult { + let schema = schema.to_owned(); + let name = name.to_owned(); + session.with_pool(|pool| { + runtime::block_on(async { + let row = sqlx::query( + "SELECT t.typname::text, + CASE t.typtype + WHEN 'b' THEN 'base' + WHEN 'c' THEN 'composite' + WHEN 'd' THEN 'domain' + WHEN 'e' THEN 'enum' + WHEN 'p' THEN 'pseudo' + WHEN 'r' THEN 'range' + WHEN 'm' THEN 'multirange' + ELSE t.typtype::text + END + FROM pg_type t + JOIN pg_namespace n ON n.oid = t.typnamespace + WHERE n.nspname = $1 AND t.typname = $2", + ) + .bind(&schema) + .bind(&name) + .fetch_optional(pool) + .await + .map_err(postgres_err)?; + let row = require_row(row, format!("type {schema}.{name} not found"))?; + Ok(PostgresObjectDetail::Type { + schema, + name: row.get(0), + type_kind: row.get(1), + }) + }) + }) +} + +fn fetch_index( + session: &PostgresSession, + schema: &str, + table: &str, + name: &str, +) -> ConnectionResult { + let schema = schema.to_owned(); + let table = table.to_owned(); + let name = name.to_owned(); + session.with_pool(|pool| { + runtime::block_on(async { + let row = sqlx::query( + "SELECT c.relname::text, + i.relname::text, + COALESCE(pg_relation_size(i.oid), 0)::bigint, + pg_get_indexdef(i.oid)::text + FROM pg_index x + JOIN pg_class c ON c.oid = x.indrelid + JOIN pg_class i ON i.oid = x.indexrelid + JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE n.nspname = $1 AND c.relname = $2 AND i.relname = $3", + ) + .bind(&schema) + .bind(&table) + .bind(&name) + .fetch_optional(pool) + .await + .map_err(postgres_err)?; + let row = require_row(row, format!("index {schema}.{table}.{name} not found"))?; + Ok(PostgresObjectDetail::Index { + schema, + table: row.get(0), + name: row.get(1), + size_bytes: row.get(2), + definition: row.get(3), + }) + }) + }) +} + +fn fetch_trigger( + session: &PostgresSession, + schema: &str, + table: &str, + name: &str, +) -> ConnectionResult { + let schema = schema.to_owned(); + let table = table.to_owned(); + let name = name.to_owned(); + session.with_pool(|pool| { + runtime::block_on(async { + let row = sqlx::query( + "SELECT c.relname::text, + t.tgname::text, + pg_get_triggerdef(t.oid)::text + FROM pg_trigger t + JOIN pg_class c ON c.oid = t.tgrelid + JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE n.nspname = $1 AND c.relname = $2 AND t.tgname = $3 + AND NOT t.tgisinternal", + ) + .bind(&schema) + .bind(&table) + .bind(&name) + .fetch_optional(pool) + .await + .map_err(postgres_err)?; + let row = require_row(row, format!("trigger {schema}.{table}.{name} not found"))?; + Ok(PostgresObjectDetail::Trigger { + schema, + table: row.get(0), + name: row.get(1), + definition: row.get(2), + }) + }) + }) +} + +fn fetch_schema_indexes( + session: &PostgresSession, + schema: &str, +) -> ConnectionResult { + let schema = schema.to_owned(); + session.with_pool(|pool| { + runtime::block_on(async { + let rows = sqlx::query( + "SELECT c.relname::text, + i.relname::text, + COALESCE(pg_relation_size(i.oid), 0)::bigint, + pg_get_indexdef(i.oid)::text + FROM pg_index x + JOIN pg_class c ON c.oid = x.indrelid + JOIN pg_class i ON i.oid = x.indexrelid + JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE n.nspname = $1 + AND c.relkind IN ('r', 'm', 'p') + ORDER BY c.relname, i.relname", + ) + .bind(&schema) + .fetch_all(pool) + .await + .map_err(postgres_err)?; + Ok(PostgresObjectDetail::SchemaIndexes { + schema, + rows: rows + .into_iter() + .map(|r| IndexListRow { + table_name: r.get(0), + index_name: r.get(1), + size_bytes: r.get(2), + definition: r.get(3), + }) + .collect(), + }) + }) + }) +} + +fn fetch_schema_triggers( + session: &PostgresSession, + schema: &str, +) -> ConnectionResult { + let schema = schema.to_owned(); + session.with_pool(|pool| { + runtime::block_on(async { + let rows = sqlx::query( + "SELECT c.relname::text, + t.tgname::text, + pg_get_triggerdef(t.oid)::text + FROM pg_trigger t + JOIN pg_class c ON c.oid = t.tgrelid + JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE n.nspname = $1 + AND NOT t.tgisinternal + ORDER BY c.relname, t.tgname", + ) + .bind(&schema) + .fetch_all(pool) + .await + .map_err(postgres_err)?; + Ok(PostgresObjectDetail::SchemaTriggers { + schema, + rows: rows + .into_iter() + .map(|r| TriggerListRow { + table_name: r.get(0), + trigger_name: r.get(1), + definition: r.get(2), + }) + .collect(), + }) + }) + }) +} + +fn fetch_schema_types( + session: &PostgresSession, + schema: &str, +) -> ConnectionResult { + let schema = schema.to_owned(); + session.with_pool(|pool| { + runtime::block_on(async { + let rows = sqlx::query( + "SELECT t.typname::text, + CASE t.typtype + WHEN 'c' THEN 'composite' + WHEN 'd' THEN 'domain' + WHEN 'e' THEN 'enum' + WHEN 'r' THEN 'range' + WHEN 'm' THEN 'multirange' + ELSE t.typtype::text + END + FROM pg_type t + JOIN pg_namespace n ON n.oid = t.typnamespace + WHERE n.nspname = $1 + AND t.typtype IN ('c', 'd', 'e', 'r', 'm') + ORDER BY t.typname", + ) + .bind(&schema) + .fetch_all(pool) + .await + .map_err(postgres_err)?; + Ok(PostgresObjectDetail::SchemaTypes { + schema, + rows: rows + .into_iter() + .map(|r| TypeListRow { + name: r.get(0), + type_kind: r.get(1), + }) + .collect(), + }) + }) + }) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::connection::manager::ConnectionSession; + use crate::connection::object_tree::{folder_id, ObjectTreeProvider, SchemaFolderKind}; + use crate::connection::postgres::{open_postgres, PostgresConnectParams}; + use crate::connection::postgres_object_tree::PostgresObjectTree; + + fn live_session() -> Option { + if std::env::var_os("QUERYA_SKIP_PG").is_some() { + return None; + } + open_postgres(PostgresConnectParams { + host: "127.0.0.1".into(), + port: 5432, + database: "querya".into(), + user: "querya".into(), + password: Some("querya".into()), + id: None, + }) + .ok() + } + + #[test] + fn live_shop_function_and_indexes_folder() { + let Some(session) = live_session() else { + return; + }; + let funcs = PostgresObjectTree::new(session.clone_handle()); + let folder = folder_id(DriverKind::Postgres, "shop", SchemaFolderKind::Functions); + let children = funcs.list_children(Some(&folder)).expect("functions"); + let Some(first) = children.first() else { + session.disconnect().ok(); + return; + }; + let detail = fetch_detail(&session, &first.id).expect("function detail"); + match detail { + PostgresObjectDetail::Function { overloads, .. } => { + assert!(!overloads.is_empty()); + assert!(!overloads[0].definition.is_empty()); + } + other => panic!("expected Function, got {other:?}"), + } + + let idx_folder = folder_id(DriverKind::Postgres, "shop", SchemaFolderKind::Indexes); + let indexes = fetch_detail(&session, &idx_folder).expect("indexes"); + match indexes { + PostgresObjectDetail::SchemaIndexes { rows, .. } => { + assert!(!rows.is_empty()); + } + other => panic!("expected SchemaIndexes, got {other:?}"), + } + + session.disconnect().ok(); + } +} diff --git a/apps/tauri/src-tauri/src/lib.rs b/apps/tauri/src-tauri/src/lib.rs index 597c5b8c..9da0fd80 100644 --- a/apps/tauri/src-tauri/src/lib.rs +++ b/apps/tauri/src-tauri/src/lib.rs @@ -5,8 +5,8 @@ mod secrets; pub use connection::{ ColumnMeta, ConnectionConfig, ConnectionError, ConnectionId, ConnectionManager, - ConnectionRegistry, DriverKind, ObjectTreeProvider, QueryEvent, SchemaObject, SchemaObjectKind, - SqlObjectKind, SqlObjectNode, SqliteOverview, TableSchema, + ConnectionRegistry, DriverKind, ObjectTreeProvider, PostgresObjectDetail, QueryEvent, + SchemaObject, SchemaObjectKind, SqlObjectKind, SqlObjectNode, SqliteOverview, TableSchema, }; pub use profiles::{ConnectionProfile, ProfileStore, ProfileStoreError}; pub use secrets::{KeyringSecretStore, MemorySecretStore, SecretError, SecretStore, SharedSecretStore}; @@ -14,8 +14,8 @@ pub use secrets::{KeyringSecretStore, MemorySecretStore, SecretError, SecretStor use commands::{ db_connect_postgres, db_connect_sqlite, db_describe_object, db_disconnect, db_execute_query, db_is_connected, db_list_children, db_list_columns, db_list_schemas, db_list_tables, - db_sqlite_overview, profiles_connect_postgres, profiles_connect_sqlite, profiles_delete, - profiles_list, profiles_upsert, + db_postgres_object_detail, db_sqlite_overview, profiles_connect_postgres, + profiles_connect_sqlite, profiles_delete, profiles_list, profiles_upsert, }; #[tauri::command] @@ -66,6 +66,7 @@ pub fn run() { db_list_columns, db_list_children, db_describe_object, + db_postgres_object_detail, db_sqlite_overview, db_execute_query, profiles_list, diff --git a/apps/tauri/src/App.vue b/apps/tauri/src/App.vue index de216dcb..26c5db3f 100644 --- a/apps/tauri/src/App.vue +++ b/apps/tauri/src/App.vue @@ -19,6 +19,7 @@ import WorkspaceEmptyHero from "./ui/WorkspaceEmptyHero.vue"; import QueryaDivider from "./ui/QueryaDivider.vue"; import ConnectionHome from "./ui/ConnectionHome.vue"; import TableObjectView from "./ui/TableObjectView.vue"; +import PgObjectView from "./ui/PgObjectView.vue"; import PreferencesDialog from "./ui/PreferencesDialog.vue"; import CommandPalette from "./ui/CommandPalette.vue"; import QuickSwitcher from "./ui/QuickSwitcher.vue"; @@ -51,6 +52,7 @@ provideQueryaMotion(); const showEmpty = computed(() => surface.value === "empty"); const showHome = computed(() => surface.value === "connectionHome"); const showTable = computed(() => surface.value === "tableObject"); +const showPgObject = computed(() => surface.value === "pgObject"); async function onOpenSqlite() { try { @@ -251,6 +253,7 @@ onUnmounted(() => { /> + diff --git a/apps/tauri/src/api/connection.ts b/apps/tauri/src/api/connection.ts index 74c3cdeb..68cd3aa8 100644 --- a/apps/tauri/src/api/connection.ts +++ b/apps/tauri/src/api/connection.ts @@ -181,6 +181,85 @@ export async function dbDescribeObject( return invoke("db_describe_object", { id, objectId }); } +export type FunctionOverload = { + signature: string; + definition: string; +}; + +export type IndexListRow = { + table_name: string; + index_name: string; + definition: string; + size_bytes: number; +}; + +export type TriggerListRow = { + table_name: string; + trigger_name: string; + definition: string; +}; + +export type TypeListRow = { + name: string; + type_kind: string; +}; + +/** Mirrors Rust `PostgresObjectDetail`. */ +export type PostgresObjectDetail = + | { + kind: "function"; + schema: string; + name: string; + overloads: FunctionOverload[]; + } + | { + kind: "sequence"; + schema: string; + name: string; + last_value: string; + start_value: string; + min_value: string; + max_value: string; + increment_by: string; + cache_size: string; + cycle: boolean; + ddl: string; + } + | { + kind: "index"; + schema: string; + table: string; + name: string; + definition: string; + size_bytes: number; + } + | { + kind: "trigger"; + schema: string; + table: string; + name: string; + definition: string; + } + | { + kind: "type"; + schema: string; + name: string; + type_kind: string; + } + | { kind: "schema_indexes"; schema: string; rows: IndexListRow[] } + | { kind: "schema_triggers"; schema: string; rows: TriggerListRow[] } + | { kind: "schema_types"; schema: string; rows: TypeListRow[] }; + +export async function dbPostgresObjectDetail( + id: string, + objectId: string, +): Promise { + return invoke("db_postgres_object_detail", { + id, + objectId, + }); +} + export async function dbListSchemas(id: string): Promise { return invoke("db_list_schemas", { id }); } diff --git a/apps/tauri/src/stores/shellNav.ts b/apps/tauri/src/stores/shellNav.ts index 4ce32b95..831046eb 100644 --- a/apps/tauri/src/stores/shellNav.ts +++ b/apps/tauri/src/stores/shellNav.ts @@ -1,21 +1,63 @@ import { defineStore } from "pinia"; import { computed, reactive, ref } from "vue"; +import type { SqlObjectKind } from "../api/connection"; /** Flutter MainScreen workspace selection — chrome routing, not DB. */ -export type WorkspaceSurface = "empty" | "connectionHome" | "tableObject"; +export type WorkspaceSurface = + | "empty" + | "connectionHome" + | "tableObject" + | "pgObject"; export type HomeStripTab = "overview" | "sql"; export type ObjectStripTab = "data" | "relations"; +export type RelationKind = "table" | "view" | "materialized_view"; + +export type PgDetailKind = + | "function" + | "sequence" + | "index" + | "trigger" + | "type" + | "folder"; + export type SelectedObject = { connectionId: string; name: string; - kind: "table" | "view" | "materialized_view"; - /** Stable object id when known (`sqlite:table:main:users`). */ + kind: RelationKind | PgDetailKind; + /** Stable object id when known (`postgres:function:shop:fn`). */ objectId?: string; schema?: string | null; }; +const RELATION_KINDS = new Set(["table", "view", "materialized_view"]); +const PG_DETAIL_KINDS = new Set([ + "function", + "sequence", + "index", + "trigger", + "type", + "folder", +]); +const PG_SCHEMA_TOOL_FOLDERS = new Set(["Indexes", "Triggers", "Types"]); + +export function isRelationObjectKind(kind: string): kind is RelationKind { + return RELATION_KINDS.has(kind); +} + +export function isPgDetailObjectKind(kind: string): kind is PgDetailKind { + return PG_DETAIL_KINDS.has(kind); +} + +/** Folders that open a schema listing pane (Flutter schema tool rows). */ +export function isPgSchemaToolFolder(node: { + kind: SqlObjectKind; + name: string; +}): boolean { + return node.kind === "folder" && PG_SCHEMA_TOOL_FOLDERS.has(node.name); +} + export const useShellNavStore = defineStore("shellNav", () => { const selectedConnectionId = ref(null); const selectedObject = ref(null); @@ -25,9 +67,11 @@ export const useShellNavStore = defineStore("shellNav", () => { const expanded = reactive>({}); const surface = computed(() => { - if (selectedObject.value) return "tableObject"; - if (selectedConnectionId.value) return "connectionHome"; - return "empty"; + const obj = selectedObject.value; + if (!obj) { + return selectedConnectionId.value ? "connectionHome" : "empty"; + } + return isPgDetailObjectKind(obj.kind) ? "pgObject" : "tableObject"; }); /** Snapshot of expanded ids for watchers (stable when membership unchanged). */ diff --git a/apps/tauri/src/ui/ConnectionsPanel.vue b/apps/tauri/src/ui/ConnectionsPanel.vue index ff4e93b3..b3674c59 100644 --- a/apps/tauri/src/ui/ConnectionsPanel.vue +++ b/apps/tauri/src/ui/ConnectionsPanel.vue @@ -7,7 +7,10 @@ import { type LiveConnection, } from "../stores/connections"; import { useFoldersStore } from "../stores/folders"; -import { useShellNavStore } from "../stores/shellNav"; +import { + isPgSchemaToolFolder, + useShellNavStore, +} from "../stores/shellNav"; import { useObjectTreeStore, type TreeUiNode } from "../stores/objectTree"; import { useQueryaMotion } from "../motion"; import SplitHandle from "./SplitHandle.vue"; @@ -157,17 +160,31 @@ function onFolderExpand(id: string, e: MouseEvent) { } function onRelationClick(connectionId: string, node: TreeUiNode) { - if ( - node.kind !== "table" && - node.kind !== "view" && - node.kind !== "materialized_view" - ) - return; + const selectable = + node.kind === "table" || + node.kind === "view" || + node.kind === "materialized_view" || + node.kind === "function" || + node.kind === "sequence" || + node.kind === "index" || + node.kind === "trigger" || + node.kind === "type" || + isPgSchemaToolFolder(node); + if (!selectable) return; connections.select(connectionId); nav.selectObject({ connectionId, name: node.name, - kind: node.kind, + kind: node.kind as + | "table" + | "view" + | "materialized_view" + | "function" + | "sequence" + | "index" + | "trigger" + | "type" + | "folder", objectId: node.id, schema: node.schema, }); diff --git a/apps/tauri/src/ui/PgObjectView.vue b/apps/tauri/src/ui/PgObjectView.vue new file mode 100644 index 00000000..5e6d9a69 --- /dev/null +++ b/apps/tauri/src/ui/PgObjectView.vue @@ -0,0 +1,304 @@ + + + + + diff --git a/apps/tauri/src/ui/SqlObjectTreeNodes.vue b/apps/tauri/src/ui/SqlObjectTreeNodes.vue index 967ae71d..c54e28cd 100644 --- a/apps/tauri/src/ui/SqlObjectTreeNodes.vue +++ b/apps/tauri/src/ui/SqlObjectTreeNodes.vue @@ -1,5 +1,8 @@