Hacker News new | ask | show | jobs
by hermanradtke 1928 days 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.

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.

1 comments

Any pitfalls that you encountered?

I'm trying to decide between this, or writing my own helpers around https://github.com/felixfbecker/node-sql-template-strings.

Also, have you found anything the solves typechecking of embedded expressions inside the SQL template?

For example, Webstorm will help you autocomplete your SQL, but you can still type:

   sql`SELECT * FROM foo WHERE barInt = ${bazStr}`

Would be nice to catch that with TypeScript magic rather than at runtime.
slonik has no knowledge of the pg schema, so it cannot help with this.

You may want to look at something like https://github.com/adelsz/pgtyped. The downside is that dynamic queries are more challenging.

We have been looking at moving over to pgtyped, but it will be a hard transition because we do a fair amount of building up queries at runtime.