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.

Slonik: A PostgreSQL client with strict types, detailed logging, and assertions

60 pointsby sarahdellysseabout 4 years ago

8 comments

chmod775about 4 years ago
I like the idea and project goals.<p>There are however gems like this in the source:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;gajus&#x2F;slonik&#x2F;blob&#x2F;master&#x2F;src&#x2F;routines&#x2F;executeQuery.ts#L220" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;gajus&#x2F;slonik&#x2F;blob&#x2F;master&#x2F;src&#x2F;routines&#x2F;exe...</a><p>You can spend an hour trying to reason about the control flow of that triple try&#x2F;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> &#x2F;* * 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. *&#x2F; </code></pre> To untangle that mess you&#x27;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.
评论 #26419615 未加载
评论 #26419143 未加载
hermanradtkeabout 4 years ago
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:&#x2F;&#x2F;github.com&#x2F;brianc&#x2F;node-postgres" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;brianc&#x2F;node-postgres</a>. One gets all the benefit of node-pg with the nicer dev experience of slonik.
评论 #26418566 未加载
joshxyzabout 4 years ago
Anyone know how this compares to porsager&#x27;s &quot;postgres&quot; lib?<p><a href="https:&#x2F;&#x2F;github.com&#x2F;porsager&#x2F;postgres" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;porsager&#x2F;postgres</a>
hardwaresoftonabout 4 years ago
Have to say I&#x27;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&#x2F;work arounds, but TypeORM also lets you drop to raw (but parametrized) SQL fairly quickly, and it&#x27;s query builder is actually pretty good...<p>[0]: <a href="https:&#x2F;&#x2F;typeorm.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;typeorm.io&#x2F;</a>
janpotabout 4 years ago
Last few years I&#x27;ve been using a similar workflow with something like <a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;pg-template-tag" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;pg-template-tag</a> in combination with `pg`. I&#x27;m never going back to ORMs and query builders.
评论 #26418577 未加载
评论 #26417770 未加载
jeffromabout 4 years ago
Great library, gets out of the way while preventing common mistakes. makes my work easier. Thank you gajus!!!
udevabout 4 years ago
As a memory aid, Slonik means &quot;little elephant&quot; in Russian, and probably other Slavic languages.
评论 #26419568 未加载
iunkabout 4 years ago
I wish it had a standard OSS license
评论 #26419780 未加载