TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Seeking feedback on my Postgres TypeScript thing

4 pointsby aleclarsoniv5 months ago
Hey HN! I&#x27;m the creator of pg-nano. It&#x27;s not an ORM, a query builder, or a basic query driver, but it&#x27;s closest to the last one. The twist is, it&#x27;s also a migration tool <i>and</i> a code generator. It&#x27;s not production-ready yet (more on that below).<p>The link: https:&#x2F;&#x2F;github.com&#x2F;pg-nano&#x2F;pg-nano&#x2F;<p>It generates TypeScript bindings for your native Postgres routines (think `CREATE FUNCTION` or `CREATE PROCEDURE`, sorry for yelling). For views (e.g. CREATE VIEW), pg-nano can infer each column&#x27;s “nullability” via static analysis. I plan to extend that inference to user-defined routines in the near future, but the generated types are already quite good.<p>From your TypeScript application server, you call your Postgres routines with 100% type safety. The query driver uses libpq, the official C driver, under the hood. I&#x27;ve implemented a connection pool, auto-reconnect with exponential backoff, and query streaming on top of libpq.<p>It scans a directory for `.sql` files and instantly updates your local database instance by diffing the current schema with the desired schema. It only drops data if absolutely necessary. Note that I haven&#x27;t implemented production migrations yet, which will of course err on the safe side.<p>I use a combination of static analysis (parsing your SQL) and introspection (querying Postgres system tables) at compile time to both generate the TypeScript bindings and the migration plan.<p>The link again: https:&#x2F;&#x2F;github.com&#x2F;pg-nano&#x2F;pg-nano&#x2F;<p>~~~<p>I posted all this to get your feedback:<p>- Could you see yourself using pg-nano? Why or why not?<p>- Are there specific features you’d like to see, or concerns you have?<p>I could really use some beta testers, but even your thoughts would help a great deal.<p>~~~<p>In order to get pg-nano production ready, I have a few things left to do.<p>1. Database seeding<p>2. Migrations in production<p>3. Transactions

1 comment

gulcin_xata5 months ago
I see you&#x27;re using pg-schema-diff for schema diffing, hadn’t come across it before, so thanks for mentioning it!<p>Have you seen pgroll? <a href="https:&#x2F;&#x2F;github.com&#x2F;xataio&#x2F;pgroll">https:&#x2F;&#x2F;github.com&#x2F;xataio&#x2F;pgroll</a> It is a Postgres schema migration tool for achieving zero downtime, minimal locking schema changes. Thought it might be interesting for you. I also checked the unsupported operations in pg-schema-diff, and from a quick look, pgroll seems to cover more migration types: <a href="https:&#x2F;&#x2F;pgroll.com&#x2F;docs&#x2F;v0.8.0&#x2F;getting-started" rel="nofollow">https:&#x2F;&#x2F;pgroll.com&#x2F;docs&#x2F;v0.8.0&#x2F;getting-started</a>