Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added emit on insert

  • Loading branch information...
commit 3f52ff2d0b5def140094e121507a1923bd255870 1 parent 328bf64
@chrisdew authored
Showing with 13 additions and 10 deletions.
  1. +3 −1 lib/table.js
  2. +10 −9 test/table-test.js
View
4 lib/table.js
@@ -62,7 +62,9 @@ Table.prototype.insert = function(spec, callback) {
callback("Duplicate Primary Key");
}
- this.rowsByPk[pk] = new row.Row(spec.fields, spec.values);
+ var r = new row.Row(spec.fields, spec.values);
+ this.rowsByPk[pk] = r;
if (callback) callback(null, "1 row inserted.");
+ this.emit('delta', {op:'insert',row:r});
return this;
}
View
19 test/table-test.js
@@ -13,19 +13,20 @@ describe('Table', function() {
new table.Table().constructor.super_.name);
});
- it('should insert a record', function() {
+ it('should insert a record', function(done) {
var bar = new table.Table({name:'bar',
fields:[{field:'id',type:'integer',pk:true,ai:true},
{field:'foo',type: 'varchar'}]});
+ bar.on('delta', function(delta) {
+ assert.deepEqual({"op":"insert","row":{"_version":1,"id":1,"foo":"hello"}}, delta);
+ done();
+ });
bar.insert({"table":"bar","fields":["id","foo"],"values":[1,"hello"]});
- //console.log("bar", bar);
- assert.deepEqual({name:'bar',
- fields:[{field:'id',type:'integer',pk:true,ai:true},
- {field:'foo',type:'varchar'}],
- rowsByPk:{'1':{id:1,foo:'hello',_version:1}},
- pkName:'id',
- nextPk:2},
- bar);
+ console.log("bar", bar);
+ assert.deepEqual({'1':{id:1,foo:'hello',_version:1}},
+ bar.rowsByPk);
+ assert.deepEqual(2,
+ bar.nextPk);
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.