Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Map Fieldnames #33

Merged
merged 1 commit into from Jan 3, 2014
Merged

Conversation

ryancarlson
Copy link
Contributor

This project could support enabling auto translation or auto mapping of java field names to database columns based on the following convention:

Query now supports ability to enable auto column mapping.

private String fieldOne;
private String fiendNumber2;
maps to database column: field_one and field_number_2 respectively if enabled

This would cut down on lots of unnecessary calls to addColumnMapping just to get what could be considered default mappings supported my most (all?) other ORM libraries.

This feature can be enabled by calling query.setAutoDeriveColumnNames(true) and that setting lasts for the duration of the query.

…of java field names to database columns based on the following convention:

`Query` now supports ability to enable auto column mapping.
```
private String fieldOne;
private String fiendNumber2;
maps to database column: field_one and field_number_2 respectively if enabled
```
This would cut down on lots of unnecessary calls to addColumnMapping just to get what could be considered default mappings supported my most (all?) other ORM libraries.

This feature can be enabled by calling query.setAutoDeriveColumnNames(true) and that setting lasts for the duration of the query.
aaberg added a commit that referenced this pull request Jan 3, 2014
@aaberg aaberg merged commit f5d52db into aaberg:master Jan 3, 2014
@aaberg
Copy link
Owner

aaberg commented Jan 3, 2014

This is really nice. Thank you very much :)

@ryancarlson
Copy link
Contributor Author

My pleasure! I really like this project. It's a nice straightforward alternative to the "JPA way"

@justin-arvay
Copy link

Great feature.

It would also be great if we could set this as default behavior when constructing the Sql2o object. Similar to how we can set the default column mappings, it would be fitting to be able to "turn on" this feature for every query.

In my case, all column names are lower case with underscore spacing. We also take advantage of the default column mappings (pulled from config files) to avoid unnecessary mapping when constructing the query. Adding in a global option would fit nicely with how we use sql2o.

@aaberg
Copy link
Owner

aaberg commented May 14, 2014

Hi @justin-arvay

I think this is a good idea. Thanks for the suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants