brianc / node-pg-pool

A connection pool for node-postgres
MIT License
180 stars 64 forks source link

Pool constructor doesn't work with frozen options #4

Closed ikokostya closed 8 years ago

ikokostya commented 8 years ago

Pool constructor changes given options parameter https://github.com/brianc/node-pg-pool/blob/master/index.js#L13-L15 This doesn't work with frozen object. Next program terminates without error:

'use strict';

var Pool = require('pg').Pool;

var config = Object.freeze({
  user: 'foo',
  password: 'secret',
  database: 'my_db',
  port: 5432
});

var pool = new Pool(config);

pool.connect(function(err, client, done) {
  if(err) {
    return console.error('error fetching client from pool', err);
  }
  console.log('done');
});

Also changing user input isn't good practice, because user can use options object later. So, I propose to clone options before adding new properties to it.

brianc commented 8 years ago

+1 nice catch on the frozen object thing. You're also spot on it should be cloned. Wanna put together a PR w/ some tests for that? 😄