Skip to content

Releases: canjs/can-query-logic

Fix the $not hydrator in IE

16 Sep 15:40
Compare
Choose a tag to compare

Document $all, $and, and $not

14 Aug 13:47
Compare
Choose a tag to compare

This adds docs for the new comparison operators.

$all, $not, and $and

14 Aug 12:43
Compare
Choose a tag to compare

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

28 May 19:37
Compare
Choose a tag to compare

This updates the tests to use [email protected].

#44

Sort literal object without can@getSchema Symbol

20 May 22:28
Compare
Choose a tag to compare

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

#47

Return an item for a given identity when comparator return 0

16 Apr 19:26
Compare
Choose a tag to compare

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

#33

Codepen code of date string example

18 Jan 21:03
Compare
Choose a tag to compare

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

03 Jan 22:27
Compare
Choose a tag to compare

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

30 Nov 03:09
Compare
Choose a tag to compare

Issue: #31 - Always use the .valueOf() operator for custom types.

Made all tests work in IE11

21 Nov 22:18
Compare
Choose a tag to compare