Live data from Hacker News

Show HN: Postgres.js – Fastest Full-Featured PostgreSQL Client for Node and Deno

github.com

41–50 of 87 posts

Re: Show HN: Postgres.js – Fastest Full-Featured PostgreSQL Client for Node and Deno

#41
This looks really nice.

The template strings and querying work somewhat similarly to my own library, Zapatos[1] (but that sits on top of the pg package and is TypeScript-specific, being more focused on having everything typed).

[1] https://jawj.github.io/zapatos/

Re: Show HN: Postgres.js – Fastest Full-Featured PostgreSQL Client for Node and Deno

#42

``` 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.

great to use template lilerals, but any way to use in perpare statement in order to escape sql injection etc type of stuff?

Re: Show HN: Postgres.js – Fastest Full-Featured PostgreSQL Client for Node and Deno

#43

Here is the bundlephobia of this: https://bundlephobia.com/package/postgres@3.0.0 33.6 kB Minified 12.5 kB Minified + Gzipped

Hey - that's pretty nice :) Didn't think of trying that - curious if it includes the cjs and esm version in the sum, since that's double of almost identical code.

Oh you think it should be just ~ 6kB min.gz? I think the site looks for `package.json` and find es6 style entrypoint. It should only build from a single entry.

---

EDIT: according to https://github.com/pastelsky/bundlephobia/discussions/546 they say it looks for `main` entry.

Re: Show HN: Postgres.js – Fastest Full-Featured PostgreSQL Client for Node and Deno

#44
post #2

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

Super cool, looks great. Interesting to see you built it with Typescript. I was wondering-- and I know this is a long story, but I am curious: How does one go about building a PostgreSQL driver for NodeJS in Typescript? How do you design and begin that sort of thing? What sort of knowledge resources did you rely on (i.e. documentation, other references)? I googled 'database driver' to get a definition: "A database dr…

Thanks a lot.

I did not built it with Typescript, just plain js - I don't use Typescript at all(not my cup of tee), but a kind soul (thanks @minigugus) contributed the typings ;)

I actually began it out of curiosity and because I was missing features in the current options. I had been using a wrapper around pg-promise to give me the API i wanted for quite a while, and one day when going through the PostgreSQL documentation I landed on the protocol (https://www.postgresql.org/docs/current/protocol.html) pages. Now the PostgreSQL documentation might seem daunting at first, but once you figure out the structure and semantics it's such an insanely good resource. I had the first POC version working over a weekend, and from there it was about 80% of the way to support all the things I needed. Now the Postgres protocol is actually fairly simple, and I suppose that's why other databases have chosen to use it as well (eg. Postgres.js also works with cockroachdb). I would love to write a longer post about the progress at some point, but I haven't found the time for it yet.

Re: Show HN: Postgres.js – Fastest Full-Featured PostgreSQL Client for Node and Deno

#45

Earlier quoted context omitted.

Super cool, looks great. Interesting to see you built it with Typescript. I was wondering-- and I know this is a long story, but I am curious: How does one go about building a PostgreSQL driver for NodeJS in Typescript? How do you design and begin that sort of thing? What sort of knowledge resources did you rely on (i.e. documentation, other references)? I googled 'database driver' to get a definition: "A database dr…

Thanks a lot. I did not built it with Typescript, just plain js - I don't use Typescript at all(not my cup of tee), but a kind soul (thanks @minigugus) contributed the typings ;) I actually began it out of curiosity and because I was missing features in the current options. I had been using a wrapper around pg-promise to give me the API i wanted for quite a while, and one day when going through the PostgreSQL documen…

Hey.

Love this lib. I am curious why you decided against using TS here? You mentioned it's not your cup of tea.

Re: Show HN: Postgres.js – Fastest Full-Featured PostgreSQL Client for Node and Deno

#46

I’m curious, how does this project compare to slonik that is also a fast, lightweight, full featured, using SQL template literals etc ? Is there any reason to consider switching, for example?

There is quite a big difference, but I'll highlight some of the main points here. Note I'm the author of Postgres.js so I'm obviously biased. Slonik is a wrapper around another node driver (pg), so it's performance is the same as that, where Postgres.js is significantly faster (2-5x)[1]. Postgres.js is also a zero dependency module, whereas Slonik has quite the dependency graph meaning - compare https://npmgraph.js.o…

> Postgres.js is also a zero dependency module, whereas Slonik has quite the dependency graph meaning - compare https://npmgraph.js.org/?q=slonik with https://npmgraph.js.org/?q=postgres.

This one just made my day. Thanks. I remember trying to build a tool at work with as little as possible dependencies (in python) and how satisfying it was to see quite a few dependencies just being wrappers replaces with 5 lines of my own code that i could easily audit and ensure no supply chain attack was possible for that functionality.

Re: Show HN: Postgres.js – Fastest Full-Featured PostgreSQL Client for Node and Deno

#47
post #4

Earlier quoted context omitted.

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?

yes, we use `pg` in all our Node servers (and no realtime)

Alright. I've got a pg wrapper lying around that can help with migration I can send you ;) I've DM'ed you on twitter, so let me know if that could be useful.

Re: Show HN: Postgres.js – Fastest Full-Featured PostgreSQL Client for Node and Deno

#48

Very interesting project! The source is inspiring, it seems the author has made an explicit choice to minimize dependencies. Even transpilation from ES modules into commonjs is done by the author himself: https://github.com/porsager/postgres/blob/master/transpile.c... I’m not sure if I’d made the same choice, but it’s fun the see it can work out great :)

Tbh I think this is quite risky to mess it up. Using a simple regex to convert…

https://github.com/porsager/postgres/blob/master/transpile.c...

Re: Show HN: Postgres.js – Fastest Full-Featured PostgreSQL Client for Node and Deno

#49
post #21

How can this be so much faster than even pg-native that uses the C library libpq? https://github.com/porsager/postgres-benchmarks#results

> How can this be so much faster than even pg-native that uses the C library libpq? the c++ to javascript membrane in v8 is expensive to pass. there are many projects that are faster implementing protocols in javascript vs c/c++ because of this. redis is another.

On the surface I'm not sure this explanation passes the smell test. Almost irrespective of how you get the data from your network card into v8 / nodejs, you're going to be crossing c++/v8 boundaries. It's possible that a native binding goes through this expense multiple times, but that's not likely now most of these bindings work (pg at least for sure).

As the author noted elsewhere in thread, the performance gains are mostly coming from prepared statements and pipelining which seems a bit of an apples to oranges benchmark as most of these native drivers will support similar features, just not enable them transparently like this library does.

Out of curiosity, do you have links to these other projects where they have similar benchmarking attempts/results?

Re: Show HN: Postgres.js – Fastest Full-Featured PostgreSQL Client for Node and Deno

#50
post #27

Thanks porsager. Any plans for Knex support?

Yeah, I think it could make sense for performance reasons to make a version for Knex, but since I try to stay away from ORMs as much as possible I'm probably not the right one to make it ;) I also wouldn't put it in the core library anyway, so it should be straight forward for someone else to make a knex-postgres package that does this?

Knex is a query builder, not an ORM :) Would love to replace pg with your library for the performance gains!
Post reply on HN