persvr / rql

Resource Query Language
http://www.persvr.org/
267 stars 49 forks source link

update js-array to support any and all #38

Closed neonstalwart closed 10 years ago

neonstalwart commented 10 years ago

the specification and rql/query have been updated with any and all rather than contains but rql/js-array still only has support for contains. since query does not support contains, you can't do

q = new Query().contains(assigned, user.id);

and since js-array doesn't support any you can't do

q = new Query().any('assigned', user.id);
assignedItems = executeQuery(q, {}, data);

so, instead you have to use a string query

q = new Query('contains(assigned,' + user.id + ')');
assignedItems = executeQuery(q, {}, data);
neonstalwart commented 10 years ago

hmm... i looked back through the history and saw that any and all used to exist previously but then dffb85e reverted them so now i'm confused :confused:

wshager commented 10 years ago

I agree the specs are confusing. I'd like to propose to have a look at the xpath/xquery operator specs, and see where rql diverges. I've written rql in xquery, and it really seems like a good match, as long as the names are consistent. In xquery there are several ways to filter sequences. I think that in the case of any/all/contains/excludes, one would be best served by providing a path within eq/ne. This would be less vague to me than a "value or expression". What kind of expression? How many levels deep? Also, xpath always returns an empty sequence instead of failing. I like to think of rql as xpath for REST. Perhaps identifying the similarities with xpath (and a better acronym) will help spread this wonderful technique.

wshager commented 10 years ago

Perhaps eq/ne isn't the best match. But I don't like contains: I have to tilt my head a bit to see why it is called that...

neonstalwart commented 10 years ago

i'm not really familiar with xpath/xquery but with any and all i like that it's possible to use a query as the value to match against items in an array

q = new Query().any('assigned', new Query().eq('id', user.id));
assignedItems = executeQuery(q, {}, data);
wshager commented 10 years ago

Both the concept of a sequence and a path are semantically and functionally more sound than any/all imo.

neonstalwart commented 10 years ago

@wshager are you aware of the existing support for paths?

// find all the items owned by a user
executeQuery('eq(owner/id,$1)', { parameters: [ user.id ]}, items);
wshager commented 10 years ago

Yes, but will this yield the result you expected from any?

neonstalwart commented 10 years ago

i expect that any returns a list of items which have an array value at the specified property where any element (i.e. at least one element) in that array matches the provided value/query. for all, i expect that the items returned will have an array value at the specified property where all elements in the array match the provided value/query.

words can be more ambiguous than code so you could look at the tests i added as part of this PR which indicate what i would expect from using any and all - maybe i misunderstand your question though (perhaps it was rhetorical? :smiley:).

wshager commented 10 years ago

I think every and some might be closer to home, don't you agree? However, in xquery quantified expressions can always be written simpler, and I think this is also true for rql. Usually quantified expressions actually yield a boolean, while your simple path example above would (or imo should) yield the actual result set. I think this is why any and all were dropped from the specs.

An xquery example, fyi: http://en.wikibooks.org/wiki/XQuery/Quantified_Expressions

neonstalwart commented 10 years ago

I think every and some might be closer to home, don't you agree?

yes, this is what i understand any and all do (when applied to a property of a specific item) but if i recall correctly, some and every were already taken (https://github.com/persvr/rql/blob/v0.3.1/query.js#L36) so synonyms were found.

neonstalwart commented 10 years ago

looks like the code has gone in the other direction. no problem - this can be closed.