Live data from Hacker News

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

github.com

1–10 of 19 posts

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

#2
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.

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

#4
post #3

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.

The template tag solution is cute but dangerous if you can accidentally leave off the `SQL` tag and the query still works.

Ideally the system would require you to use the tag and prohibit a plain ol string.

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

#6
post #3

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.

The template tag solution is cute but dangerous if you can accidentally leave off the `SQL` tag and the query still works. Ideally the system would require you to use the tag and prohibit a plain ol string.

It does require you to use the tag.

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

#7
post #3

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.

The template tag solution is cute but dangerous if you can accidentally leave off the `SQL` tag and the query still works. Ideally the system would require you to use the tag and prohibit a plain ol string.

TypeScript compiler will error on this.

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

#8

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 nice…

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.

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

#9
post #3

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.

Any reason you chose that over node-sql-template-strings [1], which looks very similar?

[1] https://github.com/felixfbecker/node-sql-template-strings

Post reply on HN