Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added example region-tag for Family.js #262

Merged
merged 16 commits into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions samples/document-snippets/family.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* 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 = {
createColmFamily: (instanceId, tableId, familyId) => {
// [START bigtable_create_family]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const table = instance.table(tableId);
const family = table.family(familyId);

family
.create()
.then(result => {
const family = result[0];
// let apiResponse = result[1];
})
.catch(err => {
// Handle the error.
});
// [END bigtable_create_family]
},
existsFamily: (instanceId, tableId, familyId) => {
// [START bigtable_exists_family]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const table = instance.table(tableId);
const family = table.family(familyId);

family
.exists()
.then(result => {
const exists = result[0];
})
.catch(err => {
// Handle the error.
});
// [END bigtable_exists_family]
},
getFamily: (instanceId, tableId, familyId) => {
// [START bigtable_get_family]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const table = instance.table(tableId);
const family = table.family(familyId);

family
.get()
.then(result => {
const family = result[0];
// const apiResponse = result[1];
})
.catch(err => {
// Handle the error.
});
// [END bigtable_get_family]
},
getMetadata: (instanceId, tableId, familyId) => {
// [START bigtable_get_family_meta]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const table = instance.table(tableId);
const family = table.family(familyId);

family
.getMetadata()
.then(result => {
const metaData = result[0];
// const apiResponse = result[1];
})
.catch(err => {
// Handle the error.
});
// [END bigtable_get_family_meta]
},
setMetadata: (instanceId, tableId, familyId) => {
// [START bigtable_set_family_meta]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const table = instance.table(tableId);
const family = table.family(familyId);

const metadata = {
rule: {
versions: 2,
union: true,
},
};

family
.setMetadata(metadata)
.then(result => {
const apiResponse = result[0];
})
.catch(err => {
// Handle the error.
});
// [END bigtable_set_family_meta]
},
delFamily: (instanceId, tableId, familyId) => {
// [START bigtable_del_family]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const table = instance.table(tableId);
const family = table.family(familyId);

family
.delete()
.then(result => {
const apiResponse = result[0];
})
.catch(err => {
// Handle the error.
});
// [END bigtable_del_family]
},
};

module.exports = snippets;
75 changes: 75 additions & 0 deletions samples/document-snippets/tests/family.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* 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 FAMILY_ID = `sample-family-${uuid.v4()}`.substr(0, 10); // Bigtable naming rules

const familySnippets = require('../family.js');

const instance = bigtable.instance(INSTANCE_ID);

describe('Family 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 column family', () => {
familySnippets.createColmFamily(INSTANCE_ID, TABLE_ID, FAMILY_ID);
});

it('should check family exists', () => {
familySnippets.existsFamily(INSTANCE_ID, TABLE_ID, FAMILY_ID);
});

it('should get the family', () => {
familySnippets.getFamily(INSTANCE_ID, TABLE_ID, FAMILY_ID);
});

it('should get family metadata', () => {
familySnippets.getMetadata(INSTANCE_ID, TABLE_ID, FAMILY_ID);
});

it('should set family metadata', () => {
familySnippets.setMetadata(INSTANCE_ID, TABLE_ID, FAMILY_ID);
});

it('should delete family', () => {
familySnippets.delFamily(INSTANCE_ID, TABLE_ID, FAMILY_ID);
});
});
80 changes: 12 additions & 68 deletions src/family.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,8 @@ Please use the format 'follows' or '${table.name}/columnFamilies/my-family'.`
* @param {Family} callback.family The metadata.
* @param {object} callback.apiResponse The full API response.
*
* @example
* family.create(function(err, family, apiResponse) {
* // The column family was created successfully.
* });
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* family.create().then(function(data) {
* const family = data[0];
* const apiResponse = data[1];
* });
* @example <caption>include:samples/document-snippets/family.js</caption>
* region_tag:bigtable_create_family
*/
create(options, callback) {
if (is.fn(options)) {
Expand All @@ -182,15 +172,8 @@ Please use the format 'follows' or '${table.name}/columnFamilies/my-family'.`
* request.
* @param {object} callback.apiResponse The full API response.
*
* @example
* family.delete(function(err, apiResponse) {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* family.delete().then(function(data) {
* const apiResponse = data[0];
* });
* @example <caption>include:samples/document-snippets/family.js</caption>
* region_tag:bigtable_del_family
*/
delete(gaxOptions, callback) {
if (is.fn(gaxOptions)) {
Expand Down Expand Up @@ -227,15 +210,8 @@ Please use the format 'follows' or '${table.name}/columnFamilies/my-family'.`
* request.
* @param {boolean} callback.exists Whether the family exists or not.
*
* @example
* family.exists(function(err, exists) {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* family.exists().then(function(data) {
* const exists = data[0];
* });
* @example <caption>include:samples/document-snippets/family.js</caption>
* region_tag:bigtable_exists_family
*/
exists(gaxOptions, callback) {
if (is.fn(gaxOptions)) {
Expand Down Expand Up @@ -275,18 +251,8 @@ Please use the format 'follows' or '${table.name}/columnFamilies/my-family'.`
* @param {Family} callback.family The Family object.
* @param {object} callback.apiResponse The resource as it exists in the API.
*
* @example
* family.get(function(err, family, apiResponse) {
* // `family.metadata` has been populated.
* });
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* family.get().then(function(data) {
* const family = data[0];
* const apiResponse = data[1];
* });
* @example <caption>include:samples/document-snippets/family.js</caption>
* region_tag:bigtable_get_family
*/
get(options, callback) {
if (is.fn(options)) {
Expand Down Expand Up @@ -322,16 +288,8 @@ Please use the format 'follows' or '${table.name}/columnFamilies/my-family'.`
* request.
* @param {object} callback.metadata The metadata.
*
* @example
* family.getMetadata(function(err, metadata, apiResponse) {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* family.getMetadata().then(function(data) {
* var metadata = data[0];
* var apiResponse = data[1];
* });
* @example <caption>include:samples/document-snippets/family.js</caption>
* region_tag:bigtable_get_family_meta
*/
getMetadata(gaxOptions, callback) {
if (is.fn(gaxOptions)) {
Expand Down Expand Up @@ -375,22 +333,8 @@ Please use the format 'follows' or '${table.name}/columnFamilies/my-family'.`
* request.
* @param {object} callback.apiResponse The full API response.
*
* @example
* var metadata = {
* rule: {
* versions: 2,
* union: true
* }
* };
*
* family.setMetadata(metadata, function(err, apiResponse) {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* family.setMetadata(metadata).then(function(data) {
* var apiResponse = data[0];
* });
* @example <caption>include:samples/document-snippets/family.js</caption>
* region_tag:bigtable_set_family_meta
*/
setMetadata(metadata, gaxOptions, callback) {
if (is.fn(gaxOptions)) {
Expand Down