voxpelli/node-connect-pg-simple

Options in constructor seem to be ignored

comatory opened this issue · 1 comments

I am trying to use pg's Pool instance and pass it to the constructor. However I'm getting an error message:

Failed to prune sessions: database "username" does not exist

The way I construct the pool is this:

const { Pool } = require('pg')

const pool = new Pool({
  host: pgConfig.host,
  user: pgConfig.username,
  database: pgConfig.database,
  port: pgConfig.port,
  password: null,
  max: 20,
  idleTimeoutMillis: 30000,
  connectionTimeoutMillis: 2000,
})

I am using express-session package so in my Express app I create session instance like this:

const session = require('express-session')
const pgSession = require('connect-pg-simple')(session)

app.use(session({
  name: 'my-app-name',
  store: new pgSession({
    pgPool: pool,
    tableName: 'Sessions',
  }),
  key: 'user_sid',
  secret: 'somerandonstuffs',
  resave: false,
  cookie: { maxAge: 30 * 24 * 60 * 60 * 1000 },
  httpOnly: true,
  saveUninitialized: true,
}))

I think the pg part works correctly because when I try to run pool.query and read the data from that database, I get the results.

Its somehow trying to default to my user account's database (which I have not created because why?)

The option is named pool, not pgPool 😊 Changing it to that should make it work, right?