On Mon, Mar 30, 2015 at 12:33 PM, Fredrik Boström <fbostrom@gmail.com> wrote:
> I'm building an API backend using Rails 4 and I'm struggling with finding a
> more elaborate way to do model queries straight from the URL than a mere
> ?name=Bob&age=43. What I'm after is some way to make AND, OR, LIKE etc
> operations straight from the URL query parameter.
>
> Loopback on node.js has something similar:
>
> With Loopback you can define your query as a javascript object {filter:
> {where: {and: [{name: {like: 'Bob%'}}, {age: 43}]}}, which, translated to
> query parameters, would be:
> ?filter[where][and][0][name][like]=Bob%25&filter[where][and][1][age]=43.
>
> I've been looking at using Arel, Squeel, sequel-rails and of course normal
> ActiveRecord but none of them seem to provide this kind of URL-to-ORM query
> mapping out of the box. Does anyone have any other pointers or ideas of how
> to make this happen?
Other pointers: don't do that. Don't reinvent SQL and something to
implement it as well. There are reasons not everybody has written a
complete database. Plus, it will be a maintenance *and security*
nightmare.
Look instead at the REST standards. Yes, there's some ambiguity...
but pick what works, for you, *simply*.
--
Dave Aronson, consulting software developer of Codosaur.us,
PullRequestRoulette.com, Blog.Codosaur.us, and Dare2XL.com.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAHxKQij2MRoOTm%3D7mMfO_51YcgtWMxFSz9qvHhqtPVUTdQFO7A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment