Open cantwellsean0127 opened 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.
agree. glad i found this. i was banging my head against the wall getting started!
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 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.)
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
Documentation states you can import the Pool class using
import { Pool } from 'pg'
. However, this is wrong. As of now, you must useimport pg from 'pg'
and thenconst { Pool } = pg
.