Closed tomas closed 3 years ago
How about the following?
table.select do |record|
conditions = []
conditions << (record.name =~ name) if name
conditions << (record.description =~ description) if description
conditions
end
Thanks, but I need to make it work using the query syntax (not the block syntax). This is because I want to combine different criteria dynamically.
If not possible, can this be fixed in a future version of rroonga?
You can use the query syntax with record.name.match(name)
.
Sorry, I meant the table.select("+column:value")
syntax, as shown in the first message. Not sure how it's called.
How do you create the query syntax? End users specify it? Or your program builds it?
I'm building an ORM around Groonga (rroonga) so that different apps can declare their models in an ActiveRecord-like fashion (using relationships, named scopes, etc).
I'm currently using this ORM in a specific app where I need to run a query to find records with nil values for two columns.
Ah, sorry. I misunderstood.
The following will work:
table.select do |record|
conditions = []
conditions << (record.name == name.to_s)
conditions << (record.description == description.to_s)
conditions
end
I think that you can use the above API in your ORM. (I'm not sure why you need the query syntax with ORM.)
Using the block syntax would make implementation much more complex, so I'd rather keep on using the query/string syntax (I've managed to do everything else so far).
Where would I modify this in the rroonga source code? Either to submit a PR or to start my own fork of this project.
Thanks again
I don't know why the block syntax causes more complex implementation but does table.select("+description:\"\" +name:foo")
work for you?
Forgot to say that the \"\"
thing worked. :)
Thanks!
Hi, me again. :)
I'm able to perform using two or more filters where one of them is blank/nil, for example:
This works as long as the nil column is at the end of the list, because if I do:
I get a nasty
column lookup failed
error.So the question is: how can I make the second example work?
This is important because I want to be able to search for two nil columns at the same time, and this problem is preventing me from doing so.
Hope you can help me out. Thanks!