Releases: canjs/can-query-logic
Fix the $not hydrator in IE
Document $all, $and, and $not
This adds docs for the new comparison operators.
$all, $not, and $and
This adds support for 3 new comparison operators taken from Mongo's operators.
$all
The $all
comparison matches collections which contain all of the provided values. For example given the dataset:
[
{
"id": "Canada",
"colors": [ "red", "white" ]
},
{
"id": "Mexico",
"colors": [ "red", "white", "green" ]
},
{
"id": "USA",
"colors": [ "red", "white", "blue" ]
}
]
The query { colors: { $all: ["red", "white"] } }
would match all 3 entries. The query { colors: { $all: ["blue"] } }
would match only USA.
$not
The $not
comparison can be used to negate any other comparison. For example given the dataset:
[
{
"name": "Joe",
"age": 45
},
{
"name": "Zoey",
"age": 22
}
]
The query { age: { $not: { $lt: 40 } } }
matches Joe. It is exactly equivalent to { age: { $gte: 40 } }
.
$and
The $and
comparison combines multiple other comparisons into a single grouping. It can be used in combination with the two above comparisons like so. Given the dataset:
[
{
"id": "Canada",
"colors": [ "red", "white" ]
},
{
"id": "Mexico",
"colors": [ "red", "white", "green" ]
},
{
"id": "USA",
"colors": [ "red", "white", "blue" ]
}
]
The query { $and: [ { colors: { $all: ["red, "white"] } }, { colors: { $not: { $all: ["blue"] } } } ] }
matches Canada and Mexico.
QUNIT2 upgrade
This updates the tests to use [email protected].
Sort literal object without can@getSchema Symbol
This fixes sorting literal objects which have not can@getSchema
symbol for example:
var query = new BasicQuery({
sort: "name"
});
var items = [{id: 1, name: "Item 0"}, {id: 2, name: "Item 1"}];
query.index({id: 1, name: "Item 1"}, items); // -> 1
Return an item for a given identity when comparator return 0
Update binary search for query.index
to return a range of items when the comparator returns 0 in order to return the index of item for a given identity.
For example:
var items = [
{id: 1, name: "Item 0"},
{id: 2, name: "Item 1"},
{id: 3, name: "Item 1"},
{id: 4, name: "Item 1"},
{id: 5, name: "Item 2"}
];
var query = new BasicQuery({
sort: "name"
});
var res = query.index({id:4, name: "Item 1"}, items); // -> 3
Codepen code of date string example
For #30
Fix the codepen example and add can.serialize
symbol to DateStringSet
type and can.new
to DateString
type:
class DateStringSet {
constructor(value){
this.value = value;
}
// used to convert to a number
valueOf(){
return new Date(this.value).getTime();
}
[Symbol.for("can.serialize")](){
return this.value;
}
}
const DateString = {
[Symbol.for("can.new")]: function(v){ return v; },
[Symbol.for("can.SetType")]: DateStringSet
};
isDefinedAndHasMembers fix
Issue #22, now when the query object when is not empty, isDefinedAndHasMembers
returns true:
console.log(queryLogic.isDefinedAndHasMembers({})); // => true
console.log(queryLogic.isDefinedAndHasMembers(QueryLogic.UNIVERSAL)); // => true
Sort custom types fix
Issue: #31 - Always use the .valueOf()
operator for custom types.