Skip to content

Custom local queries #640

@sosedoff

Description

@sosedoff

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:

  • Store queries locally at ~/.pgweb/queries/ directory.
  • Allow queries to be available in different databases (local or remote) identified by name. We could encode database match pattern (among other things) in the query file via sql comment: -- pgweb:"OPTIONS". Any file that does not have a comment should be ignored.
  • Should be able to set max execution time

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions