Skip to content

Commit

Permalink
Delete data on row.js mutation calls (#207)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
muraliQlogic authored and sduskis committed Jun 28, 2018
1 parent e77c3c9 commit 7c19034
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ class Row {
data: options.entry,
method: Mutation.methods.INSERT,
};
this.data = {};

this.table.mutate(entry, options.gaxOptions, (err, apiResponse) => {
if (err) {
Expand Down Expand Up @@ -367,7 +368,7 @@ class Row {
rowKey: Mutation.convertToBytes(this.id),
rules,
};

this.data = {};
this.bigtable.request(
{
client: 'BigtableClient',
Expand Down Expand Up @@ -409,7 +410,7 @@ class Row {
key: this.id,
method: Mutation.methods.DELETE,
};

this.data = {};
this.table.mutate(mutation, gaxOptions, callback);
}

Expand Down Expand Up @@ -467,7 +468,7 @@ class Row {
data: arrify(columns),
method: Mutation.methods.DELETE,
};

this.data = {};
this.table.mutate(mutation, gaxOptions, callback);
}

Expand Down Expand Up @@ -599,7 +600,7 @@ class Row {
trueMutations: createFlatMutationsList(config.onMatch),
falseMutations: createFlatMutationsList(config.onNoMatch),
};

this.data = {};
this.bigtable.request(
{
client: 'BigtableClient',
Expand Down Expand Up @@ -728,10 +729,10 @@ class Row {
return;
}

extend(true, this.data, row.data);
this.data = row.data;

// If the user specifies column names, we'll return back the row data we
// received. Otherwise, we'll return the row itthis in a typical
// received. Otherwise, we'll return the row "this" in a typical
// GrpcServiceObject#get fashion.
callback(null, columns.length ? row.data : this);
});
Expand Down Expand Up @@ -910,7 +911,7 @@ class Row {
data: entry,
method: Mutation.methods.INSERT,
};

this.data = {};
this.table.mutate(mutation, gaxOptions, callback);
}
}
Expand Down
31 changes: 31 additions & 0 deletions test/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,17 @@ describe('Bigtable/Row', function() {

row.delete(gaxOptions, done);
});

it('should remove existing data', function(done) {
var gaxOptions = {};
row.table.mutate = function(mutation, gaxOptions_) {
assert.strictEqual(gaxOptions_, gaxOptions);
done();
};

row.delete(gaxOptions, done);
assert.strictEqual(row.data, undefined);
});
});

describe('deleteCells', function() {
Expand Down Expand Up @@ -746,6 +757,15 @@ describe('Bigtable/Row', function() {

row.deleteCells(columns, gaxOptions, done);
});

it('should remove existing data', function(done) {
row.table.mutate = function(mutation, gaxOptions, callback) {
callback(); // done()
};

row.deleteCells(columns, done);
assert.strictEqual(row.data, undefined);
});
});

describe('exists', function() {
Expand Down Expand Up @@ -1440,6 +1460,17 @@ describe('Bigtable/Row', function() {

row.save(data, gaxOptions, assert.ifError);
});

it('should remove existing data', function(done) {
var gaxOptions = {};
row.table.mutate = function(entry, gaxOptions_) {
assert.strictEqual(gaxOptions_, gaxOptions);
done();
};

row.save(data, gaxOptions, assert.ifError);
assert.strictEqual(row.data, undefined);
});
});

describe('RowError', function() {
Expand Down

0 comments on commit 7c19034

Please sign in to comment.