$ show sosedoff/pgweb
pgweb is a web-based PostgreSQL database explorer written in Go. It provides a single-page application frontend (jQuery, Bootstrap 3, Ace editor) and a REST API backend (Gin framework) for browsing schemas, executing SQL queries, viewing table data, and exporting results. The application supports multi-session management, SSH tunnels, TOML-based bookmarks, Prometheus metrics, and third-party authentication backends. It is distributed as a single cross-platform binary with zero external runtime dependencies beyond a PostgreSQL server. The architecture is a monolith: the Go server serves static files and exposes API endpoints for database operations. Key entry points are the CLI (main.go -> pkg/cli/cli.go) and the API routes (pkg/api/routes.go). The codebase demonstrates solid engineering with clean abstractions for database client, connection string building, session management, and metrics, but the frontend relies on outdated libraries (jQuery 2.1.1, Bootstrap 3, Ace editor) and the project shows some technical drift in dependency versions and deprecated environment variables.
The LLM identified 6 files worth highlighting for reuse:
Builds a PostgreSQL connection string from CLI options, handling SSL mode, SSH tunnel configuration, and environment variable overrides. This is a self-contained utility that can be reused in any Go project needing to construct database connection strings from structured options.
Encapsulates database connection, query execution, read-only enforcement, and PostgreSQL version detection. Supports SSH tunneling and connection pooling. This abstraction can be extracted and reused as a standalone database client library for PostgreSQL.
Manages multiple database sessions with automatic idle timeout cleanup. Provides thread-safe session creation, retrieval, and expiration. This pattern is reusable for any web application that needs to manage long-lived database connections per user session.
Defines Prometheus counters and gauges for tracking active sessions, total queries, query errors, and uptime. Includes a metrics HTTP handler. This is a clean, reusable metrics instrumentation module that can be added to any Go web service.
Manages TOML-based bookmark files for database connections, supporting SSH tunnel configuration and environment variable substitution. Provides CRUD operations and file-based persistence. This pattern is reusable for any application that needs to store and manage connection profiles.
Loads SQL query files from a local directory, parsing metadata comments (-- pgweb: host, user, database) to filter queries by connection context. This enables per-database or per-user query libraries. The pattern of embedding metadata in SQL comments is reusable for any tool that needs to organize and filter SQL scripts.