私のapp.jsで
question = require('./routes/question_api'),
app.use(orm.express("mysql://root@127.0.0.1/daat", {
define: function (db, models, next) {
var question_model = db.define('questions', {
id : Number,
..... more definitions
}
});
models.question = question_model;
next();
}
}));
私の question_api.js で
var questions = require('../lib/questions/questions.js');
//NEW Question
//Get Question by ID
//Get Question By Category
exports.list = function(req, res){
res.json(questions.list_top_rates(req, res));
};
私のquestions.jsで
exports.list_top_rates = function(req, res) {
var limit = req.limit || 20;
var final_result = {"1": {}};
//Z means descending
req.models.question.find({}, limit, ["rating", "Z"], function(err, questions) {
final_result = questions;
return final_result[0];
});
return final_result;
// return final_result;
// return {
// 1: "first question , limit is " + limit,
// 2: "second question",
// 3: "third question",
// 4: "forth question"
// }
};
空の結果が得られます。question_api.js から直接戻ると動作します。