Skip to main content

Crate ssh_commander_pg

Crate ssh_commander_pg 

Source
Expand description

PostgreSQL pool for the database explorer.

Sprint 6 model: each PgPool represents one configured Postgres profile and manages up to max_size underlying connections. Callers identify their work by session_id (typically a UUID per query tab). The pool maps session_id → connection so a tab’s cursor always lives on the same wire across execute → fetch_page → close_query. Idle connections are reused for fresh sessions.

§Why per-session leasing

tokio_postgres::Client is Sync, but a Postgres session is single-threaded by protocol: one transaction at a time, one cursor at a time. To let two query tabs run independent paginated SELECTs in parallel, each must hold its own connection for the cursor’s lifetime. Without that, opening cursor A then cursor B on the same wire kills A — what Sprint 5’s single-cursor invariant produced.

§SSH tunneling

The pool dials config.host:config.port directly and knows nothing about SSH. When a profile needs an SSH tunnel, the caller (the ConnectionManager) opens one SshTunnel, points the PgConfig at its local forwarded port, and keeps the tunnel alive for the pool’s lifetime. Single tunnel per profile keeps SSH session usage minimal.

§Thread safety

PgPool is Send + Sync. All public methods take &self and acquire internal locks for short windows (the pool’s own metadata Mutex during lease/release, and a per-connection Mutex during cursor bookkeeping). FFI callers wrap one Arc<PgPool> per managed connection id.

Re-exports§

pub use config::PgAuthMethod;
pub use config::PgConfig;
pub use config::PgTlsMode;
pub use edit::InsertColumnInput;
pub use edit::InsertedRow;
pub use edit::UpdateOutcome;
pub use exec::ActiveCursor;
pub use exec::ColumnMeta;
pub use exec::ExecutionOutcome;
pub use exec::PageResult;
pub use introspect::ColumnDetail;
pub use introspect::DbSummary;
pub use introspect::ObjectType;
pub use introspect::ObjectTypeKind;
pub use introspect::Relation;
pub use introspect::RelationKind;
pub use introspect::Routine;
pub use introspect::RoutineKind;
pub use introspect::SchemaContents;
pub use introspect::SchemaSummary;
pub use introspect::Sequence;

Modules§

config
PostgreSQL connection configuration.
edit
Cell-level row editing for the explorer.
exec
Query execution for the Postgres explorer.
introspect
Schema introspection queries against pg_catalog.

Structs§

PgPool

Enums§

PgError
Errors surfaced from the Postgres explorer layer.

Constants§

BROWSER_SESSION_ID
Stable session id used for the schema browser’s introspection calls (list_databases, list_schemas, list_relations). Uses a name that can’t collide with a UUID-generated tab session id.