Alright. Can anyone help me with a question of Angular, or API with Node.js?
I have a mysql api with Node.js with inner join in 2 tables, but of course mysql returns everything in a single array, but I think it is more correct and feasible to return the arrays in level.
Example returning mysql direct results:
[
{
coluna1: 'AAAAA',
coluna2: 'XXXXX'
},{
coluna1: 'AAAAA',
coluna2: 'YYYYY'
},{
coluna1: 'BBBBB',
coluna2: 'ZZZZZ'
},
]
What I want is to turn it into this:
[
{
coluna1: 'AAAAA',
outra_arary: [
{
coluna2: 'XXXXX'
},{
coluna2: 'YYYYY'
}
]
},{
coluna1: 'BBBBB',
outra_arary: [
{
coluna2: 'ZZZZZ'
}
]
}
]
An example of how the method is:
router.get('/', (req, res, next) => {
res.locals.connection.query('select *
from tabela1
inner join tabela2
on tabela1.id = tabela2.id;', (error, results, fields) => {
if (error) {
res.send({
"status" : 500,
"error" : error,
"response" : null
});
} else {
res.send({
"status" : 200,
"error" : null,
"response" : results
});
}
});
});