Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Engine option `uri` key should not be modified. #82

Open
chakrit opened this Issue Jun 17, 2012 · 2 comments

Comments

Projects
None yet
2 participants

chakrit commented Jun 17, 2012

This prevents passing the same option object to this.use('engine', options) call when defining multiple models since the uri key is modified after the first call making it invalid for subsequent calls.

Using the resourceful-redis engine for example but I believe this applies to many other engine implementations as well since the baked-in couchdb engine do this and the README file also use uri as an example.

For example, say I define a model like this:

var r = require('resourceful-redis')
  , opts =
    { uri: 'redis://0.0.0.0:12345/'
    , namespace: 'bugtest' };

var User = r.define('user', function() {
  this.use('redis', opts);
  this.string('username');
  this.string('email');
});

var BlogPost = r.define('post', function() {
  this.use('redis', opts);
  this.string('title');
  this.string('content');
});

Notice the non-standard port part (12345 instead of 6379 for redis.)

It will fail with redis connection error on the this.use line for the BlogPost model since the opts variable has been modified (see this line) with the :12345 stripped from the uri (making it now tries to connect to the default port 6379 instead.)

Of course, I can do a global .use call on the resourceful object directly but that means I can only use one kind of engine for all my models.

@chakrit I changed this in the latest version of resourceful-redis. It's a really easy fix just a use case I'm sure was overlooked, at least in my case.

chakrit commented Aug 7, 2012

@particlebanana cool :) but still, i think this is a resourceful issue instead of resourceful-redis issue in particular.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment