四好公路
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

37 lines
818 B

/**
* Created by rain on 2015/11/11.
*/
/**
* Use orm - sequelize
* will be replace by dc implements.
*/
"use strict";
const compose = require('koa-compose');
const Sequelize = require('sequelize');
module.exports = function (app, config) {
//load orm when start.
//so insert model when start.
let orm = new Sequelize(config.url, config.opts);
let dc = {};
dc.orm = orm;
dc.ORM = Sequelize;
dc.models = {};
//export dc to app global;
app.fs = app.fs || {};
app.fs.dc = dc;
if (Array.isArray(config.models)) {
config.models.forEach(function (e) {
//is function?
e(dc);
});
}
return function *(ctx, next) {
//wrap orm and ORM
ctx.fs = ctx.fs || {};
ctx.fs.dc = dc;
yield next();
};
};