Permalink
Browse files

can reverse arguments in where clause

  • Loading branch information...
1 parent 4f60478 commit 6a876621b9a07f3360628bcb6f0692bbbf2e164f @chrisdew committed Nov 22, 2012
Showing with 6 additions and 3 deletions.
  1. +3 −0 lib/table.js
  2. +3 −3 test/table-test.js
View
@@ -97,4 +97,7 @@ function createEqual(args) {
if (args[0].field && (typeof args[1] === 'string' || typeof args[1] === 'number')) {
return function(r) { return r[args[0].field] === args[1]; };
}
+ if (args[1].field && (typeof args[0] === 'string' || typeof args[0] === 'number')) {
+ return function(r) { return r[args[1].field] === args[0]; };
+ }
}
View
@@ -51,12 +51,12 @@ describe('Table', function() {
bar.update({"table":"bar","set":[{"field":"foo","expr":"hello"}],"where":{"expr":{"fn":"equal","args":[{field:"id"},1]}}});
});
- it('should update a record again', function(done) {
+ it('should update a record again, with reversed where', function(done) {
bar.once('delta', function(delta) {
- assert.deepEqual({"op":"update","table":"bar","pk":"1","set":[{"field":"foo","expr":"hello"}]}, delta);
+ assert.deepEqual({"op":"update","table":"bar","pk":"1","set":[{"field":"foo","expr":"world"}]}, delta);
done();
});
- bar.update({"table":"bar","set":[{"field":"foo","expr":"world"}],"where":{"expr":{"fn":"equal","args":[{field:"id"},1]}}});
+ bar.update({"table":"bar","set":[{"field":"foo","expr":"world"}],"where":{"expr":{"fn":"equal","args":[1, {field:"id"}]}}});
});
});

0 comments on commit 6a87662

Please sign in to comment.