0
I am using the Knex to make a query that united several tables from a bank Sqlserver (use two version of Sqlserver 9.0.3042 and 12.0.5000.0), example:
knex('tabelaA')
.join('tabelaB', 'tabelaB.idTabelaA', '=', 'tabelA.id')
.select([
'tabelaA.coluna1',
'tabelaA.coluna2',
['tabelaB.coluna1', 'tabelaB.coluna2']
])
.groupBy('tabelaA.coluna1', 'tabelaA.coluna2')
I need the result of each JOIN to come as an array in JSON, example:
[{
tabelaAColuna1: 'Texto',
tabelaAcoluna2: 'Texto',
tabelaB: [
{
tabelaBColua1: 'Texto',
tabelaBColuna2: 'Texto'
},
{
tabelaBColua1: 'Texto',
tabelaBColuna2: 'Texto'
}
]
}]
In Postgresql I saw an example using ARRAY_AGG, but this function does not exist in Sqlserver.
knex.raw('ARRAY_AGG(tabelaB.coluna1) as tabelaBColua1')
How this should be done in the Knex using the Sqlserver?