Auto mapping the field names to snake_case
See original GitHub issueI’ve been trying to find a way to auto map the field names to snake case, this library has potential to do it cleanly.
I think the easiest way right now is to have a helper function to inject a map
attribute to the field options:
import { snakeCase } from 'snake-case';
function addStringFieldMappedSnakeCase(model: PrismaModel, name: string, options: StringFieldOption) {
model.string(name, { map: snakeCase(name), ...options });
return model;
}
But then I will have to add a similar method for each different field types in order to staisify the types. This also breaks the nice method chaining while defining the model.
Would you consider expand the API for this purpose? For example allowing users to retrieve all fields definition to edit them afterwards within the model declaration:
export default createModel((model) => {
model
.string('firstName')
.string('lastName')
.dateTime('createdAt');
model.fields.forEach((field) => ({
...field,
map: snakeCase(field.name),
}));
});
Issue Analytics
- State:
- Created a year ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
How to map camelCase properties to snake_case column ...
Learn how to map CameCase entity properties like phoneNumber to SnakeCase column names like phone_number using a Hibernate naming strategy.
Read more >java - How to map Hibernate entity fields using camelCase to ...
You can achieve this using a custom Hibernate naming strategy. All you need to do is to use the hibernate-types open-source project.
Read more >Automatically pascal case model names during introspection
change field names from snake case to pascal case and updates references to those fields in relations and indexes. Add @Map annotation to...
Read more >Using snake case column names with Dapper and PostgreSQL
In this post I describe how to use snake case naming conventions when using Dapper, by using "Schema" utility classes, nameof(), ...
Read more >Deserialize Snake Case to Camel Case With Jackson
4. Use @JsonProperty Annotation. We can use the @JsonProperty annotation on the fields of our class to map the fields to the exact...
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
@thwonghin Absolutely.
I gave up on using Prisma so I will not continue to implement this. Good luck with the project!