Skip to content

Commit 31c929f

Browse files
committed
Allow excluding ranges
1 parent 8b14343 commit 31c929f

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

store/db/IndexedDB.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,9 @@ define(['dojo/_base/declare', 'dojo/_base/lang', 'dojo/Deferred', 'dojo/when', '
469469
},
470470
keyRange: from ?
471471
to ?
472-
IDBKeyRange.bound(from, to) :
473-
IDBKeyRange.lowerBound(from) :
474-
IDBKeyRange.upperBound(to)
472+
IDBKeyRange.bound(from, to, filterValue.excludeFrom, filterValue.excludeTo) :
473+
IDBKeyRange.lowerBound(from, filterValue.excludeFrom) :
474+
IDBKeyRange.upperBound(to, filterValue.excludeTo)
475475
};
476476
})(filterValue.from, filterValue.to);
477477
} else if (typeof filterValue === 'object' && filterValue.contains) {

store/db/SQL.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,20 @@ define(['dojo/_base/declare', 'dojo/Deferred', 'dojo/when', 'dojo/store/util/Que
238238
continue;
239239
}else if(typeof filterValue == 'object' && ("from" in filterValue || "to" in filterValue)){
240240
// a range object, convert to appropriate SQL operators
241-
if("from" in filterValue){
241+
var fromComparator = filterValue.excludeFrom ? '>' : '>=';
242+
var toComparator = filterValue.excludeTo ? '<' : '<=';
243+
if('from' in filterValue){
242244
params.push(filterValue.from);
243-
if("to" in filterValue){
245+
if('to' in filterValue){
244246
params.push(filterValue.to);
245-
conditions.push('(' + table + '.' + i + '>=? AND ' + table + '.' + i + '<=?)');
247+
conditions.push('(' + table + '.' + i + fromComparator + '? AND ' +
248+
table + '.' + i + toComparator + '?)');
246249
}else{
247-
conditions.push(table + '.' + i + '>=?');
250+
conditions.push(table + '.' + i + fromComparator + '?');
248251
}
249252
}else{
250253
params.push(filterValue.to);
251-
conditions.push(table + '.' + i + '<=?');
254+
conditions.push(table + '.' + i + toComparator + '?');
252255
}
253256
continue;
254257
}

store/tests/LocalStorage.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ define([
9797
"[{name: 'two'}, {mappedTo: 'C'}, {mappedTo: 'D'}]": testQuery([{name: 'two'}, {mappedTo: 'C'}, {mappedTo: 'D'}], [2, 3]),
9898
"{id: {from: 1, to: 3}}": testQuery({id: {from: 1, to: 3}}, [1, 2, 3]),
9999
"{name: {from: 'm', to: 'three'}}": testQuery({name: {from: 'm', to: 'three'}}, [1, 3]),
100+
"{name: {from: 'one', to: 'three'}}": testQuery({name: {from: 'm', to: 'three'}}, [1, 3]),
101+
"{name: {from: 'one', excludeFrom: true, to: 'three'}}": testQuery({name: {from: 'one', excludeFrom: true, to: 'three'}}, [3]),
102+
"{name: {from: 'one', to: 'three', excludeTo: true}}": testQuery({name: {from: 'one', to: 'three', excludeTo: true}}, [1]),
103+
"{name: {from: 'one', excludeFrom: true, to: 'three', excludeTo: true}}": testQuery({name: {from: 'one', excludeFrom: true, to: 'three', excludeTo: true}}, []),
100104
"{name: 't*'}": testQuery({name: 't*'}, {sort:[{attribute: "name"}]}, [3, 2]),
101105
"{name: 'not a number'}": testQuery({name: 'not a number'}, []),
102106
"{words: {contains: ['orange']}}": testQuery({words: {contains: ['orange']}}, {multi: true}, [2, 3]),

0 commit comments

Comments
 (0)