Permalink
Browse files

Introduced bug fixes, and new 'not in' operator.

  • Loading branch information...
1 parent b1d0aa2 commit 80824fe2a638dc790cdf92be2e0557186b9d1b70 @zefhemel zefhemel committed Jul 16, 2010
Showing with 25 additions and 6 deletions.
  1. +2 −2 README.md
  2. +23 −4 persistence.js
View
@@ -309,8 +309,8 @@ A `QueryCollection` has the following methods:
* `filter(property, operator, value)`
Returns a new `QueryCollection` that adds a filter, filtering a
certain property based on an operator and value. Supported operators
- are '=', '!=', '<', '<=', '>' and '>='. Example: `.filter('done',
- '=', true)`
+ are '=', '!=', '<', '<=', '>', '>=', 'in' and 'not in'. Example:
+ `.filter('done', '=', true)`
* `order(property, ascending)`
Returns a new `QueryCollection` that will order its results by the
property specified in either an ascending (ascending === true) or
View
@@ -777,11 +777,12 @@ var persistence = (window && window.persistence) ? window.persistence : {};
});
return;
}
- tx.executeSql("SELECT * FROM `" + entityName + "` WHERE `" + property + "`= ? LIMIT 1", [session.entityValToDbVal(value)], function(results) {
+ tx.executeSql("SELECT * FROM `" + entityName + "` WHERE `" + property + "` = ? LIMIT 1", [session.entityValToDbVal(value)], function(results) {
if(results.length == 0) {
callback(null);
+ } else {
+ callback(session.rowToEntity(entityName, results[0]));
}
- callback(session.rowToEntity(entityName, results[0]));
});
}
@@ -1246,6 +1247,15 @@ var persistence = (window && window.persistence) ? window.persistence : {};
}
return "`" + alias + '`.`' + this.property + "` IN (" + qs.join(', ') + ")";
+ } else if (this.operator === 'not in') {
+ var vals = this.value;
+ var qs = [];
+ for(var i = 0; i < vals.length; i++) {
+ qs.push('?');
+ values.push(persistence.entityValToDbVal(vals[i]));
+ }
+
+ return "`" + alias + '`.`' + this.property + "` NOT IN (" + qs.join(', ') + ")";
} else {
var value = this.value;
if(value === true || value === false) {
@@ -1277,7 +1287,10 @@ var persistence = (window && window.persistence) ? window.persistence : {};
return o[this.property] >= this.value;
break;
case 'in':
- return arrayContains(this.values, o[this.property]);
+ return arrayContains(this.value, o[this.property]);
+ break;
+ case 'not in':
+ return !arrayContains(this.value, o[this.property]);
break;
}
}
@@ -1551,6 +1564,12 @@ var persistence = (window && window.persistence) ? window.persistence : {};
tx = args.tx;
oneFn = args.oneFn;
+ var that = this;
+ if(!tx) {
+ this._session.transaction(function(tx) { that.one(tx, oneFn); });
+ return;
+ }
+
this.limit(1).list(tx, function(results) {
if(results.length === 0) {
oneFn(null);
@@ -2091,7 +2110,7 @@ try {
} catch(e) {}
-// Argspec library: http://github.com/zefhemel/argspecjs
+// ArgSpec.js library: http://github.com/zefhemel/argspecjs
var argspec = {};
(function() {

0 comments on commit 80824fe

Please sign in to comment.