Open me-ascii opened 11 years ago
Yes, you can see how to bootstrap the Mongo adapter in the Mongo test file:
https://github.com/mde/model/blob/master/test/integration/adapters/mongo/index.js
The tests are all mixed in from the shared file, but the bootstrap happens in the 'before'.
Sorry, but example from the test file uses relative paths within the project:
Adapter = require('../../../../lib/adapters/mongo').Adapter`
How to do that in my application where the model
installed via npm
? For example
var model = require( 'model' ),
Adapter = ??
// may be something like model.adapters.mongo
@me-ascii I got it to work like this. Seems hack-ish, but it's the shortest 'clean' way I found after sifting through the model
code and the node
API.
var model = require('model'),
path = require('path'),
Adapter = require(path.join(path.dirname(require.resolve('model')), 'adapters', 'filesystem')).Adapter,
adapter;
adapter = new Adapter();
var User = function () {
this.adapter = adapter;
this.property('name', 'string');
};
Edit: removed unnecessary "model.adapters.filesystem = adapter;
".
thanks! require.resolve
it's realy good idea :+1:
+1 for require.resolve, that was useful (:
Nicely done.
: ) But it would be great to have access to the Adapter
through the exports
of model
like model.adapters.origin.mongo
or so
You're just wanting to get access to all the different adapter constructors?
We use
model
without Geddy.js Is it possible to load mongodb adapter without requiring like that:Adapter = require('../node_modules/model/lib/adapters/mongo').Adapter
Thank you