-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relational to JSON - How to run two selects? #826
Comments
@naiieandrade wondering whether you're using Tedious and do you have any issue or ambiguity with Tedious driver? 🤔 cause what you have posted seems like a specific SQL question related to project |
@Hadis-Fard Hi, sorry, I'm new with Tedious. I'm using Tedious. I'm doing a project and in shortly time I have to do this. So I'm studying and learning in this short period. I just want to know if I can do two select to return in the same JSON like as the example above. Is my question is clearer now? 😕 |
Hey @Hadis-Fard I got it! I'm sure was not the correct form. How I said, I don't know yet. router.get('/:id', authCheck.ensureLoggedIn(),
function (request, response) {
const personId = request.params.id;
const connection = new tediousConnection(config.db);
let kinds = [];
connection.on('connect', function (err) {
if (err) {
// ....
}
else {
getKinds(personId, connection)
.then(data => {
kinds = data;
const connection1 = new tediousConnection(config.db);
connection1.on('connect', function (err) {
if (err) {
// ...
}
else {
getPersonIdInfo(personId, connection1)
.then(data => response.status(200).json({ person:data, 'kinds':kinds }));
}
});
});
}
});
}); This way I got to do 2 selects and concatenate in the same json. My result was something like this: {
"person": {
"id": 3,
"name": "Mary",
"age": 27,
},
"kinds": {
"kind": [
{
"id": 5
},
{
"id": 2
},
{
"id": 3
}
]
}
} |
I'm using tedious with sql-server, and I have to return a
json
file.The #1 problem I had was because my select was returning 3 rows because was a relation one-to-many tables.
For example:
The select was some like
Was returning 3 rows, but it's was justing showing in Postman the last row because was being replaced.
And I need this return:
To do this, I think I need two selects. One to get id, name, isSenior, commissionPct and another to put in a list for jobHistory.
Do you can help me?
The text was updated successfully, but these errors were encountered: