Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

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

Merged
merged 1 commit into from
Aug 13, 2015

Conversation

AprilArcus
Copy link
Contributor

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
Copy link
Owner

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.

multimeric added a commit that referenced this pull request Aug 13, 2015
allow co-pg client pool as connection argument to constructor
@multimeric multimeric merged commit d922d7d into multimeric:master Aug 13, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants