Description
node-postgres
allows to connect using sockets in a connection string like this:
pg.connect('/some/path', callback)
That is nice, but does not allows to set another database but one with the same user name.
I propose to accept a special protocol named socket
to enable the database selection like this:
pg.connect('socket:/some/path?database', callback)
The url.parse('socket:/some/path?database')
returns:
{ protocol: 'socket:',
host: '',
query: 'database',
pathname: '/some/path',
...}
That data is enough to make the magic, with a small change on function parse
at connection-parameters.js
. (and also my favorite solution)
That can not change the current behavior for sockets when the first char is "/".
I also try a change on current sockets behavior, splitting the string on spaces. That makes easy to set a database by this way:
pg.connect('/some/path database', callback)
pg/lib/connection-parameters.js
*** 14,20 ****
var parse = function(str) {
//unix socket
if(str.charAt(0) === '/') {
- return { host: str };
}
--- 14,21 ----
var parse = function(str) {
//unix socket
if(str.charAt(0) === '/') {
+ var config = str.split(' ');
+ return { host: config[0], database: config[1] };
}
What you think? node-postgres
can use the solution 1, 2, or a mix of both?
I can also code it, if you like.