Live data from Hacker News

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

github.com

51–60 of 87 posts

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

#51

Earlier quoted context omitted.

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

This can’t be overstated. Crossing the JS native barrier is inherently a perf hit. I’ve measured it trying a large variety of high performance messaging protocols and postMessage with structured clone nearly always wins. If that sounds like a bold claim, there are troves of Node and Deno issues where they’ve improved perf by staying in JS specifically because calling into native and back has been the bottleneck. Ther…

I responded to the OP, but I'll add here too for the conversation. Where are these projects that are implementing network protocols, where the nodejs versions are faster than the native ones?

As I noted in my other comment, in -any- of those implementations, you're still going to be required to traverse from libc somewhere to nodejs (even if it's just to read the network data out of the socket and send it to v8). The performance gains would have to either come from a faster (JIT'd) protocol parser, or from eliminating additional FFI calls (that it isn't obvious why they'd exist).

So, would you mind linking to one or some of those projects? I'd love to see what happened to the implementations.

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

#52

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 :)

Manipulating source code via regex... I wonder what could possibly go wrong.

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

#53

I spent some time today trying to replace pg but I ran into an issue. When using an rds proxy with iam authentication, it seems to repeatedly retry authentication and eventually my lambda functions time out. If I switch to using regular credentials it works fine. Using the exact same options with pg+iam authentication also works fine which leads me to believe it's an issue with this project. I'll open an issue on Git…

That's interesting - haven't heard of that issue before, so do please create an issue on github or let me know if you figure it out ;)

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

#54
post #52

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 :)

Manipulating source code via regex... I wonder what could possibly go wrong.

The results are run through the same tests ;)

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

#55
post #51

Earlier quoted context omitted.

This can’t be overstated. Crossing the JS native barrier is inherently a perf hit. I’ve measured it trying a large variety of high performance messaging protocols and postMessage with structured clone nearly always wins. If that sounds like a bold claim, there are troves of Node and Deno issues where they’ve improved perf by staying in JS specifically because calling into native and back has been the bottleneck. Ther…

I responded to the OP, but I'll add here too for the conversation. Where are these projects that are implementing network protocols, where the nodejs versions are faster than the native ones? As I noted in my other comment, in -any- of those implementations, you're still going to be required to traverse from libc somewhere to nodejs (even if it's just to read the network data out of the socket and send it to v8). The…

I think you're right. Here's a project proving the exact opposite of native bindings being slow - https://github.com/uNetworking/uWebSockets.js

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

#56
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…

One question - is there a way to explicitly start the connection, instead of auto connection at the initialization?

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

#57
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…

One question - is there a way to explicitly start the connection, instead of auto connection at the initialization?

Yeah, just make a simple query :)

  await sql`select 1`

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

#58

Earlier quoted context omitted.

One question - is there a way to explicitly start the connection, instead of auto connection at the initialization?

Yeah, just make a simple query :) await sql`select 1`

well.. my bad, somehow I didn't think about that..

anyway this lib looks really cool! definitely will use that instead of hand crafted tagged template functions passed to `pg`.

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

#59
post #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?

Just saw this on the page: >Parameters are automatically extracted and handled by the database so that SQL injection isn't possible. No special handling is necessary, simply use tagged template literals as usual. Dynamic queries and query building can be seen in the next section. // todo

this is great! Can't wait to give a try.

Post reply on HN