我必须查询一组我希望嵌套的数据以使其更有意义。当使用 ExpressJS 和 oracledb 框架查询数据时,如下所示,
oracledb.getConnection(getConnectAttr, function(err,connection){
if(err){
res.set('content-type','application/json');
res.status(500).send(JSON.stringify({
status:500,
message:"Error connection to DB",
detailed_message:err.message
}));
return;
}
connection.execute("select * from REGISTRATION_MASTER", {}, {outFormat : oracledb.OBJECT
},function(err, result){
if(err){
res.set('content-type','application/json');
res.status(500).send(JSON.stringify({
status:500,
message:"Error connection the REGISTRATION",
detailed_message:err.message
}));
}
else{
res.contentType('application/json').status(200);
res.send(result.rows);
}
//Release the connection
connection.release(
function(err){
if(err){
console.error(err.message);
}
else{
console.log("GET/comments : connection released")
}
});
});
});
我曾经查询过,查询结果会是这样的,
[
{
"REG_ID": 1,
"REG_TEXT": "User Name",
"REG_VALUE": null,
"REG_IS_REQUIRED": "true",
"REG_TYPE": "text"
},
{
"REG_ID": 2,
"REG_TEXT": "Password",
"REG_VALUE": null,
"REG_IS_REQUIRED": "true",
"REG_TYPE": "password"
},
{
"REG_ID": 3,
"REG_TEXT": "First Name",
"REG_VALUE": null,
"REG_IS_REQUIRED": "true",
"REG_TYPE": "text"
}
]
我实际上需要通过以这样的方式查询来形成一个 json 输出应该像
{
"REG_FIELDS": [{
"REG_ID": 1, "REG_TEXT": "User Name", "REG_VALUE": "", "REG_IS_REQUIRED": "true",
"REG_TYPE": "text"
}, {
"REG_ID": 2, "REG_TEXT": "Password", "REG_VALUE": "",
"REG_IS_REQUIRED": "true", "REG_TYPE": "password"
}, {
"REG_ID": 3, "REG_TEXT": "First Name",
"REG_VALUE": "", "REG_IS_REQUIRED": "true", "REG_TYPE": "text"
}, ],
"MAINHEADING": "CONSUMER SIGNUP",
"SUBHEADER": "ACCOUNT - CONSUMER - SIGN UP",
"IS_ACTIVE": "TRUE"
};
我正在寻找具有嵌套值的此类输出。我的要求是有更多的嵌套值。我正在寻找一个起点。
我还尝试将 ORM 与 ExpressJS 一起使用,但在将 ExpressJS 与 Oracle 一起使用时,每个都有自己的缺点。谢谢。