Rename query result columns right after query

On Laravel there’s a thing called “resource” that can translate the entire query result columns and retrieve as it follows:

Query result: result.A_NAME ->
result.CODIGO ->

And goes on.

Is there’s something similar in AdonisJS?

Is it something like automatic mapper that will change query results?

You can create mapper in model as hook, getters and setters, serializer or custom method.

Also to move mapping to database you can use .query().select('username AS name') in queries.

1 Like

Hi. I’v found a package for it:

But I would prefer to do a hook in model. Can you give me a example?

1 Like

You can start from doc:

1 Like