Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Consider Decoupling all but Memory Engine #109

Open
DamonOehlman opened this Issue · 3 comments

2 participants

@DamonOehlman

Hey Guys,

Love the general approach of resourceful, but just wondering why actual storage engines are implemented within the core library? Even though I primarily use CouchDB, it really just does make that much sense (to me) to have a library that handles abstract model definition implement storage adapters within the library itself?

This for me is somewhat reminiscent of earlier versions of winston which included an implementation of the loggly reporter and package dependencies to make it work.

Taking the example in the readme, I'd much rather do something like the following to wire up the storage engine:

var resourceful = require('resourceful'),
    couchStorage = require('resourceful-couchdb');

var Creature = resourceful.define('creature', function () {
  //
  // Specify a storage engine
  //
  this.use(couchStorage);

  //
  // Specify some properties with validation
  //
  this.string('diet');
  this.bool('vertebrate');
  this.array('belly');

  //
  // Specify timestamp properties
  //
  this.timestamps();
});

//
// Now that the `Creature` prototype is defined
// we can add custom logic to be available on all instances
//
Creature.prototype.feed = function (food) {
  this.belly.push(food);
};

You could additionally support your existing implementation by implementing an engine registry within resourceful, so that some initialization code such as below would result in the readme code working as is:

resourceful.engines.register('couchdb', require('resourceful-couchdb'));

I'd certainly be happy to work on this kind of implementation if you felt that it was a direction that you wanted to take resourceful in.

Cheers,
Damon.

@Marak

Yes, that is an artifact from the old design.

We'll be moving towards a broadway based plugin system for resource engines eventually.

No need to build something new. Broadway.use should be able to handle this.

Feel free to start up a fork / pull request.

@Marak

Seems somewhat relevant:

indexzero/broadway#34

@DamonOehlman

Good call on using Broadway, re plugins I've written a small experimental library will comment on indexzero/broadway#34.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.