Skip to content

Instantly share code, notes, and snippets.

@aarosil
Last active August 29, 2015 14:15
Show Gist options
  • Save aarosil/168b5149118247b494a4 to your computer and use it in GitHub Desktop.
Save aarosil/168b5149118247b494a4 to your computer and use it in GitHub Desktop.
var mongoose = require('mongoose')
, testClient = require('api_client') // npm link'd
;
mongoose.connect('localhost', 'delete-me');
testClient.getItems({name: 'foo'})
.then(function(){
console.log(item);
});
/* export a function that accepts mongoose conx
and use it to initialize the module
*/
exports = module.exports = function (mongoose) {
return new FooService(mongoose)
}
// use the mongoose instance to create model
function FooService(mongoose) {
this.model = require('./bar.model.js')(mongoose)
}
FooService.prototype.getItems = function getItems (query) {
return this.model.findAsync(query)
}
var Promise = require('bluebird')
/* export a function which accepts a mongoose instance,
* creates a model on it, and returns the model
*/
exports = module.exports = function genModel(mongoose) {
var BarSchema = new mongoose.Schema({
name: { type: String},
age: { type: Number, default: 0}
})
mongoose.model('Bar', BarSchema)
return Promise.promisifyAll(mongoose.model('Bar'))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment