4 ms·
I bit more than a month ago my curiosity got the better of me, and I took a deep dive in the Postgres protocol docs[1]. I was fascinated by it's simplicity, and
by porsager 7y ago
I bit more than a month ago my curiosity got the better of me, and I took a deep dive in the Postgres protocol docs[1]. I was fascinated by it's simplicity, and since I've been wrapping current node modules pg or pg-promise in a tagged template function for easier use, for a long time, I thought it would be interesting to see how it would be to build a client from scratch. The result ended up being a 0 dependency full featured client in 1250 loc, that's somewhere between 2-10x faster than pg (still cleaning up benchmarks to publish).
I also think I've managed to make a welcoming, simple and safe surface API at the same time, so the postgres experience in Node becomes even nicer. Feedback is very much welcomed.
I found a lot of inspiration for tricks to make it faster in other libraries, but the biggest boost came from following the Postgres protocol docs recommendations.
Another thing I've found since becoming a Postgres user is how amazing their documentation is once you wrap your head around it. It took me a while, probably because I've always been used to quickly scanning documentation for the thing I need, instead of actually reading it. That's a foolish thing to do with the Postgres docs. There is so much useful information in there, so now I just read from top to bottom every time I look at a topic.
[1] https://www.postgresql.org/docs/current/protocol.html https://www.postgresql.org/docs/current/protocol.html
- rgharris 7y agoI really like the sql() helpers and the naming of the unsafe() method. The file query helper is great - I've moved to using external query files for everything in a current project. I've used pg-promise a lot and this seems to cover a good bit of the core functionality and could be extended pretty well in a project. Do you plan to continue building out features or are you looking to keep this as lean as possible long term? Also, does sql.file() support named parameters or just indexed parameters (like $1)?
- porsager 7y agoThanks. I'll definitely be open to features that improves daily usage, and features that treats SQL as a first class citizen. It'll never turn into an ORM. So if a feature has great value and it doesn't interfere with the core I'm all ears :) Your example with named parameters in sql files is definitely something I'd like to do, since that's not supported currently. You're very welcome to create an issue for it so we can continue that idea there.
- rgharris 7y agoAwesome, I think your plans on feature development make a lot of sense. Hopefully I’ll have some time to try it out in a real project before long!
- whatl3y 7y agoWhen I came to the comments my first question was going to be how it compares to pg. Thanks for documenting and having benchmarks against it since it has to be close to the current de facto client for Node users.