Permalink
Browse files

Switch from contains() to any() and all().

  • Loading branch information...
1 parent 9dddb94 commit ba5f2008d02c012d53f6cc8c7cfc180c0dcddc3a @kriszyp kriszyp committed Sep 29, 2010
Showing with 28 additions and 8 deletions.
  1. +4 −2 README.md
  2. +16 −4 lib/js-array.js
  3. +8 −2 specification/draft-zyp-rql-00.xml
View
6 README.md
@@ -105,7 +105,8 @@ for more less operators):
* aggregate(<property|function>,...) - Aggregates the array, grouping by objects that are distinct for the provided properties, and then reduces the remaining other property values using the provided functions
* distinct() - Returns a result set with duplicates removed
* in(<property>,<array-of-values>) - Filters for objects where the specified property's value is in the provided array
-* contains(<property>,<value | array-of-values>) - Filters for objects where the specified property's value is an array and the array contains the provided value or contains a value in the provided array
+* any(<property>,<value | expression>) - Filters for objects where the specified property's value is an array and the array contains any value that equals the provided value or satisfies the provided expression.
+* all(<property>,<value | expression>) - Filters for objects where the specified property's value is an array and the array contains values that all equal the provided value or satisfy the provided expression.
* limit(count,start,maxCount) - Returns the given range of objects from the result set
* and(<query>,<query>,...) - Applies all the given queries
* or(<query>,<query>,...) - The union of the given queries
@@ -115,6 +116,7 @@ for more less operators):
* gt(<property>,<value>) - Filters for objects where the specified property's value is greater than the provided value
* ge(<property>,<value>) - Filters for objects where the specified property's value is greater than or equal to the provided value
* ne(<property>,<value>) - Filters for objects where the specified property's value is not equal to the provided value
+* rel(<relation name?>,<query>) - Applies the provided query against the linked data of the provided relation name.
@dvv
dvv Sep 29, 2010

Can you elaborate what is rel() for?

@kriszyp
kriszyp Sep 29, 2010

You wanted a way to refer to linked objects and I think we agreed we didn't want to just rely on dot-delimiting for referring to linked objects. That makes sense to me, so rel() is used evaluation expression in linked relation context.
So if you had:
links:[
{rel:"parent", href:"{parentId}"}
]

and then a query to find the children of someone named Bill could be:
rel(parent,name=Bill)

@dvv
dvv Sep 29, 2010

I see. How do we address nested properties then? ?select(name.ru) ---> ?rel(???)

* sum(<property?>) - Finds the sum of every value in the array or if the property argument is provided, returns the sum of the value of property for every object in the array
* mean(<property?>) - Finds the mean of every value in the array or if the property argument is provided, returns the mean of the value of property for every object in the array
* max(<property?>) - Finds the maximum of every value in the array or if the property argument is provided, returns the maximum of the value of property for every object in the array
@@ -125,7 +127,7 @@ for more less operators):
* count() - Returns the count of the number of records in the query's result set
If you are writing an implementation of RQL for a database or other storage endpoint, or want to introspect queries, you can use the parsed query data
-structures. You can parse string queries with resource-query module's parseQuery function.
+structures. You can parse string queries with query module's parseQuery function.
Query objects have a "name" property and an "args" with an array of the arguments.
For example:
View
20 lib/js-array.js
@@ -41,16 +41,28 @@ exports.operators = {
"in": filter(function(value, values){
return values.indexOf(value) > -1;
}),
- contains: filter(function(array, value){
- if(value instanceof Array){
- return value.some.call(arguments, function(value){
- return array.indexOf(value) > -1;
+ any: filter(function(array, value){
+ if(typeof value == "function"){
+ return array.some(function(i){
+ return value([i]).length;
});
}
else{
return array.indexOf(value) > -1;
}
}),
+ all: filter(function(array, value){
+ if(typeof value == "function"){
+ return array.every(function(i){
+ return value([i]).length;
+ });
+ }
+ else{
+ return array.every(function(i){
+ return i == value;
+ });
+ }
+ }),
or: function(){
var items = [];
//TODO: remove duplicates and use condition property
View
10 specification/draft-zyp-rql-00.xml
@@ -178,8 +178,11 @@ aggregate(departmentId,sum(sales))
<section title="in">
<t>in(&lt;property>,&lt;array-of-values>) - Filters for objects where the specified property's value is in the provided array</t>
</section>
- <section title="contains">
- <t>contains(&lt;property>,&lt;value | array-of-values>) - Filters for objects where the specified property's value is an array and the array contains the provided value or contains a value in the provided array</t>
+ <section title="any">
+ <t>any(&lt;property>,&lt;value | query>) - Filters for objects where the specified property's value is an array and the array contains any value that equals the provided value or satisfies the provided query.</t>
+ </section>
+ <section title="all">
+ <t>all(&lt;property>,&lt;value | query>) - Filters for objects where the specified property's value is an array and the array contains values that all equal the provided value or satisfy the provided query.</t>
</section>
<section title="limit">
<t>limit(&tl;count>,&lt;start>) - Returns a limited range of records from the result set. The first parameter indicates the number of records to return, and the optional second parameter indicates the starting offset.</t>
@@ -208,6 +211,9 @@ aggregate(departmentId,sum(sales))
<section title="ne">
<t>ne(&lt;property>,&lt;value>) - Filters for objects where the specified property's value is not equal to the provided value</t>
</section>
+ <section title="rel">
+ <t>rel(&lt;relation name?>,&lt;query>) - Applies the provided query against the linked data of the provided relation name.</t>
+ </section>
<section title="sum">
<t>sum(&lt;property?>) - Finds the sum of every value in the array or if the property argument is provided, returns the sum of the value of property for every object in the array</t>
</section>

0 comments on commit ba5f200

Please sign in to comment.