Skip to content

Commit

Permalink
Added @example tags to src/table.js (#239)
Browse files Browse the repository at this point in the history
* added example tags for tabe.js

* fixed lint issues

* updated table sample snippets and related test cases

* Added changes for review-comment

* callback removed from promise-style code-snippets within region-tags

* callback removed from promise-style code-snippets within region-tags

* used done only

* used done only

* update for non-promise function

* update for non-promise function

* added fix as per review comments

* added fix as per review comments

* removed callbacks

* removed callbacks

* Updating instance.js snippets

Always using `require` in the snippet, and including it within the tag.

* fix for lint error

* removed unused <caughtError> constant
  • Loading branch information
vijay-qlogic authored and sduskis committed Oct 12, 2018
1 parent 58457b7 commit b0917e5
Show file tree
Hide file tree
Showing 5 changed files with 550 additions and 545 deletions.
139 changes: 61 additions & 78 deletions samples/document-snippets/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,51 +52,47 @@ 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 = {
// location: 'us-central1-b',
// 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 = {
Expand All @@ -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 = {
Expand Down Expand Up @@ -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.
Expand All @@ -268,54 +257,48 @@ 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',
};

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]
},
Expand Down
Loading

0 comments on commit b0917e5

Please sign in to comment.