I like the idea and project goals.<p>There are however gems like this in the source:<p><a href="https://github.com/gajus/slonik/blob/master/src/routines/executeQuery.ts#L220" rel="nofollow">https://github.com/gajus/slonik/blob/master/src/routines/exe...</a><p>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).<p>There may be an explanation for this horrifying code, but it should probably be right above in the form of:<p><pre><code> /*
* The following code is not for the weak minded.
*
* Great care needs to be taken with it, for even the smallest mistake
* risks summoning the gods of old to end all life on earth
* in the most terrible way imaginable.
*
* There is however no other way because a, b, and c.
*/
</code></pre>
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.<p>But at least afterwards a newcomer can fix a bug without endangering the multiverse.
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.<p>Another nice thing about slonik is that it is built on top of <a href="https://github.com/brianc/node-postgres" rel="nofollow">https://github.com/brianc/node-postgres</a>. 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?<p><a href="https://github.com/porsager/postgres" rel="nofollow">https://github.com/porsager/postgres</a>
Have to say I'm pretty happy with TypeORM[0], this is going to have to be <i>really</i> good to pry that from my hands.<p>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...<p>[0]: <a href="https://typeorm.io/" rel="nofollow">https://typeorm.io/</a>
Last few years I've been using a similar workflow with something like <a href="https://www.npmjs.com/package/pg-template-tag" rel="nofollow">https://www.npmjs.com/package/pg-template-tag</a> in combination with `pg`. I'm never going back to ORMs and query builders.