This infrastructure plugin listens for 'models' field in infrastructure config object.
The field should be object of type {path:"/path", host:'host',port:1234,db:"dbname",options:{...}} The last if for future usage - will be possible to load multiple database/ORM plugins in one application.
Usage: Install: npm install infrastructure-mongoose in app: var infrastructure=require("infrastructure"); var infrastructure_mongoose = require("infrastructure-mongoose");
infrastructure.use(infrastructure_mongoose);
var config = require("./config.js"); //config.models is path to file or directory (all files will be loaded in it)
var app_extensions = {error:function(msg){throw new Error(msg);}};
app.run(config, app_extensions. function(app){
//App.models id object with mongoose model classes
});
Adds app.models as result.
Define schema: module.exports = { Person:{ plugin: require("mongoose-plugin-package") //or plugins:[ require("mongoose-plugin-package"), require("mongoose-plugin-package2"), require("mongoose-plugin-package3") ], //Both - plugin and plugins array members can be object {plugin:require(...), options:{...}} methods:{ method1: function(){...}, method2: function(){...} }, static:{ staticMethod1: function(){} },
field1: "String",
field2: ["Number"],
friends: ["Person"] // Relation
}
};