Make it possible to load an adapter within a model definition #3

Merged
merged 2 commits into from Oct 7, 2012

Conversation

Projects
None yet
4 participants
Contributor

nlf commented Oct 6, 2012

This patch allows a user to define an adapter more easily, by putting a function in the model definition, i.e.

var model = require('model');

var User = function () {
  this.adapter('riak', { host: 'riakhost' });
}
User = model.register('User', User);

It wraps the getAdapterInfo function to find the path to the individual adapter, requires it, initializes it, and adds it to model.adapters. Additionally, it passes configuration options through to the adapter.

@mde I like this change, it'll allow people to use two separate instances of the same DB on different hosts if they'd like. Might help people vertically shard their databases (unless I'm reading this wrong).

We'll have to see what kind of impact this has on Geddy, and how easy it'll be to change up how models are loaded in, but I don't see this having too deep of repercussions.

What do you think?

mde merged commit 146c9ce into geddy:master Oct 7, 2012

Contributor

mde commented Oct 7, 2012

Merged, thanks!

Contributor

akanieski commented Dec 31, 2013

Is this feature still supported? Doesn't seem to be working for me and I couldn't find the code anymore in lib/index.js

Contributor

mde commented Dec 31, 2013

Looks like this got dropped at some point in favor of setting this.adapter directly to an Adapter instance. I suspect this happened during the push to implement shared tests for all adapters. There is a utility method for getting the Adapter metadata by name (model.getAdapterInfo) so you can instantiate them, but it's not a very nice API. I'll add a setAdapter method on ModelDefinitionBase with the API you followed here.

Contributor

mde commented Dec 31, 2013

Added to master in daf6d78 -- let me know if this works for you.

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