diff --git a/samples/document-snippets/instance.js b/samples/document-snippets/instance.js index f5e622b52..d32b6e75b 100644 --- a/samples/document-snippets/instance.js +++ b/samples/document-snippets/instance.js @@ -13,12 +13,11 @@ * limitations under the License. */ -const Bigtable = require('@google-cloud/bigtable'); -const bigtable = new Bigtable(); - const snippets = { - createInstance: (instanceId, clusterId, callback) => { + createInstance: (instanceId, clusterId) => { // [START bigtable_create_instance] + const Bigtable = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); const instance = bigtable.instance(instanceId); // options for a PRODUCTION Instance @@ -53,19 +52,17 @@ const snippets = { const newInstance = result[0]; // let operations = result[1]; // let apiResponse = result[2]; - - console.log(`Created Instance: ${newInstance.id}`); - callback(null, newInstance); }) .catch(err => { - console.error('Error creating prod-instance:', err); - callback(err); + // Handle the error. }); // [END bigtable_create_instance] }, - createCluster: (instanceId, clusterId, callback) => { + createCluster: (instanceId, clusterId) => { // [START bigtable_create_cluster] + const Bigtable = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); const instance = bigtable.instance(instanceId); // const options = { @@ -73,31 +70,29 @@ const snippets = { // nodes: 3, // storage: 'ssd', // }; - const options = { location: 'us-central1-b', storage: 'hdd', }; - instance .createCluster(clusterId, options) .then(result => { const newCluster = result[0]; // const operations = result[1]; // const apiResponse = result[2]; - console.log(`Cluster created: ${newCluster.id}`); - callback(null, newCluster); }) .catch(err => { - console.error('Error creating cluster: ', err); - callback(err); + // Handle the error. }); // [END bigtable_create_cluster] }, createAppProfile: (instanceId, clusterId, appProfileId, callback) => { // [START bigtable_create_app_profile] + const Bigtable = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); const instance = bigtable.instance(instanceId); + const cluster = instance.cluster(clusterId); const options = { @@ -108,18 +103,18 @@ const snippets = { instance.createAppProfile(appProfileId, options, (err, appProfile) => { if (err) { - console.error('Error creating appProfile: ', err); - callback(err); - return; + // Handle the error. + return callback(err); } - console.log(`App-Profile created: ${appProfile.name}`); - callback(appProfile); + return callback(appProfile); }); // [END bigtable_create_app_profile] }, - createTable: (instanceId, tableId, callback) => { + createTable: (instanceId, tableId) => { // [START bigtable_create_table] + const Bigtable = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); const instance = bigtable.instance(instanceId); const options = { @@ -151,110 +146,104 @@ const snippets = { .then(result => { const newTable = result[0]; // const apiResponse = result[1]; - console.log(`Table created: ${newTable.name}`); - callback(null, newTable); }) .catch(err => { - console.error('Error creating table: ', err); - callback(err); + // Handle the error. }); // [END bigtable_create_table] }, - existsInstance: (instanceId, callback) => { + existsInstance: instanceId => { + // [START bigtable_exists_instance] + const Bigtable = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); const instance = bigtable.instance(instanceId); - // [START bigtable_exists_instance] instance .exists() .then(result => { const exists = result[0]; - console.log(`Instance ${instanceId} Exists: ${exists}`); - callback(null, exists); }) .catch(err => { - console.error('Error in checking Instance exists: ', err); - callback(err); + // Handle the error. }); // [END bigtable_exists_instance] }, - getInstance: (instanceId, callback) => { + getInstance: instanceId => { + // [START bigtable_get_instance] + const Bigtable = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); const instance = bigtable.instance(instanceId); - // [START bigtable_get_instance] instance .get() .then(result => { const instance = result[0]; // const apiResponse = result[1]; - console.log(`Instance: \n${instance}`); - callback(null, instance); }) .catch(err => { - console.error('Error geting Instance: ', err); - callback(err); + // Handle the error. }); // [END bigtable_get_instance] }, - getClusters: (instanceId, callback) => { + getClusters: instanceId => { + // [START bigtable_get_clusters] + const Bigtable = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); const instance = bigtable.instance(instanceId); - // [START bigtable_get_clusters] instance .getClusters() .then(result => { - console.log(`Clusters: \n${result[0]}`); - callback(null, result); + const clusters = result[0]; }) .catch(err => { - console.error('Error geting Clusters: ', err); - callback(err); + // Handle the error. }); // [END bigtable_get_clusters] }, - getAppProfiles: (instanceId, callback) => { + getAppProfiles: instanceId => { + // [START bigtable_get_app_profiles] + const Bigtable = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); const instance = bigtable.instance(instanceId); - // [START bigtable_get_app_profiles] instance .getAppProfiles() .then(result => { - console.log(`AppProfiles: \n${result[0]}`); - callback(null, result); + const appProfiles = result[0]; }) .catch(err => { - console.error('Error geting AppProfiles: ', err); - callback(err); + // Handle the error. }); // [END bigtable_get_app_profiles] }, - getMetaData: (instanceId, callback) => { + getMetadata: instanceId => { + // [START bigtable_get_instance_metadata] + const Bigtable = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); const instance = bigtable.instance(instanceId); - // [START bigtable_get_instance_metadata] instance .getMetadata() .then(result => { const metaData = result[0]; - // const apiResponse = result[1]; - console.log('%s %O', 'Instance Metadata:\n', metaData); - callback(null, metaData); }) .catch(err => { - console.error('Error geting Metadata: ', err); - callback(err); + // Handle the error. }); // [END bigtable_get_instance_metadata] }, - getTables: (instanceId, callback) => { - const instance = bigtable.instance(instanceId); - + getTables: instanceId => { // [START bigtable_get_tables] + const Bigtable = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceId); // To control how many API requests are made and page through the results // manually, set `autoPaginate` to false. @@ -268,24 +257,20 @@ const snippets = { instance .getTables(options) .then(result => { - console.log(`Tables:`); const tables = result[0]; - tables.forEach(t => { - console.log(t.id); - }); - callback(null, tables); }) .catch(err => { - console.error('Error geting Tables: ', err); - callback(err); + // Handle the error. }); // [END bigtable_get_tables] }, - updateInstance: (instanceId, callback) => { + updateInstance: instanceId => { + // [START bigtable_set_meta_data] + const Bigtable = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); const instance = bigtable.instance(instanceId); - // [START bigtable_set_meta_data] const metadata = { displayName: 'updated-name', }; @@ -293,29 +278,27 @@ const snippets = { instance .setMetadata(metadata) .then(result => { - console.log(`API Response: \n${result[0]}`); - callback(null, result); + const apiResponse = result[0]; }) .catch(err => { - console.error('Error in Set MetaData: ', err); - callback(err); + // Handle the error. }); // [END bigtable_set_meta_data] }, - delInstance: (instanceId, callback) => { + delInstance: instanceId => { // [START bigtable_del_instance] + const Bigtable = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); const instance = bigtable.instance(instanceId); + instance .delete() .then(result => { const apiResponse = result[0]; - console.log(`Instance ${instanceId} deleted: ${apiResponse}`); - callback(null, apiResponse); }) .catch(err => { - console.error('Error deleting instance: ', err); - callback(err); + // Handle the error. }); // [END bigtable_del_instance] }, diff --git a/samples/document-snippets/table.js b/samples/document-snippets/table.js new file mode 100644 index 000000000..6f23c4fff --- /dev/null +++ b/samples/document-snippets/table.js @@ -0,0 +1,332 @@ +/** + * 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 Bigtable = require('@google-cloud/bigtable'); +const bigtable = new Bigtable(); + +const snippets = { + createTable: (instanceId, tableId) => { + const instance = bigtable.instance(instanceId); + const table = instance.table(tableId); + + // [START bigtable_create_table] + table + .create() + .then(result => { + const table = result[0]; + // let apiResponse = result[1]; + }) + .catch(err => { + // Handle the error. + }); + // [END bigtable_create_table] + }, + + existsTable: (instanceId, tableId) => { + const instance = bigtable.instance(instanceId); + const table = instance.table(tableId); + + // [START bigtable_exists_table] + table + .exists() + .then(result => { + const exists = result[0]; + }) + .catch(err => { + // Handle the error. + }); + // [END bigtable_exists_table] + }, + + getTable: (instanceId, tableId) => { + const instance = bigtable.instance(instanceId); + const table = instance.table(tableId); + + // [START bigtable_get_table] + table + .get() + .then(result => { + const table = result[0]; + // const apiResponse = result[1]; + }) + .catch(err => { + // Handle the error. + }); + // [END bigtable_get_table] + }, + + getMetadata: (instanceId, tableId) => { + const instance = bigtable.instance(instanceId); + const table = instance.table(tableId); + + // [START bigtable_get_table_meta] + table + .getMetadata() + .then(result => { + const metaData = result[0]; + // const apiResponse = result[1]; + }) + .catch(err => { + // Handle the error. + }); + // [END bigtable_get_table_meta] + }, + + createFamily: (instanceId, tableId, familyId) => { + const instance = bigtable.instance(instanceId); + const table = instance.table(tableId); + + // [START bigtable_create_family] + const options = {}; + // options.rule = { + // age: { + // seconds: 0, + // nanos: 5000 + // }, + // versions: 3, + // union: true + // }; + + table + .createFamily(familyId, options) + .then(result => { + const family = result[0]; + // const apiResponse = result[1]; + }) + .catch(err => { + // Handle the error. + }); + // [END bigtable_create_table] + }, + + getFamilies: (instanceId, tableId) => { + const instance = bigtable.instance(instanceId); + const table = instance.table(tableId); + + // [START bigtable_get_families] + table + .getFamilies() + .then(result => { + const families = result[0]; + }) + .catch(err => { + // Handle the error. + }); + // [END bigtable_get_families] + }, + + insertRows: (instanceId, tableId) => { + const instance = bigtable.instance(instanceId); + const table = instance.table(tableId); + + // [START bigtable_insert_rows] + const entries = [ + { + key: 'alincoln', + data: { + follows: { + gwashington: 1, + }, + }, + }, + ]; + + table + .insert(entries) + .then(result => { + const apiResponse = result[0]; + }) + .catch(err => { + // Handle the error. + }); + // [END bigtable_insert_rows] + }, + + getRows: (instanceId, tableId) => { + const instance = bigtable.instance(instanceId); + const table = instance.table(tableId); + + // [START bigtable_get_rows] + const options = { + keys: ['alincoln', 'gwashington'], + }; + table + .getRows(options) + .then(result => { + const rows = result[0]; + }) + .catch(err => { + // Handle the error. + }); + // [END bigtable_get_rows] + }, + + mutate: (instanceId, tableId) => { + const instance = bigtable.instance(instanceId); + const table = instance.table(tableId); + + // [START bigtable_mutate_rows] + const entries = [ + { + method: 'delete', + key: 'alincoln', + }, + ]; + table + .mutate(entries) + .then(() => { + // handle success + }) + .catch(err => { + // Handle the error. + }); + // [END bigtable_mutate_rows] + }, + + createReadStream: (instanceId, tableId) => { + const instance = bigtable.instance(instanceId); + const table = instance.table(tableId); + + // [START bigtable_table_readstream] + table + .createReadStream() + .on('error', err => { + // Handle the error. + }) + .on('data', function(row) { + // `row` is a Row object. + }) + .on('end', function() { + // All rows retrieved. + }); + //- + // If you anticipate many results, you can end a stream early to prevent + // unnecessary processing. + //- + // table + // .createReadStream() + // .on('data', function (row) { + // this.end(); + // }); + + //- + // Specify arbitrary keys for a non-contiguous set of rows. + // The total size of the keys must remain under 1MB, after encoding. + //- + // table.createReadStream({ + // keys: [ + // 'alincoln', + // 'gwashington' + // ] + // }); + + //- + // Scan for row keys that contain a specific prefix. + //- + // table.createReadStream({ + // prefix: 'gwash' + // }); + + //- + // Specify a contiguous range of rows to read by supplying `start` and `end` + // keys. + // + // If the `start` key is omitted, it is interpreted as an empty string. + // If the `end` key is omitted, it is interpreted as infinity. + //- + // table.createReadStream({ + // start: 'alincoln', + // end: 'gwashington' + // }); + + //- + // Specify multiple ranges. + //- + // table.createReadStream({ + // ranges: [{ + // start: 'alincoln', + // end: 'gwashington' + // }, { + // start: 'tjefferson', + // end: 'jadams' + // }] + // }); + + //- + // Apply a {@link Filter} to the contents of the specified rows. + //- + // table.createReadStream({ + // filter: [ + // { + // column: 'gwashington' + // }, { + // value: 1 + // } + // ] + // }); + // + // [END bigtable_table_readstream] + }, + + sampleRowKeys: (instanceId, tableId) => { + const instance = bigtable.instance(instanceId); + const table = instance.table(tableId); + + // [START bigtable_sample_row_keys] + table + .sampleRowKeys() + .then(result => { + const sampleRKeys = result[0]; + }) + .catch(err => { + // Handle the error. + }); + // [END bigtable_sample_row_keys] + }, + + delRows: (instanceId, tableId) => { + const instance = bigtable.instance(instanceId); + const table = instance.table(tableId); + + // [START bigtable_del_rows] + table + .deleteRows('alincoln') + .then(result => { + const apiResponse = result[0]; + }) + .catch(err => { + // Handle the error. + }); + // [START bigtable_del_rows] + }, + + delTable: (instanceId, tableId) => { + const instance = bigtable.instance(instanceId); + const table = instance.table(tableId); + + // [START bigtable_del_table] + table + .delete() + .then(result => { + const apiResponse = result[0]; + }) + .catch(err => { + // Handle the error. + }); + // [END bigtable_del_table] + }, +}; + +module.exports = snippets; diff --git a/samples/document-snippets/tests/instance.js b/samples/document-snippets/tests/instance.js index 5e3cb5fe5..148bc9be5 100644 --- a/samples/document-snippets/tests/instance.js +++ b/samples/document-snippets/tests/instance.js @@ -31,90 +31,60 @@ const instanceSnippets = require('../instance.js'); describe('Instance Snippets', function() { after(function(done) { const instance = bigtable.instance(INSTANCE_ID); - instance.delete(done); - }); - - it('should create an instance', function(done) { - instanceSnippets.createInstance(INSTANCE_ID, CLUSTER_ID, err => { - assert.ifError(err); + instance.exists().then(result => { + const exists = result[0]; + if (exists) { + instance.delete(); + } done(); }); }); - // it('should create cluster', function(done) { - // instanceSnippets.createCluster(INSTANCE_ID, CLUSTER_ID, function(err, instance) { - // assert.ifError(err); - // done(); - // }); + it('should create an instance', () => { + instanceSnippets.createInstance(INSTANCE_ID, CLUSTER_ID); + }); + + // it('should create cluster', () => { + // instanceSnippets.createCluster(INSTANCE_ID, CLUSTER_ID); // }); // it('should create an app-profile', function(done) { - // instanceSnippets.createAppProfile(INSTANCE_ID, APP_PROFILE_ID, function(err, appProfile) { - // assert.ifError(err); - // done(); - // }); + // instanceSnippets.createAppProfile(INSTANCE_ID, APP_PROFILE_ID, done); // }); - it('should create table', function(done) { - instanceSnippets.createTable(INSTANCE_ID, TABLE_ID, err => { - assert.ifError(err); - done(); - }); + it('should create table', () => { + instanceSnippets.createTable(INSTANCE_ID, TABLE_ID); }); - it('should check instance existance', function(done) { - instanceSnippets.existsInstance(INSTANCE_ID, err => { - assert.ifError(err); - done(); - }); + it('should check instance existance', () => { + instanceSnippets.existsInstance(INSTANCE_ID); }); - it('should get instance', function(done) { - instanceSnippets.getInstance(INSTANCE_ID, err => { - assert.ifError(err); - done(); - }); + it('should get instance', () => { + instanceSnippets.getInstance(INSTANCE_ID); }); - it('should get Clusters', function(done) { - instanceSnippets.getClusters(INSTANCE_ID, err => { - assert.ifError(err); - done(); - }); + it('should get Clusters', () => { + instanceSnippets.getClusters(INSTANCE_ID); }); - // it('should get appProfiles', function(done) { - // instanceSnippets.getAppProfiles(INSTANCE_ID, err => { - // assert.ifError(err); - // done(); - // }); + // it('should get appProfiles', () => { + // instanceSnippets.getAppProfiles(INSTANCE_ID); // }); - it('should get MetaData', function(done) { - instanceSnippets.getMetaData(INSTANCE_ID, err => { - assert.ifError(err); - done(); - }); + it('should get metadata', () => { + instanceSnippets.getMetadata(INSTANCE_ID); }); - it('should get tables', function(done) { - instanceSnippets.getTables(INSTANCE_ID, err => { - assert.ifError(err); - done(); - }); + it('should get tables', () => { + instanceSnippets.getTables(INSTANCE_ID); }); - it('should update instance', function(done) { - instanceSnippets.updateInstance(INSTANCE_ID, err => { - assert.ifError(err); - done(); - }); + it('should update instance', () => { + instanceSnippets.updateInstance(INSTANCE_ID); }); - it('should delete instance', function(done) { - instanceSnippets.delInstance(INSTANCE_ID, err => { - assert.ifError(err); - done(); - }); + it('should delete instance', () => { + instanceSnippets.delInstance(INSTANCE_ID); }); }); diff --git a/samples/document-snippets/tests/table.js b/samples/document-snippets/tests/table.js new file mode 100644 index 000000000..30c7e0da4 --- /dev/null +++ b/samples/document-snippets/tests/table.js @@ -0,0 +1,101 @@ +/** + * Copyright 2016 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 tableSnippets = require('../table.js'); + +const instance = bigtable.instance(INSTANCE_ID); + +describe('Table Snippets', function() { + before(async () => { + await instance.create({ + clusters: [ + { + name: CLUSTER_ID, + location: 'us-central1-f', + storage: 'hdd', + }, + ], + type: 'DEVELOPMENT', + }); + }); + + after(async () => { + await instance.delete(); + }); + + it('should create a table', () => { + tableSnippets.createTable(INSTANCE_ID, TABLE_ID); + }); + + it('should check table exists', () => { + tableSnippets.existsTable(INSTANCE_ID, TABLE_ID); + }); + + it('should get the table', () => { + tableSnippets.getTable(INSTANCE_ID, TABLE_ID); + }); + + it('should get table metadata', () => { + tableSnippets.getMetadata(INSTANCE_ID, TABLE_ID); + }); + + it('should create family', () => { + tableSnippets.createFamily(INSTANCE_ID, TABLE_ID, 'follows'); + }); + + it('should get families', () => { + tableSnippets.getFamilies(INSTANCE_ID, TABLE_ID); + }); + + it('should insert row', () => { + tableSnippets.insertRows(INSTANCE_ID, TABLE_ID); + }); + + it('should get rows', () => { + tableSnippets.getRows(INSTANCE_ID, TABLE_ID); + }); + + it('should mutate table', () => { + tableSnippets.mutate(INSTANCE_ID, TABLE_ID); + }); + + it('should create a read-stream', () => { + tableSnippets.createReadStream(INSTANCE_ID, TABLE_ID); + }); + + it('should create sample row-keys', () => { + tableSnippets.sampleRowKeys(INSTANCE_ID, TABLE_ID); + }); + + // it('should delete rows', () => { + // tableSnippets.delRows(INSTANCE_ID, TABLE_ID); + // }); + + it('should delete table', () => { + tableSnippets.delTable(INSTANCE_ID, TABLE_ID); + }); +}); diff --git a/src/table.js b/src/table.js index 01facde06..eda4d4a32 100644 --- a/src/table.js +++ b/src/table.js @@ -147,20 +147,9 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.` * @param {?error} callback.err An error returned while making this request. * @param {Table} callback.table The newly created table. * @param {object} callback.apiResponse The full API response. - * @example - * table.create(function(err, table, apiResponse) { - * if (!err) { - * // The table was created successfully. - * } - * }); * - * //- - * // If the callback is omitted, we'll return a Promise. - * //- - * table.create().then(function(data) { - * var table = data[0]; - * var apiResponse = data[1]; - * }); + * @example include:samples/document-snippets/table.js + * region_tag:bigtable_create_table */ create(options, callback) { if (is.fn(options)) { @@ -201,49 +190,8 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.` * @param {Family} callback.family The newly created Family. * @param {object} callback.apiResponse The full API response. * - * @example - * const Bigtable = require('@google-cloud/bigtable'); - * const bigtable = new Bigtable(); - * const instance = bigtable.instance('my-instance'); - * const table = instance.table('prezzy'); - * - * const callback = function(err, family, apiResponse) { - * // `family` is a Family object - * }; - * - * const options={}; - * - * options.rule = { - * age: { - * seconds: 0, - * nanos: 5000 - * }, - * versions: 3, - * union: true - * }; - * - * table.createFamily('follows', options, callback); - * - * //- - * // If the callback is omitted, we'll return a Promise. - * //- - * table.createFamily('follows').then(function(data) { - * const family = data[0]; - * const apiResponse = data[1]; - * }); - * - * // Note that rules can have nested rules. For example The following rule - * // will delete cells that are either older than 10 versions OR if the cell - * // is is a month old and has at least 2 newer version. - * // Essentially: (version > 10 OR (age > 30 AND version > 2)) - * const rule = { - * union: true, - * versions: 10, - * rule: { - * versions: 2, - * age: { seconds: 60 * 60 * 24 * 30 }, // one month - * }, - * }; + * @example include:samples/document-snippets/table.js + * region_tag:bigtable_create_family */ createFamily(id, options, callback) { if (is.function(options)) { @@ -313,85 +261,8 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.` * @param {string} [options.start] Start value for key range. * @returns {stream} * - * @example - * const Bigtable = require('@google-cloud/bigtable'); - * const bigtable = new Bigtable(); - * const instance = bigtable.instance('my-instance'); - * const table = instance.table('prezzy'); - * - * table.createReadStream() - * .on('error', console.error) - * .on('data', function(row) { - * // `row` is a Row object. - * }) - * .on('end', function() { - * // All rows retrieved. - * }); - * - * //- - * // If you anticipate many results, you can end a stream early to prevent - * // unnecessary processing. - * //- - * table.createReadStream() - * .on('data', function(row) { - * this.end(); - * }); - * - * //- - * // Specify arbitrary keys for a non-contiguous set of rows. - * // The total size of the keys must remain under 1MB, after encoding. - * //- - * table.createReadStream({ - * keys: [ - * 'alincoln', - * 'gwashington' - * ] - * }); - * - * //- - * // Scan for row keys that contain a specific prefix. - * //- - * table.createReadStream({ - * prefix: 'gwash' - * }); - * - * //- - * // Specify a contiguous range of rows to read by supplying `start` and `end` - * // keys. - * // - * // If the `start` key is omitted, it is interpreted as an empty string. - * // If the `end` key is omitted, it is interpreted as infinity. - * //- - * table.createReadStream({ - * start: 'alincoln', - * end: 'gwashington' - * }); - * - * //- - * // Specify multiple ranges. - * //- - * table.createReadStream({ - * ranges: [{ - * start: 'alincoln', - * end: 'gwashington' - * }, { - * start: 'tjefferson', - * end: 'jadams' - * }] - * }); - * - * //- - * // Apply a {@link Filter} to the contents of the specified rows. - * //- - * table.createReadStream({ - * filter: [ - * { - * column: 'gwashington' - * }, { - * value: 1 - * } - * ] - * }); + * @example include:samples/document-snippets/table.js + * region_tag:bigtable_table_readstream */ createReadStream(options) { options = options || {}; @@ -591,15 +462,8 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.` * request. * @param {object} callback.apiResponse The full API response. * - * @example - * table.delete(function(err, apiResponse) {}); - * - * //- - * // If the callback is omitted, we'll return a Promise. - * //- - * table.delete().then(function(data) { - * var apiResponse = data[0]; - * }); + * @example include:samples/document-snippets/table.js + * region_tag:bigtable_del_table */ delete(gaxOptions, callback) { if (is.fn(gaxOptions)) { @@ -633,29 +497,8 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.` * @param {?error} callback.err An error returned while making this request. * @param {object} callback.apiResponse The full API response. * - * @example - * const Bigtable = require('@google-cloud/bigtable'); - * const bigtable = new Bigtable(); - * const instance = bigtable.instance('my-instance'); - * const table = instance.table('prezzy'); - * - * //- - * // You can supply a prefix to delete all corresponding rows. - * //- - * const callback = function(err, apiResponse) { - * if (!err) { - * // Rows successfully deleted. - * } - * }; - * - * table.deleteRows('alincoln', callback); - * - * //- - * // If the callback is omitted, we'll return a Promise. - * //- - * table.deleteRows('alincoln').then(function(data) { - * const apiResponse = data[0]; - * }); + * @example include:samples/document-snippets/table.js + * region_tag:bigtable_del_rows */ deleteRows(prefix, gaxOptions, callback) { if (is.function(gaxOptions)) { @@ -693,15 +536,8 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.` * request. * @param {boolean} callback.exists Whether the table exists or not. * - * @example - * table.exists(function(err, exists) {}); - * - * //- - * // If the callback is omitted, we'll return a Promise. - * //- - * table.exists().then(function(data) { - * var exists = data[0]; - * }); + * @example include:samples/document-snippets/table.js + * region_tag:bigtable_exists_table */ exists(gaxOptions, callback) { if (is.fn(gaxOptions)) { @@ -765,18 +601,8 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.` * @param {Table} callback.table The Table object. * @param {object} callback.apiResponse The resource as it exists in the API. * - * @example - * table.get(function(err, table, apiResponse) { - * // The `table` data has been populated. - * }); - * - * //- - * // If the callback is omitted, we'll return a Promise. - * //- - * table.get().then(function(data) { - * var table = data[0]; - * var apiResponse = data[0]; - * }); + * @example include:samples/document-snippets/table.js + * region_tag:bigtable_get_table */ get(options, callback) { if (is.fn(options)) { @@ -812,23 +638,8 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.` * @param {Family[]} callback.families The list of families. * @param {object} callback.apiResponse The full API response. * - * @example - * const Bigtable = require('@google-cloud/bigtable'); - * const bigtable = new Bigtable(); - * const instance = bigtable.instance('my-instance'); - * const table = instance.table('prezzy'); - * - * table.getFamilies(function(err, families, apiResponse) { - * // `families` is an array of Family objects. - * }); - * - * //- - * // If the callback is omitted, we'll return a Promise. - * //- - * table.getFamilies().then(function(data) { - * var families = data[0]; - * var apiResponse = data[1]; - * }); + * @example include:samples/document-snippets/table.js + * region_tag:bigtable_get_families */ getFamilies(gaxOptions, callback) { if (is.fn(gaxOptions)) { @@ -914,21 +725,8 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.` * request. * @param {object} callback.metadata The table's metadata. * - * @example - * const Bigtable = require('@google-cloud/bigtable'); - * const bigtable = new Bigtable(); - * const instance = bigtable.instance('my-instance'); - * const table = instance.table('prezzy'); - * - * table.getMetadata(function(err, metadata) {}); - * - * //- - * // If the callback is omitted, we'll return a Promise. - * //- - * table.getMetadata().then(function(data) { - * var metadata = data[0]; - * var apiResponse = data[1]; - * }); + * @example include:samples/document-snippets/table.js + * region_tag:bigtable_get_table_meta */ getMetadata(options, callback) { if (is.function(options)) { @@ -973,24 +771,8 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.` * @param {?error} callback.err An error returned while making this request. * @param {Row[]} callback.rows List of Row objects. * - * @example - * const Bigtable = require('@google-cloud/bigtable'); - * const bigtable = new Bigtable(); - * const instance = bigtable.instance('my-instance'); - * const table = instance.table('prezzy'); - * - * table.getRows(function(err, rows) { - * if (!err) { - * // `rows` is an array of Row objects. - * } - * }); - * - * //- - * // If the callback is omitted, we'll return a Promise. - * //- - * table.getRows().then(function(data) { - * var rows = data[0]; - * }); + * @example include:samples/document-snippets/table.js + * region_tag:bigtable_get_rows */ getRows(options, callback) { if (is.function(options)) { @@ -1022,66 +804,8 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.` * failures. It's possible for part of your request to be completed * successfully, while the other part was not. * - * @example - * const Bigtable = require('@google-cloud/bigtable'); - * const bigtable = new Bigtable(); - * const instance = bigtable.instance('my-instance'); - * const table = instance.table('prezzy'); - * - * const callback = function(err) { - * if (err) { - * // An API error or partial failure occurred. - * - * if (err.name === 'PartialFailureError') { - * // err.errors[].code = 'Response code' - * // err.errors[].message = 'Error message' - * // err.errors[].entry = The original entry - * } - * } - * }; - * - * const entries = [ - * { - * key: 'alincoln', - * data: { - * follows: { - * gwashington: 1 - * } - * } - * } - * ]; - * - * table.insert(entries, callback); - * - * //- - * // By default whenever you insert new data, the server will capture a - * // timestamp of when your data was inserted. It's possible to provide a - * // date object to be used instead. - * //- - * const entries = [ - * { - * key: 'gwashington', - * data: { - * follows: { - * jadams: { - * value: 1, - * timestamp: new Date('March 22, 2016') - * } - * } - * } - * } - * ]; - * - * table.insert(entries, callback); - * - * - * //- - * // If the callback is omitted, we'll return a Promise. - * //- - * table.insert(entries).then(function() { - * // All requested inserts have been processed. - * }); - * //- + * @example include:samples/document-snippets/table.js + * region_tag:bigtable_insert_rows */ insert(entries, gaxOptions, callback) { if (is.fn(gaxOptions)) { @@ -1114,98 +838,8 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.` * failures. It's possible for part of your request to be completed * successfully, while the other part was not. * - * @example - * const Bigtable = require('@google-cloud/bigtable'); - * const bigtable = new Bigtable(); - * const instance = bigtable.instance('my-instance'); - * const table = instance.table('prezzy'); - * - * //- - * // Insert entities. See {@link Table#insert}. - * //- - * const callback = function(err) { - * if (err) { - * // An API error or partial failure occurred. - * - * if (err.name === 'PartialFailureError') { - * // err.errors[].code = 'Response code' - * // err.errors[].message = 'Error message' - * // err.errors[].entry = The original entry - * } - * } - * }; - * - * const entries = [ - * { - * method: 'insert', - * key: 'gwashington', - * data: { - * follows: { - * jadams: 1 - * } - * } - * } - * ]; - * - * table.mutate(entries, callback); - * - * //- - * // Delete entities. See {@link Row#deleteCells}. - * //- - * const entries = [ - * { - * method: 'delete', - * key: 'gwashington' - * } - * ]; - * - * table.mutate(entries, callback); - * - * //- - * // Delete specific columns within a row. - * //- - * const entries = [ - * { - * method: 'delete', - * key: 'gwashington', - * data: [ - * 'follows:jadams' - * ] - * } - * ]; - * - * table.mutate(entries, callback); - * - * //- - * // Mix and match mutations. This must contain at least one entry and at - * // most 100,000. - * //- - * const entries = [ - * { - * method: 'insert', - * key: 'alincoln', - * data: { - * follows: { - * gwashington: 1 - * } - * } - * }, { - * method: 'delete', - * key: 'jadams', - * data: [ - * 'follows:gwashington' - * ] - * } - * ]; - * - * table.mutate(entries, callback); - * - * //- - * // If the callback is omitted, we'll return a Promise. - * //- - * table.mutate(entries).then(function() { - * // All requested mutations have been processed. - * }); + * @example include:samples/document-snippets/table.js + * region_tag:bigtable_mutate_rows */ mutate(entries, options, callback) { options = options || {}; @@ -1337,23 +971,8 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.` * @param {?error} callback.err An error returned while making this request. * @param {object[]} callback.keys The list of keys. * - * @example - * table.sampleRowKeys(function(err, keys) { - * // keys = [ - * // { - * // key: '', - * // offset: '805306368' - * // }, - * // ... - * // ] - * }); - * - * //- - * // If the callback is omitted, we'll return a Promise. - * //- - * table.sampleRowKeys().then(function(data) { - * var keys = data[0]; - * }); + * @example include:samples/document-snippets/table.js + * region_tag:bigtable_sample_row_keys */ sampleRowKeys(gaxOptions, callback) { if (is.fn(gaxOptions)) {