-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example region-tag for Family.js (#262)
* Added example region-tag for Family.js * callback removed from promise-style code-snippets within region-tags * minor fix * sample ID updated * Added review updates * removed callbacks * rebased with master and code-review update * code review updates
- Loading branch information
1 parent
a323760
commit 41d6d68
Showing
3 changed files
with
224 additions
and
68 deletions.
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 |
---|---|---|
@@ -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; |
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,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); | ||
}); | ||
}); |
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