Pa

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

Hacker News

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 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)

Share card

Actual performance

116points
21comments
Made the leaderboard

Launch Intel predictions

Analyze your own launch →
Indie HackersFits the IH revenue-focused audience · Missing: supports, reddit linkedin, podcasting
80%80% predicted probability of success on Indie Hackers, based on ML models trained on real launch data.
best fitHighest predicted score across all platforms for this description.
Product HuntOn track for Day 1 leaderboard · Strong signals: using · Missing: mac, agents, macos
80%80% predicted probability of success on Product Hunt, based on ML models trained on real launch data.
Hacker NewsStrong engagement from HN community · Strong signals: ide, io · Missing: https docs, excited, just released
52%52% predicted probability of success on Hacker News, based on ML models trained on real launch data.
nativeThis product was originally launched on this platform.
AppSumoMay struggle as an AppSumo deal · Missing: plus, platform, intuitive
41%41% predicted probability of success on AppSumo, based on ML models trained on real launch data.
TrustMRRLess likely to generate early MRR · Strong signals: way · Missing: mobile apps, ios, personal
40%40% predicted probability of success on TrustMRR, based on ML models trained on real launch data.
Acquire.comPre-revenue stage for this audience · Missing: arr, mrr, revenue
12%12% predicted probability of success on Acquire.com, based on ML models trained on real launch data.
BetaListMay not resonate with beta-testers · Missing: web3, chat, crypto
0%0% predicted probability of success on BetaList, based on ML models trained on real launch data.

Correct prediction on native model

Similar products

Ty
Typed Postgres CRUD Queries71%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Typed Postgres CRUD Queries

Hacker News29
Mo
Mostly ORMless – Ergonomic Postgres from TypeScript62%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Mostly ORMless – Ergonomic Postgres from TypeScript

Hacker News2
Mo
Mostly ORMless – Ergonomic Postgres from TypeScript62%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Mostly ORMless – Ergonomic Postgres from TypeScript

Hacker News14
Ta
Tablespace – Postgres columnstore indexes for faster OLAP queries73%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Tablespace – Postgres columnstore indexes for faster OLAP queries

Hacker News2
Pg
Pg_analytics – Speed Up Postgres Analytical Queries by 94x63%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Pg_analytics – Speed Up Postgres Analytical Queries by 94x

Hacker News8
Za
Zapatos, a Postgres Library for TypeScript62%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Zapatos, a Postgres Library for TypeScript

Hacker News28
Pg
PgTyped – Typesafe SQL in TypeScript and Postgres70%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

PgTyped – Typesafe SQL in TypeScript and Postgres

Hacker News269
NebulaDB
NebulaDB63%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

TypeScript-first embedded database with reactive queries

Product Hunt+9
DB
DBOS TypeScript – Lightweight Durable Execution Built on Postgres64%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

DBOS TypeScript – Lightweight Durable Execution Built on Postgres

Hacker News77
No
Now supporting MySQL, Postgres, Redis, Mongo60%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Now supporting MySQL, Postgres, Redis, Mongo

Hacker News3