My 14-Year Journey Away from ORMs - How I Built pGenie, the…
    Neura MarketNeura Market/Stable Diffusion
    ChatGPTChatGPTClaudeClaudeGeminiGeminiCursorCursorGrokGrokPerplexityPerplexityStable DiffusionStable Diffusion
    DeepSeekDeepSeekCoPilotCoPilotMidjourneyMidjourney
    View All Directories
    OverviewPromptsBlogVideosGuidesCoursesCommunityModelsLoRAsComfyUI WorkflowsTrending
    Stable DiffusionBlogMy 14-Year Journey Away from ORMs - How I Built pGenie, the SQL-First Postgres Code Generator
    Back to Blog
    My 14-Year Journey Away from ORMs - How I Built pGenie, the SQL-First Postgres Code Generator
    postgres

    My 14-Year Journey Away from ORMs - How I Built pGenie, the SQL-First Postgres Code Generator

    Nikita Volkov April 14, 2026
    0 views

    Story about how I went from shipping a popular ORM in 2012… to throwing it all away… to realizing that the database itself should be the single source of truth.


    title: My 14-Year Journey Away from ORMs - How I Built pGenie, the SQL-First Postgres Code Generator description: Story about how I went from shipping a popular ORM in 2012… to throwing it all away… to realizing that the database itself should be the single source of truth. canonical_url: https://nikita-volkov.github.io/pgenie-in-production-part-1/

    Hi, I'm Nikita Volkov - architect, consultant, and the author of hasql, one of the two main PostgreSQL drivers in Haskell used in major production projects like PostgREST and IHP. After 25 years in IT and more late-night schema-drift fires than I care to count, I open-sourced something I wish had existed a decade ago: pGenie.

    Following is the story of how I went from shipping a popular ORM in 2012... to throwing it all away... to realizing that the database itself should be the single source of truth.

    2012: I Built an ORM

    Back then I was a typical web developer of the time. CRUD was all we needed. Performance problems were for "later". Deployments were ssh + git pull. Migrations were non-existent.

    So I wrote SORM - an ORM framework for Scala - and open-sourced it. Instead of treating objects as mutable views of the database, it exchanged them as immutable values with the db. It felt novel. It gained traction. For a while it felt like success.

    Then reality hit.

    • Every non-trivial query exposed the limits of the DSL.
    • Keeping the code model in sync with the real database schema became an endless source of headaches.
    • I was essentially inventing a worse version of SQL just to make the integration "safer".

    In 2014 I stopped development. In 2016 I killed support. Lesson learned: abstracting over SQL is usually a mistake.

    Insight #1: Instead of replacing SQL - we should make integration with it better

    Instead of building another layer on top, I decided to make the integration with raw SQL as safe and convenient as possible.

    That led to hasql in 2014 - a driver that embraced raw SQL and gave composable abstractions supporting it. It's one of the two main Postgres drivers in the Haskell ecosystem today and the most efficient one.

    With this library I found the perfect integration point.

    Insight #2: The Query is the Optimal Integration Point

    Not the business logic model. Not the table row structure. The query itself.

    The query determines the structure of parameters it needs and what it returns. The types that represent those parameters and results are just that - parameters and results of that particular query. They are not your table rows, they are not your business models. However similar they may look, they are not the same thing and they will evolve independently and become different given enough time.

    Similar ≠ same, looks ≠ identity.

    Reusing row types across queries creates hidden dependencies and plants future failures: change one query and another silently fails. Attaching domain models to database entities escalates this problem to other application layers. Coupling to API types is just a recipe to get either an API violation or a database integration bug.

    That perspective made a solid foundation, but something was still missing.

    The user had to accompany every query with hand-rolled codecs and the SQL string was lacking any validation. So in 2019 I shipped hasql-th - a compile-time SQL syntax checking library based on a port of the PostgreSQL parser. It made things simpler and safer, but still not enough. We needed the queries validated against the actual schema.

    I saw projects pop up over the years that tried to solve this problem by introducing a compile-time connection to the database. But that always felt like a hack that made builds unreproducible. I was looking for a solution that could be contained in code in a repository without infrastructure dependencies, and eventually it came in the form of the following insight.

    Insight #3: Migrations + Queries = Database API

    Here's the mental model that changed everything for me:

    If you treat your Postgres server like a microservice, then by the analogy of REST APIs:

    • Migrations = the contract (like OpenAPI schemas)
    • Queries = the operations (like OpenAPI endpoints)

    Your application is just a client of that API. The database is primary. The application code is secondary.

    This is the essence of the DB-First (or SQL-First) approach.

    Suddenly everything clicked. The schema lives in SQL migrations. The queries live in .sql files. All of that gets checked into a repository and becomes a subject to development, testing and review. Everything else - types, encoders, decoders, index recommendations - can be automatically derived and safely integrated into codebases with the help of type-checking compilers.

    2022–2026: From Closed SaaS Experiment to Open Source

    I first released pGenie as SaaS in 2022. Companies didn't like sending their schemas and queries to a third party. Fair enough.

    So in 2026 I open-sourced it completely and switched to the OSS+Consulting business model:

    github.com/pgenie-io/pgenie

    It's a simple CLI. You point it at your migrations/ and queries/ folders. It spins up a real PostgreSQL container, recreates the schema by running migrations, prepares queries, analyses the information schema, and generates a type-safe client code for various targets via plugins. Currently Haskell, Rust and Java are fully supported as such plugins.

    What pGenie Actually Gives You

    • Zero boilerplate type-safe SDKs
    • Fidelity to advanced Postgres features (JSONB, arrays, composites, multiranges, extensions, etc.) and queries of any complexity
    • Decentralized code generators written in safe, reproducible Dhall
    • Signature files that catch schema drift at build time
    • Automatic index recommendations and sequential-scan warnings

    The full side-by-side of source SQL and the generated client code for Haskell, Rust and Java is in the demo repo.

    How this fits in the AI Era

    LLMs are great at writing SQL. They are not that great at ensuring it still works after your next migration.

    pGenie closes that gap: AI writes the query, pGenie deterministically verifies it against the real schema, you get a predictably structured type-safe SDK in seconds.

    SQL-First + AI = maximum velocity with zero surprises.


    • Learn pGenie in Y minutes: pgenie.io/docs/tutorials/learn-pgenie-in-y-minutes

    • Ask questions and share ideas: github.com/pgenie-io/pgenie/discussions

    • Give it a star on GitHub: github.com/pgenie-io/pgenie

    Tags

    postgresjavarusthaskell

    Comments

    More Blog

    View all
    Context bankruptcy: The case for strategic forgetting for AI Agentsai

    Context bankruptcy: The case for strategic forgetting for AI Agents

    Most of us have seen a coding agent fail to complete a task we know it can do. We just don't...

    J
    James O'Reilly
    Parallel Compliance Engine: Drive-to-Sheets Multi-Agent Orchestrationgooglecloud

    Parallel Compliance Engine: Drive-to-Sheets Multi-Agent Orchestration

    When building Generative AI applications, developers often encounter a massive bottleneck: sequential...

    A
    Aryan Irani
    Is It Ethical to Post and Ask About Circuits on Dev.to?discuss

    Is It Ethical to Post and Ask About Circuits on Dev.to?

    I’ve been thinking about sharing some electronic circuit posts on Dev.to — small circuits, DIY...

    C
    codebunny20
    The One-Click Exporter: AI Studio Antigravity, Probed to Its Limitsagents

    The One-Click Exporter: AI Studio Antigravity, Probed to Its Limits

    What nobody tells you about exporting your multi-agent prototype to a local workspace. Every...

    L
    leslysandra
    Guarding the till while autonomous data agents do the diggingagenticarchitect

    Guarding the till while autonomous data agents do the digging

    Autonomous agents are genuinely good at answering messy business questions. Give one an LLM and a set...

    S
    Sireesha Pulipati
    Return on Attention: Why AI Code Reviews Are Wearing Us Outai

    Return on Attention: Why AI Code Reviews Are Wearing Us Out

    PR volume went up, ticket quality didn't, and the gap got filled with LLMs on both sides of the review: bots reviewing, bots replying, bots occasionally arguing with bots about priorities that only existed in a teammate's head. Our CEO named the actual problem, and it's bigger than code review.

    C
    christine

    Stay up to date

    Get the latest Stable Diffusion prompts, rules, and resources delivered to your inbox weekly.

    Neura Market LogoNeura Market

    Discover the best AI prompts, plugins, and resources for Stable Diffusion and more.

    Content Types

    • Rules
    • Prompts
    • MCPs
    • Agents
    • Guides

    Platforms

    • ChatGPT Directory
    • Claude Directory
    • Gemini Directory
    • Cursor Directory
    • Grok Directory
    • Perplexity Directory
    • DeepSeek Directory
    • CoPilot Directory
    • Stable Diffusion Directory
    • Midjourney Directory
    • All Directories

    Resources

    • Blog
    • Documentation
    • Help Center
    • Marketplace

    Legal

    • Privacy Policy
    • Terms of Service

    © 2026 Neura Market. All rights reserved.

    |

    Not affiliated with any AI platform vendors.

    Ready-made automations for this

    Workflows from the Neura Market marketplace related to this Stable Diffusion resource

    • Twitch Auto-Clip-Generator: Fetch from Streamers, Clip & Edit on Autopilotn8n · Free · Related topic
    • Automated FAQ Generator from WhatsApp Groups Using GPT-4 and Google Docsn8n · Free · Related topic
    • Bright Data-Powered Competitive Price Lookup and Report Generatorn8n · Free · Related topic
    • AI-Powered Upwork Cover Letter Generator - Pinecone, Groq, Google Gemini, SerpAPIn8n · Free · Related topic
    Browse all workflows