Format count query parameters with BookshelfJS
I'm just getting up to speed with BookshelfJS, so I'm probably missing something, but I'm wondering how to get query parameters to be formatted correctly for doing a count. For example, if I want my JS objects to use camelCase, and the database rows to use snake_case, I know I can use the format()
and parse()
functions on the model like so: http://bookshelfjs.org/#parse-and-format
But how do I get query parameters for a count to be converted from camelCase to snake_case before they're run as queries on the DB?
Example:
Now let's say the books
database table has author_name
as a column, but, if this is being used in an API, we want users to query on the authorName
parameter.
Doing this converts the query parameters just fine:
And it queries the DB on author_name
instead of authorName
. But the analogous:
doesn't work as expected, because it's not converting authorName
to author_name
before querying. How do I get bookshelf to use the format()
function I wrote to do this?
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.