Last active
August 29, 2015 14:15
-
-
Save aarosil/168b5149118247b494a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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