pgqb

Crates.iopgqb
lib.rspgqb
version0.1.0
created_at2025-09-25 01:13:12.592776+00
updated_at2025-09-25 01:13:12.592776+00
descriptionAn interactive PostgreSQL query builder for the terminal
homepage
repositoryhttps://github.com/PKWadsy/pgqb
max_upload_size
id1854013
size63,288
(PKWadsy)

documentation

README

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:

  1. Ensure you have Rust installed: rustup.rs
  2. Clone the repository:
    git clone https://github.com/PKWadsy/pgqb.git
    cd pgqb
    
  3. 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

  1. Interactive mode with descriptions:

    pgqb --conn "postgresql://user:pass@localhost/db" --details
    
  2. Execute query and save as CSV:

    pgqb --conn "postgresql://user:pass@localhost/db" --exec --format csv --output results.csv
    
  3. Pipe to pager:

    pgqb --conn "postgresql://user:pass@localhost/db" --exec --format table | less
    

How It Works 🔍

  1. Select Schema & Table: Choose from available schemas and tables with fuzzy search.
  2. Pick Columns: Multi-select columns to include (or select all with *).
  3. Add Filters: Enter WHERE clauses with column name autocompletion.
  4. Sort & Limit: Optionally add ORDER BY and LIMIT clauses.
  5. 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 ☕

Commit count: 8

cargo fmt