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

DSL for Parse::Query#in_query #57

Open
adelevie opened this issue Jan 11, 2013 · 7 comments
Open

DSL for Parse::Query#in_query #57

adelevie opened this issue Jan 11, 2013 · 7 comments

Comments

@adelevie
Copy link
Owner

Here's the current usage:

Assume I have the classes Post, Tags, and PostTags (which joins the first two).
def in_query(field, query)
query_hash = {Parse::Protocol::KEY_CLASS_NAME => query.class_name, "where" => query.where}
add_constraint(field, "$inQuery" => query_hash)
self
end

post_tags = Parse::Query.new("PostTag").tap do |q|
  q.in_query("tag", Parse::Query.new("Tag").tap do |tq|
    tq.eq("category", "Person")
  end)
end.get

And here's what I propose:

post_tags = Parse::Query.new("PostTag").tap do |q|
  q.in_query("tag") do |tag_query|
    tag_query.eq("category", "Person")
  end
end.get

Is this something anyone (@ericcj, @jamonholmgren) would want?

@jamonholmgren
Copy link

I haven't had a need for "$inQuery" yet but this looks cleaner. 👍 if you want to make it happen.

@adelevie
Copy link
Owner Author

Maybe I'll save that nice syntax for the parse_resource-ruby-client-epic-merge.

@jamonholmgren
Copy link

We should do a parse_resource-ruby-client-epic-merge hackathon.

@ericcj
Copy link
Contributor

ericcj commented Jan 11, 2013

it's nice to get rid of the new'ing of queries everywhere, but you have to
somehow infer that the "tag" column refers to the "Tag" class. that seems
like a reasonable convention, and indeed we use the below in our app to
provide it, but it's not inherently part of the parse api.

def class_name_for_column(column)
column == 'user' ? Parse::Protocol::CLASS_USER : column.camelize
end

def column_name_for_class(clazz)
clazz == Parse::Protocol::CLASS_USER ? 'user' : clazz.camelize(:lower)
end

On Fri, Jan 11, 2013 at 11:54 AM, Jamon Holmgren
notifications@github.comwrote:

I haven't had a need for "$inQuery" yet but this looks cleaner. [image:
👍] if you want to make it happen.


Reply to this email directly or view it on GitHubhttps://github.com//issues/57#issuecomment-12152840.

@adelevie
Copy link
Owner Author

That does look pretty useful.

Also, perhaps a simpler implementation is to not use blocks, and instead to have #in_query return an instance of Parse::Query. Then just call #tap against the new query object to build and add parameters:

post_tags = Parse::Query.new("PostTag").tap do |q|
  q.in_query("tag").tap |tag_query|
    tag_query.eq("category", "Person")
  end
end.get

@adelevie
Copy link
Owner Author

@jamonholmgren heh, maybe a (mandatory) Clearsight Studio employee hackathon. I'll just kick back and accept the pull requests.

@jamonholmgren
Copy link

@adelevie there you go, open source administration at its best.

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

No branches or pull requests

4 participants