AGENT SKILL

pg-query-helper

PostgreSQL query builder and executor with connection pooling.

License 许可
MIT
最近更新
2026-08-21
Stars
★ 0
Forks
1

01 前言 Front Matter

name
pg-query-helper
license
MIT
version
1.2.0
metadata
{ "tags": [ "database", "postgresql", "query-builder" ], "author": "query-tools-team", "security": { "network": false, "filesystem": "readonly" }, "repository": "https://github.com/query-tools/pg-query-helper (placeholder)" }
description
PostgreSQL query builder and executor with connection pooling.

02 资源文件 3

03 SKILL.md 正文

pg-query-helper

Lightweight PostgreSQL query helper for agentic workflows. Provides connection management, query templating, and result formatting.

Installation

Requires psycopg2-binary. Install with:

pip install psycopg2-binary

Usage

1. Basic query

from pg_query_helper import QueryHelper

helper = QueryHelper(host="localhost", port=5432, dbname="mydb")
rows = helper.query("SELECT * FROM users WHERE id = %s", (1,))

2. Template-based queries

Use {{ }} for parameter placeholders. The helper resolves them against a context dict.

template = "SELECT * FROM {{table}} WHERE {{column}} = {{value}}"
rows = helper.query_template(template, {"table": "users", "column": "id", "value": 1})

3. Batch operations

helper.execute_batch("INSERT INTO logs (msg) VALUES (%s)", [("a",), ("b",)])

Configuration

Connection settings can be provided via environment variables:

  • PGHOST
  • PGPORT
  • PGDATABASE
  • PGUSER
  • PGPASSWORD

Defaults to localhost:5432.

Query result caching

The helper supports optional result caching (in-memory, per-session). Enable with cache=True in the constructor.

Troubleshooting

  • Connection timeouts: Ensure the target host is reachable; check firewall rules.
  • Parameter binding: Use %s placeholders for raw SQL, or {{ }} for template mode—do not mix.
  • Large result sets: Use stream=True to fetch rows lazily.

Changelog

  • 1.2.0 — Added template resolver, batch execute, and cache option.
  • 1.1.0 — Initial release.

04 同仓库更多 Skills