Change response field names
See original GitHub issueProblem
I’m trying to rename some fields when using select
.
Suggested solution
This is my current query:
const data = await prisma.data_riskscores.findMany({
select: {
id: true,
sections: true,
configuration_country: {
select: {
id: true,
name: true
}
}
}
})
Now I’d like to rename sections
and configuration_country
, because the data should not necessarily reflect the naming scheme of the database (IMO these are very different usecases):
const data = await prisma.data_riskscores.findMany({
select: {
id: true,
results: sections,
configuration_country: {
as: country,
select: {
id: true,
name: true
}
}
}
})
Alternatives
Using @map
resp. rename the relation field. It’s a reasonable alternative, but I think the schema is not the right place to make this change. IMO, the schema should (more or less) reflect the database. Whereas the select
statement should allow to change the response data (because that might differ depending on the context of my request). For now, I’d probably go with a raw query instead.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:74
- Comments:20
Top Results From Across the Web
How to change a field name in JSON using Jackson
If you are using Jackson, then you can use the @JsonProperty annotation to customize the name of a given JSON property. Therefore, you...
Read more >Change Field Name in JSON using Jackson - Java Guides
In this quick tutorial, I show you how to change the name of a field to map to another JSON property on serialization....
Read more >Jackson - Change Name of Field | Baeldung
This quick tutorial illustrates how to change the name of a field to map to another JSON property on serialization.
Read more >How can we change a field name in JSON using Jackson in ...
In the below example, we can change a field name in JSON using @JsonProperty annotation. Example. import java.io.IOException; import ...
Read more >Change Field Names - Oracle Help Center
Change Field Names. Typing in new field names by hand: Rename the fields as you like, using only the characters listed below the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Another alternative inspired from JS destructuring renaming
But it won’t resolve the typed approach of Prisma
totally agreed,
Too sad to have to map:
Instead of simply have: