Skip to content


Subversion checkout URL

You can clone with
Download ZIP


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

merged 2 commits into from

4 participants

nlf commented

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 mde merged commit 146c9ce into geddy:master
mde commented

Merged, thanks!


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


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.


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
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 0 deletions.
  1. +5 −0 lib/index.js
5 lib/index.js
@@ -751,6 +751,11 @@ model.ModelDefinitionBase = function (name) { = name;
+ this.adapter = function (adapter, config) {
+ var Adapter = require('./adapters/' + adapters.getAdapterInfo(adapter).filePath).Adapter;
+ model.adapters[name] = new Adapter(config);
+ };
+ = function (name, datatype, o) {
reg[].properties[name] =
new model.PropertyDescription(name, datatype, o);
Something went wrong with that request. Please try again.