node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

Documentation Contains Incorrect Syntax

Open cantwellsean0127 opened this issue 2 years ago • 5 comments

Documentation states you can import the Pool class using import { Pool } from 'pg'. However, this is wrong. As of now, you must use import pg from 'pg' and then const { Pool } = pg.

cantwellsean0127 avatar Nov 09 '23 21:11 cantwellsean0127

I second that. There is a node-postgres lib, a pg lib and then extra packages (e.g pg-pool). It is quite confusing which dependencies to use when reading the docs. It would be nice if these were a bit more specific and mentionned typings as well. It would also mitigate risk of installing wrong libs.

Standaa avatar Nov 27 '23 11:11 Standaa

agree. glad i found this. i was banging my head against the wall getting started!

briandavidjoyner avatar Dec 21 '23 20:12 briandavidjoyner

Why does node-postgres even export a class instance instead of just using module-scoped variables to store state? Module exports are basically singletons anyways so that seems redundant at best.

fire332 avatar Feb 28 '24 04:02 fire332

@fire332 It was just a way to write the abstraction over pg/pg-native, as far as I know. It didn’t really make a difference how it was implemented before ESM became a thing, and it hasn’t been changed yet now that it is.

(Also, storing state at the module level is pretty much always bad, but what pg does isn’t a case of that.)

charmander avatar Mar 03 '24 01:03 charmander

Here's a longer description of the issue and my explanation (excuse) for the confusion. tl;dr - I'll be fixing this within the month.

https://github.com/brianc/node-postgres/issues/3190#issuecomment-2039904263

brianc avatar Apr 05 '24 14:04 brianc