sosedoff / pgweb

Cross-platform client for PostgreSQL databases
https://sosedoff.github.io/pgweb
MIT License
8.55k stars 723 forks source link

Custom local queries #640

Closed sosedoff closed 1 year ago

sosedoff commented 1 year ago

This is a tracking issue for the new feature: Custom Local Queries

Background: Pgweb is a basic database browser and query runner, and does not have a way of executing any pre-defined user queries stored locally. There's no persistent level (aside from the filesystem) for storing these queries. When developing locally, or against a remote database, having an easy and quick access to a set of database-specific queries (mostly for troubleshooting or fast data selection) would be very convenient and helpful. We could allow Pgweb to read sql files (query+metadata?) from ~/.pgweb/queries/... and expose them in a separate Queries UI tab. This behavior smells like a BI use-case, but it's not.

Ideas:

Here's an example query file with pgweb metadata:

-- pgweb: database=myapp                 <- only available in "myappdb", remotely or locally
-- pgweb: database=myapp; host=localhost <- only available in "myappdb" locally
-- pgweb: database=myapp_*;              <- matching any database starting with "myapp", e.g. "myapp_development, "myapp_test"
-- pgweb: database=*;                    <- available for all connections and databases
-- pgweb: database=*;user=admin          <- available only for "admin" users on any connection

SELECT * FROM orders 
WHERE status = 'pending' AND amount > 1000 
ORDER BY submitted_at DESC 
LIMIT 100