tgriesser/knex — pull request #390 by bhirt-bpl (2014-07-21 18:08:04+00:00)
Title: fix for using a pgConnectionString

When you connect to postgresql using a connection string, the connectionSettings object of knex is inaccurate and calls like columnInfo() that rely on that information fail.

In the following example you can see the database name binding is undefined:

var knex = require('knex')({
client: 'pg',
connection: "pg://user@localhost/mydb"
});

knex('user').debug().columnInfo().then(function(info) {});

{ __cid: '__cid1',
method: 'columnInfo',
options: undefined,
bindings: [ 'user', undefined ],
sql: 'select * from information_schema.columns where table_name = $1 and table_catalog = $2',
output: [Function] }

The pg module has a connection string parser and it writes through the parsed string to the pg client object connectionParameters. Unfortunately it seems the pg module does not expose this parser, so we have to delay updating the knex.connectionSettings until the the actual database connection is made. I'm going to ask the pg dev if it's possible to get access to the parser. If so, a better place to do this would probably be in the Client_PG function.