[HN Gopher] Show HN: Postgres.js - Fastest Full-Featured Postgre...
___________________________________________________________________
Show HN: Postgres.js - Fastest Full-Featured PostgreSQL Client for
Node and Deno
Author : porsager
Score : 29 points
Date : 2022-03-24 19:30 UTC (3 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| whenlambo wrote:
| This is the example of a great nodejs library. Congrats on v3!
| porsager wrote:
| Hi everyone. A bit more than two years ago I released the first
| version of Postgres.js. A fully featured PostgreSQL driver for
| Node.js written as a learning experience out of curiosity and
| annoyance with the current options. It greatly outperformed the
| alternatives[1] using pipelining and prepared statements, while
| providing a much better development experience safe from SQL
| injections. Since then I've been busy building things using it,
| now running in production, and although quite delayed I'm so
| happy to release a new major today with some really exciting new
| features:
|
| 1. Realtime subscribe to changes through Logical Replication [2]
|
| It's now possible to use logical replication to subscribe in
| realtime to any changes in your database with a simple api like
| `sql.subscribe('insert:events', row => ...)`. Inspired from
| Supabase Realtime you can now have it yourself in Node.
|
| 2. A Safe Dynamic Query Builder
|
| Nesting the sql`` tagged template literal function allows
| building highly dynamic queries while staying safe and using
| parameterized queries at the same time.
|
| 3. Multi-host connection URLs for High Availability support
|
| It's really nice to be able to quickly spin up a High
| Availability Postgres setup using pg_auto_failover[3] and connect
| using Postgres.js with automatic failover and almost 0 downtime.
|
| 4. Deno support
|
| It also works with Deno now, completing all tests except a few
| SSL specific ones which requires fixes in Deno.
|
| 5. And much more
|
| Large object support, efficient connection handling for large
| scale use, cancellation of requests, Typescript suport, async
| cursors.
|
| [1] https://github.com/porsager/postgres-benchmarks#results
|
| [2] https://github.com/porsager/postgres#realtime-subscribe
|
| [3] https://github.com/citusdata/pg_auto_failover
| kiwicopple wrote:
| Congrats on the release - as I mentioned on twitter, your
| templating design is the best DX i've seen for any PG client.
|
| > Inspired from Supabase Realtime you can now have it yourself
| in Node.
|
| Very cool! We have some Node servers internally, I'll see if
| the team want to switch.
| porsager wrote:
| Thanks - that's really nice to hear!
|
| That would be really interesting. Are you using `pg`
| currently, and are you using WebSocket connections in Node to
| Elixir for realtime, or not using realtime in Node?
| kiwicopple wrote:
| yes, we use `pg` in all our Node servers (and no realtime)
| somebee wrote:
| What a coincidence seeing this on HN. Great lib! I actually
| experimented with replacing our use of node-postgres with this
| today. Your lib was the reason I finally got around to shipping
| support for tagged template literals in Imba today
| (https://github.com/imba/imba/commit/ae8c329d1bb72eec6720108d...)
| :) Are you open for a PR exposing the option to return rows as
| arrays? It's pretty crucial for queries joining multiple tables
| with duplicate column names.
| porsager wrote:
| Thanks a lot! What a coincidence - and perfect timing since v3
| supports .raw()[1] to receive results as arrays.
|
| I'd also be very curious to hear how replacing pg goes :)
|
| And also good job on Imba! I'm a really big fan of stripping
| syntax down to the bare essentials, and what you've done with
| Imba is really impressive!
|
| [1] https://github.com/porsager/postgres#raw
| rubyist5eva wrote:
| ``` const users = await sql` select name, age from users where
| age > ${ age } ` ```
|
| Do template literals like this in JS work differently than just
| straight up string interpolation? As a rails dev this set off
| alarm bells.
| porsager wrote:
| Yeah, when a function is called as a "tagged template
| literal"[1] the function takes control over how the parameters
| are handled. Postgres.js uses this to replace the value with
| $1, $2, etc and send over the value as parameters to the
| database, thereby preventing any chance of SQL injection[2].
|
| [1] https://developer.mozilla.org/en-
| US/docs/Web/JavaScript/Refe... [2]
| https://github.com/porsager/postgres#await-sql---result
| throwthere wrote:
| Looks good from what I see. How does this compare with slonik?
| mpfundstein wrote:
| wow i really love this. will try it out tmrw in a new greenfield
| project.
| keb_ wrote:
| Excellent work as usual, Rasmus! :) Loved my time with
| postgres.js in past projects, looking forward to checking out v3
| in an upcoming project of mine. The speed and lack of any
| dependencies, while being so full-featured is really attractive.
___________________________________________________________________
(page generated 2022-03-24 23:01 UTC)