我正在使用nodejs创建API. API接受请求并以
JSON响应
例如:
我的数据库中有一个表QUESTION,因此对端点http://localhost/table/question的GET请求将以JSON格式输出表.
但是在执行JOINS时出现问题
考虑表QUESTION和CHOICE.一个问题有很多选择(答案)他们的加入
表:
我想转换成这样的东西
{
"0":{
"QUESTION":"If Size of integer pointer is 4 Bytes what is size of float pointer ?",
"OPTION":{
"A":"3 Bytes",
"B":"32 Bits",
"C":"64 Bits",
"D":"12 Bytes"
}
},
"1":{
"QUESTION":"Which one is not a SFR",
"OPTION":{
"A":"PC",
"B":"R1",
"C":"SBUF"
}
},
"2":{
"QUESTION":"What is Size of DPTR in 8051",
"OPTION":{
"A":"16 Bits",
"B":"8 Bytes",
"C":"8 Bits"
}
},
"3":{
"QUESTION":"Is to_string() is valid builtin function prior to c++11 ? ",
"OPTION":{
"A":"Yes",
"B":"No"
}
}
}
显而易见的解决方案是使用JOIN解析查询并将其转换为JSON.
有没有更有效的方法呢?