我是nodejs
的新手,我有一个数据库名称schooldetail
,我想在我的控制台中仅显示schoolid
和schoolname
,目前我正在获取所有在我的schooldetail database
中。如何使用 res.send 来做到这一点?我以原始json格式获取所有数据吗?
router.get('/childarea', function (req, res, next) {
//var area = req.query.area;
/* this function will get us the areas from the database*/
dbops.getArea(req, function (err, result) {
console.log("error" + err + "result:" + result);
if (result == "1")
res.send({
"Success":done
});
else
res.send("does not exist");
});
});
module.exports.getArea = function (child, callback) {
sql.connect(db_config, function (err) {
if (err) {
console.log(err);
sql.close();
callback(err, null);
} else {
// create Request object
var request = new sql.Request();
/* query to get all details of the area */
var areaQuery = "select * from dbo.tbl_Area";
request.query(areaQuery, function (err, recordset) {
sql.close();
if (err)
console.log(err);
console.log(JSON.stringify(recordset));
});
}
});
};