nowfound

Dev tools · September 18, 2024

PY

Parse your Postgres queries into a fully-typed AST in TypeScript

Hey all, I'm the creator of @pg-nano/pg-parser. I'm using it in pg-nano[1] to statically analyze Postgres schemas spread across multiple SQL files for a couple of reasons: 1. Each CREATE statement needs to be in topological order, so pg-nano's dev command can execute them without issue. 2. pg-nano has a plugin system like Vite that allows SQL generation based on the parsed schema. Probably to the surprise of no one, working with an untyped AST feels like you're back in the days of JavaScript, because well... you are. Most of you know by now just how great TypeScript and static types in…

Visit github.comAlternativestop 25% of September 2024

In plain words

pg-nano/pg-parser converts PostgreSQL queries into a fully-typed Abstract Syntax Tree (AST) for TypeScript developers. It's designed for teams building tools that need to statically analyze Postgres schemas across multiple SQL files, such as enforcing statement ordering or generating SQL through plugins. The tool uses libpg_query to automatically generate comprehensive type definitions, eliminating manual AST typing and keeping pace with PostgreSQL updates.

written from the facts on this page · September 2026

From the sources

In the maker’s words, at launch

Hey all, I'm the creator of @pg-nano/pg-parser. I'm using it in pg-nano[1] to statically analyze Postgres schemas spread across multiple SQL files for a couple of reasons: 1. Each CREATE statement needs to be in topological order, so pg-nano's dev command can execute them without issue. 2. pg-nano has a plugin system like Vite that allows SQL generation based on the parsed schema. Probably to the surprise of no one, working with an untyped AST feels like you're back in the days of JavaScript, because well... you are. Most of you know by now just how great TypeScript and static types in general are, especially if you appreciate SQL. So why is this project worth sharing with you? Well, writing the AST type definitions by hand would have taken me way too much time. It would also be a bear to keep up-to-date as Postgres continues to evolve. To my surprise, I discovered that libpg_query, the C library used under-the-hood, includes JSON definitions in their /srcdata/ folder. I figured I could use them to generate the type definitions. Genius, right? Okay... maybe not genius, but still cool, I think. You see, those JSON definitions provided by libpg_query? They don't exactly contain the TypeScript definitions (was that obvious?). No, no. I had to translate them into TypeScript definitions. (I'm sure you could have done it, yes yes. But did you? No siree bob) It was pain-staking, but overall really not too hard. Time-consuming? Yes, but not as much as writing the type definitions by hand. So... was it worth it? Only time will tell. I hope you find it as useful as I do. And that's all I've got, so thanks for reading. P.S. The build for Windows is broken, so if anyone could lend a hand, you would be a true hero. [1]: https://github.com/pg-nano/pg-nano (not ready for production use)

More dev tools this month

the category →
  • Dograh592

    The open source VAPI alternative

    Dev tools · 25d ago · dograh.com

  • Meridian530

    Don't let your work go unnoticed. Get promoted!

    Dev tools · 20d ago · meridiona.com

  • x1516

    Lovable for iPhone apps go from idea to App Store

    Dev tools · 11d ago · x1.new

  • Open-source GTM skills for technical founders

    Dev tools · 29d ago · gtmcofounder.com

  • OpenTrailPaper is open-source bike computer firmware for the LilyGO T5S3 4.7" E-Paper PRO. It supports offline maps, GPX routes, FIT recording and Bluetooth sensors.

    Dev tools · 1d ago · opentrailpaper.com

  • Nuphos380

    The AI-Native DevOps Workspace.

    Dev tools · 24d ago · nuphos.ai

Launched alongside, September 2024

the whole month →
  • Wispr Flow2,737

    Speak naturally, write perfectly & 3x faster in every app

    AI · 2024 · wisprflow.ai

  • Pathway1,335

    Get user insights 10x faster

    Work · 2024 · wynde.io

  • Personalized AI daily planning that suits your life

    AI · 2024 · beforesunset.ai

  • Osmos1,194

    Match with like-minded professionals for 1:1 conversations

    Growth · 2024

  • Polar1,169

    An open source monetization platform for developers

    Dev tools · 2024 · polar.sh

  • Carrot Care1,167

    Understand & optimise your bloodwork

    Life & fun · 2024 · carrotcare.health