Closed neonstalwart closed 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:
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.
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...
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);
Both the concept of a sequence and a path are semantically and functionally more sound than any/all imo.
@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);
Yes, but will this yield the result you expected from any?
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:).
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
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.
looks like the code has gone in the other direction. no problem - this can be closed.
the specification and rql/query have been updated with
any
andall
rather thancontains
but rql/js-array still only has support forcontains
. since query does not supportcontains
, you can't doand since js-array doesn't support
any
you can't doso, instead you have to use a string query