Great to see this package here. We have been using slonik for over a year now with few regrets. I am not a fan of query builders. Query builders work for simple inserts or updates. For really complex queries, nothing beats writing SQL inside of the sql template tag.
Another nice thing about slonik is that it is built on top of https://github.com/brianc/node-postgres. One gets all the benefit of node-pg with the nicer dev experience of slonik.
Anyone know how this compares to porsager's "postgres" lib?
Have to say I'm pretty happy with TypeORM[0], this is going to have to be really good to pry that from my hands.
Slonik does have a wonderfully smaller API surface and I sure do like writing SQL manually and getting to take advantage of various lower level benefits (ex. postgres JSON operations) without too much fuss/work arounds, but TypeORM also lets you drop to raw (but parametrized) SQL fairly quickly, and it's query builder is actually pretty good...
[0]: https://typeorm.io/
Last few years I've been using a similar workflow with something like https://www.npmjs.com/package/pg-template-tag in combination with `pg`. I'm never going back to ORMs and query builders.
Great library, gets out of the way while preventing common mistakes. makes my work easier. Thank you gajus!!!
As a memory aid, Slonik means "little elephant" in Russian, and probably other Slavic languages.
I wish it had a standard OSS license
I like the idea and project goals.
There are however gems like this in the source:
https://github.com/gajus/slonik/blob/master/src/routines/exe...
You can spend an hour trying to reason about the control flow of that triple try/catch alone. Bonus points if that function can recursively call itself (not sure what retryTransaction can get up to).
There may be an explanation for this horrifying code, but it should probably be right above in the form of:
To untangle that mess you'd probably have to rewrite it once just to understand it, rewrite it again to get it right, then spend a month getting the edge-cases right.But at least afterwards a newcomer can fix a bug without endangering the multiverse.