pg-mem icon indicating copy to clipboard operation
pg-mem copied to clipboard

Subtle behavior difference between the node-postgres (pg) adapter and actual node-postgres (pg)

Open jakelowen opened this issue 4 years ago • 1 comments

Not an urgent issue, as the workaround is trivial but I have noticed one subtle difference between the way the pg-mem node-postgres (pg) adapter works compared to the actual node-postgres (pg).

When I write SQL I tend to use the https://github.com/felixfbecker/node-sql-template-strings library as a nice way to construct my queries using tagged template literals. With the normal node-postgres (pg) you can pass the SQL`` function directly to query like:

pg.query(SQL`SELECT author FROM books WHERE name = ${book} AND author = ${author}`)

And the real node-postgres library will (somehow) automatically split the query text from the values.

with pg-mems adapter you have to be more explicit like:

const q = SQL`SELECT author FROM books WHERE name = ${book} AND author = ${author}`
const { rows } = await db.client.query(q.text, q.values);

Not a big deal as the benefits of pg-mem make it more than worth it to make this small adaptation, but if you are working for exact parity between the adapter and the actual library, this behavior is one for the todo list.

Thanks for a kick ass project. Loving pg-mem.

jakelowen avatar Sep 25 '21 00:09 jakelowen

Nice catch ! Thanks for the feedback, and for the kind words :)

Note to myself: here is how pg seems to normalize input (called here).

Will fix when I have a bit of time :)

oguimbal avatar Sep 25 '21 09:09 oguimbal