Query returning array instead an object

Hey there.
I need to return theses datas as object to use toJSON() to format my datas.
Why this query is return array instead object?

My query
image

result
image

this way i cant use toJSON() method if implement the following code:
image

i got the error
image

same to:

return view.render('ordensdeservico', {
title: 'Ordens de Serviços',
ordens: ordens[0].toJSON()
})

toJSON is a Lucid method. You just selecting data from db. So all you need to return a single row as an object is just to add .first() to your query

Like this:

const obj = await Database.select(...).from(...).first();
3 Likes

Wow. Nice.
Thank you very much :slight_smile: