1 unstable release
| 0.1.0 | Sep 25, 2025 |
|---|
#727 in Database interfaces
26KB
557 lines
pgqb 🗄️
A sleek and interactive PostgreSQL query builder for the terminal! 🚀
pgqb is a command-line tool that helps you build and execute SQL queries interactively. No more typing complex queries by hand – just select your tables, columns, filters, and more through an intuitive interface!
Features ✨
- Interactive Query Building: Step-by-step selection of schemas, tables, columns, WHERE clauses, ORDER BY, and LIMIT.
- Fuzzy Search: Quickly find tables with fuzzy search support.
- Rich Descriptions: View table and column descriptions (if available) with aligned formatting.
- Multiple Output Formats: Export results as CSV, JSON, JSON Lines, or TSV.
- Flexible Output Destinations: Save to files or pipe to stdout (with pager support via shell).
- Safe Execution: Confirm queries before execution, with an option to skip confirmations.
- Cross-Platform: Works on Linux, macOS, and Windows.
Installation 🛠️
Install directly from crates.io:
cargo install pgqb
Or build from source:
- Ensure you have Rust installed: rustup.rs
- Clone the repository:
git clone https://github.com/PKWadsy/pgqb.git cd pgqb - Build and install:
cargo build --release cargo install --path .
Usage 📖
Basic Usage
pgqb "postgresql://user:password@localhost/dbname"
This starts the interactive query builder. Follow the prompts to select your table, columns, and options.
Command-Line Options
--conn <CONNECTION_STRING>: PostgreSQL connection string (required)--details: Show table and column descriptions--exec: Execute the generated query--no-confirm: Skip confirmation prompts--format <FORMAT>: Output format (csv, json, jsonl, tsv)--output <DEST>: Output destination (file path)
Examples
-
Interactive mode with descriptions:
pgqb --conn "postgresql://user:pass@localhost/db" --details -
Execute query and save as CSV:
pgqb --conn "postgresql://user:pass@localhost/db" --exec --format csv --output results.csv -
Pipe to pager:
pgqb --conn "postgresql://user:pass@localhost/db" --exec --format table | less
How It Works 🔍
- Select Schema & Table: Choose from available schemas and tables with fuzzy search.
- Pick Columns: Multi-select columns to include (or select all with
*). - Add Filters: Enter WHERE clauses with column name autocompletion.
- Sort & Limit: Optionally add ORDER BY and LIMIT clauses.
- Execute & Export: Run the query and choose output format/destination.
The tool generates clean, properly formatted SQL queries and handles various PostgreSQL data types.
Output Formats 📊
- CSV: Comma-separated values with headers
- JSON: Pretty-printed JSON array of objects
- JSONL: JSON Lines (one JSON object per line)
- TSV: Tab-separated values
Contributing 🤝
Contributions welcome! Please feel free to submit issues, feature requests, or pull requests.
License 📄
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ and lots of ☕
Dependencies
~14–29MB
~404K SLoC