Skip to content

Commit 76adc19

Browse files
muraliQlogicGautamSharda
authored andcommitted
Delete data on row.js mutation calls (#207)
* fix for Issue#151 * deleting data for createRules, filter, create, save and delete method * Changing how this.data works In read, data is now set to the resulting row's data. In mutation methods, clearing the map instead of deleting it. * Update row.js * Update row.js
1 parent a1b0f67 commit 76adc19

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

handwritten/bigtable/src/row.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ class Row {
266266
data: options.entry,
267267
method: Mutation.methods.INSERT,
268268
};
269+
this.data = {};
269270

270271
this.table.mutate(entry, options.gaxOptions, (err, apiResponse) => {
271272
if (err) {
@@ -367,7 +368,7 @@ class Row {
367368
rowKey: Mutation.convertToBytes(this.id),
368369
rules,
369370
};
370-
371+
this.data = {};
371372
this.bigtable.request(
372373
{
373374
client: 'BigtableClient',
@@ -409,7 +410,7 @@ class Row {
409410
key: this.id,
410411
method: Mutation.methods.DELETE,
411412
};
412-
413+
this.data = {};
413414
this.table.mutate(mutation, gaxOptions, callback);
414415
}
415416

@@ -467,7 +468,7 @@ class Row {
467468
data: arrify(columns),
468469
method: Mutation.methods.DELETE,
469470
};
470-
471+
this.data = {};
471472
this.table.mutate(mutation, gaxOptions, callback);
472473
}
473474

@@ -599,7 +600,7 @@ class Row {
599600
trueMutations: createFlatMutationsList(config.onMatch),
600601
falseMutations: createFlatMutationsList(config.onNoMatch),
601602
};
602-
603+
this.data = {};
603604
this.bigtable.request(
604605
{
605606
client: 'BigtableClient',
@@ -728,10 +729,10 @@ class Row {
728729
return;
729730
}
730731

731-
extend(true, this.data, row.data);
732+
this.data = row.data;
732733

733734
// If the user specifies column names, we'll return back the row data we
734-
// received. Otherwise, we'll return the row itthis in a typical
735+
// received. Otherwise, we'll return the row "this" in a typical
735736
// GrpcServiceObject#get fashion.
736737
callback(null, columns.length ? row.data : this);
737738
});
@@ -910,7 +911,7 @@ class Row {
910911
data: entry,
911912
method: Mutation.methods.INSERT,
912913
};
913-
914+
this.data = {};
914915
this.table.mutate(mutation, gaxOptions, callback);
915916
}
916917
}

handwritten/bigtable/test/row.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,17 @@ describe('Bigtable/Row', function() {
719719

720720
row.delete(gaxOptions, done);
721721
});
722+
723+
it('should remove existing data', function(done) {
724+
var gaxOptions = {};
725+
row.table.mutate = function(mutation, gaxOptions_) {
726+
assert.strictEqual(gaxOptions_, gaxOptions);
727+
done();
728+
};
729+
730+
row.delete(gaxOptions, done);
731+
assert.strictEqual(row.data, undefined);
732+
});
722733
});
723734

724735
describe('deleteCells', function() {
@@ -746,6 +757,15 @@ describe('Bigtable/Row', function() {
746757

747758
row.deleteCells(columns, gaxOptions, done);
748759
});
760+
761+
it('should remove existing data', function(done) {
762+
row.table.mutate = function(mutation, gaxOptions, callback) {
763+
callback(); // done()
764+
};
765+
766+
row.deleteCells(columns, done);
767+
assert.strictEqual(row.data, undefined);
768+
});
749769
});
750770

751771
describe('exists', function() {
@@ -1440,6 +1460,17 @@ describe('Bigtable/Row', function() {
14401460

14411461
row.save(data, gaxOptions, assert.ifError);
14421462
});
1463+
1464+
it('should remove existing data', function(done) {
1465+
var gaxOptions = {};
1466+
row.table.mutate = function(entry, gaxOptions_) {
1467+
assert.strictEqual(gaxOptions_, gaxOptions);
1468+
done();
1469+
};
1470+
1471+
row.save(data, gaxOptions, assert.ifError);
1472+
assert.strictEqual(row.data, undefined);
1473+
});
14431474
});
14441475

14451476
describe('RowError', function() {

0 commit comments

Comments
 (0)