multimeric / koa-pg-session

A model implementation of sessions for koa using postgres as the backend
10 stars 7 forks source link

allow co-pg client pool as connection argument to constructor #1

Closed AprilArcus closed 9 years ago

AprilArcus commented 9 years ago

When using koa-pg-session in conjunction with koa-pg, it can be desirable to share a single co-pg client pool among both sessions table access and generic database queries -- in particular for small setups where the sessions table and other tables are running on the same postgres server. This PR allows a co-pg object to be passed in to the PgSession constructor:

import koa from 'koa';
const app = koa();

import koaPg from 'koa-pg';
app.use(koaPg({
    name: 'db',
    conStr: 'postgres://...'
}));

import genericSession from 'koa-generic-session';
import PgSession from 'koa-pg-session';
app.use(function * (next) {
    const session = genericSession({
        store: new PgSession(this.pg.db)
    })
    yield session.call(this, next);
});
multimeric commented 9 years ago

I'm not able to test the code at the moment, but from what I can see it makes sense.

I'll merge it, but do you think you could also write a test for it that ensures a new connection is attempted if you don't pass in one, and not attempted if you do? My current tests are awful but I'd like a test that covers this PR at any rate.