brianc / node-postgres

PostgreSQL client for node.js.
https://node-postgres.com
MIT License
12.04k stars 1.21k forks source link

Documentation Contains Incorrect Syntax #3096

Open cantwellsean0127 opened 7 months ago

cantwellsean0127 commented 7 months ago

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.

Standaa commented 7 months ago

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.

briandavidjoyner commented 6 months ago

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

fire332 commented 4 months ago

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.

charmander commented 4 months ago

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

brianc commented 2 months ago

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