BTC
ETH
SOL
BNB
GOLD
XRP
DOGE
ADA
Back to home
Tech

pGenie – SQL-first code generator for PostgreSQL (Haskell, Rust, Java)

pGenie takes plain PostgreSQL SQL as input—migrations and queries—and outputs validated code, index management, and type-safe client SDKs in Haskell, Rust, or Java.

pGenie takes plain PostgreSQL SQL as input—migrations and queries—and outputs validated code, index management, and type-safe client SDKs in Haskell, Rust, or Java. Developers write SQL in migrations/ and queries/ directories, then run pgn generate. It checks queries against the schema from migrations, flags errors like wrong types or nullability mismatches, suggests index additions or drops, and spits out APIs with inferred types. No ORMs, no DSLs—just your SQL, verified and codified.

This matters because SQL drift kills production databases. Teams evolve schemas and queries independently, leading to runtime failures: sequential scans from missing indexes, broken joins from altered columns, or null pointer exceptions from guessed types. pGenie enforces consistency upfront. Run it in CI, and PRs fail if SQL doesn’t match the schema. In 2024, with LLMs like GPT-4 or Claude drafting queries, this verification layer turns AI output from risky drafts into shippable code. LLMs hallucinate schema details 20-30% of the time on complex DBs, per benchmarks from Supabase and Timescale; pGenie catches that before deploy.

Workflow: Three Steps, Reproducible in CI

Step 1: Dump schema changes into migrations/ as raw PostgreSQL SQL files. pGenie replays them sequentially to build the effective schema—no abstractions to leak.

Step 2: Add queries to queries/. Each gets analyzed: column existence, type compatibility, nullability from actual constraints. It flags performance red flags like table scans on large tables (assuming stats from your DB).

Step 3: pgn generate produces: validation reports, index migration SQL (e.g., CREATE INDEX on frequently joined columns), and SDKs. For Rust, you get structs with Serde derives matching row shapes; Haskell gets typeclasses for encoders/decoders; Java, records or Lombok classes. One command, zero boilerplate wiring.

Reproducibility shines in pipelines. Dockerize it with your Postgres image, and every build uses the same schema state. No “works on my machine” excuses.

Implications for Real Teams

For SQL-heavy teams—think fintech analytics, e-commerce inventory, or crypto exchanges—pGenie closes gaps ORMs ignore. ORMs like Prisma or Diesel abstract SQL for speed but hide perf issues and complicate reviews. Hand-written SQL stays readable for audits, but manual typing in app code duplicates effort and errors. pGenie generates per-query functions: call getUserById(id: UUID) -> Option<User> with compile-time guarantees from your schema.

Index management automates a chore. Redundant indexes bloat storage (up to 50% overhead in unoptimized DBs, per Percona studies); missing ones trigger scans costing 10x query time. pGenie diffs your schema, proposes changes as migrations.

AI integration amplifies this. Prompt an LLM for a query refactor, paste into queries/, generate—fail if it breaks. Early adopters report 40% faster iteration on data layers, per tool’s demos.

Skepticism: Language support is narrow—Haskell, Rust, Java only. No Python, Go, or JS/TS, limiting broad appeal. “Decentralized ecosystem” for custom generators sounds vague; it’s early, with few extensions listed. Assumes Postgres-only; no MySQL or Citus scaling. Still, for typed-lang stacks preferring SQL control, it delivers. Open-source core (check GitHub), so fork if needed.

Bottom line: pGenie shifts DB errors left, from runtime to compile-time, and scales with AI tooling. If your Postgres workload outgrows ORMs, test the demo—it validates faster than you think.

April 2, 2026 · 3 min · 10 views · Source: Lobsters

Related