-
Notifications
You must be signed in to change notification settings - Fork 577
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
Added a case converter plugin #1093
Conversation
There's been some talk about moving this functionality into core Bookshelf (not a plugin and not using I'm not saying this won't get accepted, but it's a bit against the general direction for the future, so let's see what the other guys think. |
Thanks for the reply! Then, there could be a boolean option for initializing Bookshelf instances, indicating whether automatic case conversion should happen. |
Merge with remote branch
@ricardograca Just to philosophically continue the converisation. What will be the future as this project is not actively developed but just maintained? |
That question is in no way related to this issue, so please use the appropriate communication channels for that, like Gitter or a relevant GitHub issue. |
@kripod Yeah, this is a great idea. I'd like simple test cases for this just to be sure. Also this should be documented as the default way to achieve this, leaving manual @ricardograca I don't think that the idea of key conversion for records will go away, we'll just have to update/remove the plugin as the feature evolves. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to make the conversion functions parameters?
return _.reduce(attrs, function (memo, val, key) { | ||
memo[_.camelCase(key)] = val; | ||
return memo; | ||
}, {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not do instead:
parse: function(attrs) {
return _.mapKeys(attrs, (, k) => _.camelCase(k));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll convert to that method after merging this, since the original author isn't interested in doing it.
@kripod If you can address the comment by the reviewer and provide some tests we can merge this. |
@ricardograce I'm sorry, but unfortunately, I lost my interest for this project. |
Merging this as is and then I'll add more documentation to it and change the method used as proposed by @chamini2. The difference in performance is negligible between the two, but it uses less code, and is not less readable, so there's that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good enough starting point.
The case converter plugin handles the conversion between the DB's snake_cased and JS's camelCased Model properties automatically.
It is not hard to implement manually by anyone, but as many people use similar code, I think that this functionality deserves its own official plugin.