sqorn/sqorn

A way to use existing node-postgres connection pool

Closed this issue · 2 comments

I'm not sure if that is possible to use existing connection to Postgres server, couldn't find anything about that in Tutorial as it only mentions how to connect to it.
I want to migrate existing application to using this brilliant library, but without a way to use existing connection it would force me either move all application at once, which is not viable or use multiple pg instances with presumably separate pools of clients.

This is on the list of TODOs for the 1.0.0 release (see Projects). I plan to modify Sqorn initialization so that you pass existing adapter and connection objects to it.

This will help with migrating existing apps as you described. It will also allow you to use monkey-patched/customized database adapters.

I haven't ironed out the details completely yet, but it will probably look something like this:

const pg = require('pg')
const sqorn = require('sqorn-pg')

const pool = new pg.Pool()
const sq = sqorn({ pg, pool })

One drawback of this approach is its verbosity. Another is that you must know how to use the underlying database library's adapter. I think its worth the added flexibility. And you probably should know how to work with the underlying adapter anyways.

Implemented in Sqorn Postgres v0.0.36, see the tutorial.