Disclaimer: If you have preconceived notions about using “stored procedures” a lot (personally, I just call them “routines”, like Postgres does), then you probably won’t like what I’m going to show you, And I’m not going to try to convince you.
I’m the creator of pg-nano. It’s not an ORM, a query builder or a basic query driver, but it’s the closest to the last. The difference is that it is also a migration tool and code generator. It’s not ready for production yet (more on that below).
link: https://github.com/pg-nano/pg-nano/
It produces TypeScript bindings for your native Postgres routines (think CREATE FUNCTION
or CREATE PROCEDURE
please excuse the capitalization). For views (such as CREATE VIEW), pg-nano can infer the “nullability” of each column through static analysis. I plan to extend this inference to user-defined routines in the near future, but the generated types are already pretty good.
From a TypeScript application server, you can call Postgres routines with 100% type safety. The query driver uses libpq (the official C driver) under the hood. I have implemented a connection pool, automatic reconnection with exponential backoff, and query streaming on top of libpq.
it scans directories .sql
file and instantly updates the local database instance by comparing the current schema with the required schema. It only deletes material when absolutely necessary. Please note that I haven’t implemented production migration yet, this is of course just to be on the safe side.
I use a combination of static analysis (parsing SQL) and introspection (querying Postgres system tables) at compile time to generate TypeScript bindings and migration plans.
Link again: https://github.com/pg-nano/pg-nano/
I’m posting all of these to get your feedback:
- Can you imagine yourself using pg-nano? Why or why not?
- Is there a specific feature you’d like to see, or do you have any concerns?
I could really use some testers, but even your ideas would be of great help.
I still have a few things to do to get pg-nano ready for production.
Database seeding
Migration in production
trade