-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Added example region-tags for row object #266
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9c5bf23
Added example region-tags for row object
vijay-qlogic 159ffff
lint update
vijay-qlogic 3b273c2
added code review update
vijay-qlogic fc292e3
more update to sample code
vijay-qlogic b8e24dc
added code-review updates
vijay-qlogic a6b4d49
removed callbacks
vijay-qlogic 6d2aaaa
added lint fixes, uniform variable naming
vijay-qlogic a16b930
Merge branch 'master' into tag-ex-comments-row
sduskis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ env: | |
mocha: true | ||
rules: | ||
node/no-unpublished-require: off | ||
no-unused-vars: off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,312 @@ | ||
/** | ||
* Copyright 2018, Google, Inc. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const snippets = { | ||
createRow: (instanceId, tableId) => { | ||
const Bigtable = require('@google-cloud/bigtable'); | ||
const bigtable = new Bigtable(); | ||
const instance = bigtable.instance(instanceId); | ||
const table = instance.table(tableId); | ||
|
||
// [START bigtable_create_row] | ||
const row = table.row('samplerow'); | ||
|
||
row | ||
.create() | ||
.then(result => { | ||
const apiResponse = result[0]; | ||
}) | ||
.catch(err => { | ||
// Handle the error. | ||
}); | ||
// [END bigtable_create_row] | ||
}, | ||
|
||
createRules: (instanceId, tableId) => { | ||
const Bigtable = require('@google-cloud/bigtable'); | ||
const bigtable = new Bigtable(); | ||
const instance = bigtable.instance(instanceId); | ||
const table = instance.table(tableId); | ||
|
||
// [START bigtable_create_rules] | ||
const row = table.row('samplerow'); | ||
// - | ||
// Add an increment amount to an existing value, if the targeted cell is | ||
// unset, it will be treated as containing a zero. | ||
// | ||
const rules = [ | ||
{ | ||
column: 'follows:gwashington', | ||
increment: 1, | ||
}, | ||
]; | ||
|
||
// - | ||
// You can also create a rule that will append data to an existing value. | ||
// If the targeted cell is unset, it will be treated as a containing an | ||
// empty string. | ||
// | ||
// var rules = [ | ||
// { | ||
// column: 'follows:alincoln', | ||
// append: ' Honest Abe!', | ||
// }, | ||
// ]; | ||
|
||
row | ||
.createRules(rules) | ||
.then(result => { | ||
const apiResponse = result[0]; | ||
}) | ||
.catch(err => { | ||
// Handle the error. | ||
}); | ||
// [END bigtable_create_rules] | ||
}, | ||
|
||
deleteAllCells: (instanceId, tableId) => { | ||
const Bigtable = require('@google-cloud/bigtable'); | ||
const bigtable = new Bigtable(); | ||
const instance = bigtable.instance(instanceId); | ||
const table = instance.table(tableId); | ||
|
||
// [START bigtable_delete_all_cells] | ||
const row = table.row('samplerow'); | ||
row | ||
.delete() | ||
.then(result => { | ||
const apiResponse = result[0]; | ||
}) | ||
.catch(err => { | ||
// Handle the error. | ||
}); | ||
// [END bigtable_delete_all_cells] | ||
}, | ||
|
||
deleteCells: (instanceId, tableId) => { | ||
const Bigtable = require('@google-cloud/bigtable'); | ||
const bigtable = new Bigtable(); | ||
const instance = bigtable.instance(instanceId); | ||
const table = instance.table(tableId); | ||
|
||
// [START bigtable_delete_particular_cells] | ||
const row = table.row('samplerow'); | ||
|
||
// Delete selective cell within a family. | ||
// let cells = [ | ||
// 'follows:gwashington' | ||
// ]; | ||
|
||
// Delete all cells within a family. | ||
const cells = ['follows']; | ||
|
||
row | ||
.deleteCells(cells) | ||
.then(result => { | ||
const apiResponse = result[0]; | ||
}) | ||
.catch(err => { | ||
// Handle the error. | ||
}); | ||
// [END bigtable_delete_particular_cells] | ||
}, | ||
|
||
exists: (instanceId, tableId) => { | ||
const Bigtable = require('@google-cloud/bigtable'); | ||
const bigtable = new Bigtable(); | ||
const instance = bigtable.instance(instanceId); | ||
const table = instance.table(tableId); | ||
|
||
// [START bigtable_row_exists] | ||
const row = table.row('samplerow'); | ||
|
||
row | ||
.exists() | ||
.then(result => { | ||
const exists = result[0]; | ||
}) | ||
.catch(err => { | ||
// Handle the error. | ||
}); | ||
// [END bigtable_row_exists] | ||
}, | ||
|
||
filter: (instanceId, tableId) => { | ||
const Bigtable = require('@google-cloud/bigtable'); | ||
const bigtable = new Bigtable(); | ||
const instance = bigtable.instance(instanceId); | ||
const table = instance.table(tableId); | ||
|
||
// [START bigtable_row_filter] | ||
const row = table.row('samplerow'); | ||
|
||
const filter = [ | ||
{ | ||
family: 'follows', | ||
}, | ||
{ | ||
column: 'alincoln', | ||
}, | ||
{ | ||
value: 1, | ||
}, | ||
]; | ||
|
||
// Optionally, you can pass in an array of entries to be ran in the event | ||
// that a match is not made. | ||
const config = { | ||
onNoMatch: [ | ||
{ | ||
method: 'insert', | ||
data: { | ||
follows: { | ||
jadams: 1, | ||
}, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
row | ||
.filter(filter, config) | ||
.then(result => { | ||
const matched = result[0]; | ||
}) | ||
.catch(err => { | ||
// Handle the error. | ||
}); | ||
// [END bigtable_row_filter] | ||
}, | ||
|
||
get: (instanceId, tableId) => { | ||
const Bigtable = require('@google-cloud/bigtable'); | ||
const bigtable = new Bigtable(); | ||
const instance = bigtable.instance(instanceId); | ||
const table = instance.table(tableId); | ||
|
||
// [START bigtable_get_row] | ||
const row = table.row('samplerow'); | ||
|
||
row | ||
.get() | ||
.then(result => { | ||
const row = result[0]; | ||
}) | ||
.catch(err => { | ||
// Handle the error. | ||
}); | ||
|
||
//- | ||
// Or pass in an array of column names to populate specific cells. | ||
// Under the hood this will create an interleave filter. | ||
//- | ||
// row | ||
// .get([ | ||
// 'follows:gwashington', | ||
// 'follows:alincoln' | ||
// ]) | ||
// .then(result => { | ||
// let row = result[0]; | ||
// }) | ||
// .catch(err => { | ||
// // Handle the error. | ||
// }); | ||
|
||
// [END bigtable_get_row] | ||
}, | ||
|
||
getMetadata: (instanceId, tableId) => { | ||
const Bigtable = require('@google-cloud/bigtable'); | ||
const bigtable = new Bigtable(); | ||
const instance = bigtable.instance(instanceId); | ||
const table = instance.table(tableId); | ||
|
||
// [START bigtable_get_row_meta] | ||
const row = table.row('samplerow'); | ||
|
||
row | ||
.getMetadata() | ||
.then(result => { | ||
const metaData = result[0]; | ||
const apiResponse = result[1]; | ||
}) | ||
.catch(err => { | ||
// Handle the error. | ||
}); | ||
// [END bigtable_get_row_meta] | ||
}, | ||
|
||
increment: (instanceId, tableId) => { | ||
const Bigtable = require('@google-cloud/bigtable'); | ||
const bigtable = new Bigtable(); | ||
const instance = bigtable.instance(instanceId); | ||
const table = instance.table(tableId); | ||
|
||
// [START bigtable_row_increment] | ||
const row = table.row('samplerow'); | ||
|
||
// Specify a custom amount to increment the column by. | ||
// row | ||
// .increment('follows:gwashington', 2) | ||
// .then(result => { | ||
// let value = result[0]; | ||
// let apiResponse = result[1]; | ||
// }); | ||
|
||
// To decrement a column, simply supply a negative value. | ||
// row | ||
// .increment('follows:gwashington', -1) | ||
// .then(result => { | ||
// let value = result[0]; | ||
// let apiResponse = result[1]; | ||
// }); | ||
row | ||
.increment('follows:gwashington') | ||
.then(result => { | ||
const value = result[0]; | ||
const apiResponse = result[1]; | ||
}) | ||
.catch(err => { | ||
// Handle the error. | ||
}); | ||
// [END bigtable_row_increment] | ||
}, | ||
|
||
save: (instanceId, tableId) => { | ||
const Bigtable = require('@google-cloud/bigtable'); | ||
const bigtable = new Bigtable(); | ||
const instance = bigtable.instance(instanceId); | ||
const table = instance.table(tableId); | ||
|
||
// [START bigtable_row_save] | ||
const row = table.row('samplerow'); | ||
const entry = { | ||
follows: { | ||
jadams: 1, | ||
}, | ||
}; | ||
row | ||
.save(entry) | ||
.then(result => { | ||
const apiResponse = result[0]; | ||
}) | ||
.catch(err => { | ||
// Handle the error. | ||
}); | ||
// [END bigtable_row_save] | ||
}, | ||
}; | ||
|
||
module.exports = snippets; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* Copyright 2018 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
const assert = require('assert'); | ||
const uuid = require(`uuid`); | ||
|
||
const Bigtable = require(`@google-cloud/bigtable`); | ||
const bigtable = new Bigtable(); | ||
|
||
const INSTANCE_ID = `nodejs-bigtable-samples-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules | ||
const CLUSTER_ID = `nodejs-bigtable-samples-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules | ||
const TABLE_ID = `nodejs-bigtable-samples-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules | ||
|
||
const rowSnippets = require('../row.js'); | ||
|
||
const instance = bigtable.instance(INSTANCE_ID); | ||
|
||
describe('Row Snippets', function() { | ||
before(async () => { | ||
await instance.create({ | ||
clusters: [ | ||
{ | ||
name: CLUSTER_ID, | ||
location: 'us-central1-f', | ||
storage: 'hdd', | ||
}, | ||
], | ||
type: 'DEVELOPMENT', | ||
}); | ||
await instance.createTable(TABLE_ID); | ||
}); | ||
|
||
after(async () => { | ||
await instance.delete(); | ||
}); | ||
|
||
it('should create a row', () => { | ||
rowSnippets.createRow(INSTANCE_ID, TABLE_ID); | ||
}); | ||
it('should create a row rules', () => { | ||
rowSnippets.createRules(INSTANCE_ID, TABLE_ID); | ||
}); | ||
it('should delete all cells', () => { | ||
rowSnippets.deleteAllCells(INSTANCE_ID, TABLE_ID); | ||
}); | ||
it('should delete selected cells', () => { | ||
rowSnippets.deleteCells(INSTANCE_ID, TABLE_ID); | ||
}); | ||
it('should check row exists', () => { | ||
rowSnippets.exists(INSTANCE_ID, TABLE_ID); | ||
}); | ||
it('should mutate row with matched filter', () => { | ||
rowSnippets.filter(INSTANCE_ID, TABLE_ID); | ||
}); | ||
it('should get row meta-data', () => { | ||
rowSnippets.getMetadata(INSTANCE_ID, TABLE_ID); | ||
}); | ||
it('should increment row', () => { | ||
rowSnippets.increment(INSTANCE_ID, TABLE_ID); | ||
}); | ||
it('should save row', () => { | ||
rowSnippets.save(INSTANCE_ID, TABLE_ID); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.