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

Merged
merged 2 commits into from Jan 12, 2018

Conversation

Projects
5 participants
@kripod
Contributor

kripod commented Jan 15, 2016

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.

@ricardograca

This comment has been minimized.

Member

ricardograca commented Jan 15, 2016

There's been some talk about moving this functionality into core Bookshelf (not a plugin and not using parse and format) for some time. You can check out the conversations about that if you search for "format is confusing" and issues dealing with both methods.

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.

@kripod

This comment has been minimized.

Contributor

kripod commented Jan 15, 2016

Thanks for the reply! Then, there could be a boolean option for initializing Bookshelf instances, indicating whether automatic case conversion should happen.

@vellotis

This comment has been minimized.

Contributor

vellotis commented May 21, 2016

@ricardograca Just to philosophically continue the converisation. What will be the future as this project is not actively developed but just maintained?

@ricardograca

This comment has been minimized.

Member

ricardograca commented May 22, 2016

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.

@rhys-vdw

This comment has been minimized.

Contributor

rhys-vdw commented May 23, 2016

@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 parse/format overrides as more "advanced" approaches.

@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.

@chamini2

Is there any way to make the conversion functions parameters?

return _.reduce(attrs, function (memo, val, key) {
memo[_.camelCase(key)] = val;
return memo;
}, {});

This comment has been minimized.

@chamini2

chamini2 Oct 25, 2017

Contributor

Why not do instead:

parse: function(attrs) {
  return _.mapKeys(attrs, (, k) => _.camelCase(k));
}

This comment has been minimized.

@ricardograca

ricardograca Jan 12, 2018

Member

I'll convert to that method after merging this, since the original author isn't interested in doing it.

@ricardograca

This comment has been minimized.

Member

ricardograca commented Jan 7, 2018

@kripod If you can address the comment by the reviewer and provide some tests we can merge this.

@kripod

This comment has been minimized.

Contributor

kripod commented Jan 7, 2018

@ricardograce I'm sorry, but unfortunately, I lost my interest for this project.

@ricardograca ricardograca added this to To Do in Version 0.13.0 via automation Jan 9, 2018

@ricardograca

This comment has been minimized.

Member

ricardograca commented Jan 12, 2018

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.

@ricardograca

This is a good enough starting point.

@ricardograca ricardograca merged commit 7de5660 into bookshelf:master Jan 12, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

Version 0.13.0 automation moved this from To Do to Done Jan 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment