Skip to content

Instantly share code, notes, and snippets.

@mikehostetler
Created June 20, 2014 13:32
Show Gist options
  • Save mikehostetler/6d36dbd4cabb8870adb5 to your computer and use it in GitHub Desktop.
Save mikehostetler/6d36dbd4cabb8870adb5 to your computer and use it in GitHub Desktop.
Sails powered script
var extend = require('util')._extend;
var async = require('async');
var Waterline = require('../node_modules/sails/node_modules/waterline');
var couchdb = require('sails-couchdb-orm');
var config = require('../config/adapters').adapters.couchdb;
couchdb.config = extend(couchdb.defaults, config);
module.exports = bootstrap;
function bootstrap(modelNames, cb) {
async.map(modelNames, bootstrapModel, done);
function done(err, models) {
if (err) return cb(err);
models.forEach(function(model, i) {
var modelName = modelNames[i];
global[modelName] = model;
});
process.nextTick(cb);
}
}
function bootstrapModel(modelName, cb) {
var Model = require('../api/models/' + modelName);
Model.adapter = 'couchdb';
var Model = Waterline.Collection.extend(Model);
var modelConfig = {
adapters: { 'couchdb': couchdb }
};
new Model(modelConfig, cb);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment