Skip to content

Commit

Permalink
Allow excluding ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Mar 5, 2014
1 parent 8b14343 commit 31c929f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions store/db/IndexedDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,9 @@ define(['dojo/_base/declare', 'dojo/_base/lang', 'dojo/Deferred', 'dojo/when', '
},
keyRange: from ?
to ?
IDBKeyRange.bound(from, to) :
IDBKeyRange.lowerBound(from) :
IDBKeyRange.upperBound(to)
IDBKeyRange.bound(from, to, filterValue.excludeFrom, filterValue.excludeTo) :
IDBKeyRange.lowerBound(from, filterValue.excludeFrom) :
IDBKeyRange.upperBound(to, filterValue.excludeTo)
};
})(filterValue.from, filterValue.to);
} else if (typeof filterValue === 'object' && filterValue.contains) {
Expand Down
13 changes: 8 additions & 5 deletions store/db/SQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,20 @@ define(['dojo/_base/declare', 'dojo/Deferred', 'dojo/when', 'dojo/store/util/Que
continue;
}else if(typeof filterValue == 'object' && ("from" in filterValue || "to" in filterValue)){
// a range object, convert to appropriate SQL operators
if("from" in filterValue){
var fromComparator = filterValue.excludeFrom ? '>' : '>=';
var toComparator = filterValue.excludeTo ? '<' : '<=';
if('from' in filterValue){
params.push(filterValue.from);
if("to" in filterValue){
if('to' in filterValue){
params.push(filterValue.to);
conditions.push('(' + table + '.' + i + '>=? AND ' + table + '.' + i + '<=?)');
conditions.push('(' + table + '.' + i + fromComparator + '? AND ' +
table + '.' + i + toComparator + '?)');
}else{
conditions.push(table + '.' + i + '>=?');
conditions.push(table + '.' + i + fromComparator + '?');
}
}else{
params.push(filterValue.to);
conditions.push(table + '.' + i + '<=?');
conditions.push(table + '.' + i + toComparator + '?');
}
continue;
}
Expand Down
4 changes: 4 additions & 0 deletions store/tests/LocalStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ define([
"[{name: 'two'}, {mappedTo: 'C'}, {mappedTo: 'D'}]": testQuery([{name: 'two'}, {mappedTo: 'C'}, {mappedTo: 'D'}], [2, 3]),
"{id: {from: 1, to: 3}}": testQuery({id: {from: 1, to: 3}}, [1, 2, 3]),
"{name: {from: 'm', to: 'three'}}": testQuery({name: {from: 'm', to: 'three'}}, [1, 3]),
"{name: {from: 'one', to: 'three'}}": testQuery({name: {from: 'm', to: 'three'}}, [1, 3]),
"{name: {from: 'one', excludeFrom: true, to: 'three'}}": testQuery({name: {from: 'one', excludeFrom: true, to: 'three'}}, [3]),
"{name: {from: 'one', to: 'three', excludeTo: true}}": testQuery({name: {from: 'one', to: 'three', excludeTo: true}}, [1]),
"{name: {from: 'one', excludeFrom: true, to: 'three', excludeTo: true}}": testQuery({name: {from: 'one', excludeFrom: true, to: 'three', excludeTo: true}}, []),
"{name: 't*'}": testQuery({name: 't*'}, {sort:[{attribute: "name"}]}, [3, 2]),
"{name: 'not a number'}": testQuery({name: 'not a number'}, []),
"{words: {contains: ['orange']}}": testQuery({words: {contains: ['orange']}}, {multi: true}, [2, 3]),
Expand Down

0 comments on commit 31c929f

Please sign in to comment.