-
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
- Loading branch information
1 parent
4bfd84e
commit ad72fc3
Showing
3 changed files
with
233 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,128 @@ | ||
/** | ||
* 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 = { | ||
createColmFamily: (instanceId, tableId, familyId, callback) => { | ||
const instance = bigtable.instance(instanceId); | ||
const table = instance.table(tableId); | ||
const family = table.family(familyId); | ||
// [START bigtable_create_family] | ||
family | ||
.create() | ||
.then(result => { | ||
const family = result[0]; | ||
// let apiResponse = result[1]; | ||
callback(null, family); | ||
}) | ||
.catch(err => { | ||
callback(err); | ||
}); | ||
// [END bigtable_create_family] | ||
}, | ||
existsFamily: (instanceId, tableId, familyId, callback) => { | ||
const instance = bigtable.instance(instanceId); | ||
const table = instance.table(tableId); | ||
const family = table.family(familyId); | ||
|
||
// [START bigtable_exists_family] | ||
family | ||
.exists() | ||
.then(result => { | ||
const exists = result[0]; | ||
callback(null, exists); | ||
}) | ||
.catch(err => { | ||
callback(err); | ||
}); | ||
// [END bigtable_exists_family] | ||
}, | ||
getFamily: (instanceId, tableId, familyId, callback) => { | ||
const instance = bigtable.instance(instanceId); | ||
const table = instance.table(tableId); | ||
const family = table.family(familyId); | ||
// [START bigtable_get_family] | ||
family | ||
.get() | ||
.then(result => { | ||
const family = result[0]; | ||
// const apiResponse = result[1]; | ||
callback(null, family); | ||
}) | ||
.catch(err => { | ||
callback(err); | ||
}); | ||
// [END bigtable_get_family] | ||
}, | ||
getMetaData: (instanceId, tableId, familyId, callback) => { | ||
const instance = bigtable.instance(instanceId); | ||
const table = instance.table(tableId); | ||
const family = table.family(familyId); | ||
// [START bigtable_get_family_meta] | ||
family | ||
.getMetadata() | ||
.then(result => { | ||
const metaData = result[0]; | ||
// const apiResponse = result[1]; | ||
callback(null, metaData); | ||
}) | ||
.catch(err => { | ||
callback(err); | ||
}); | ||
// [END bigtable_get_family_meta] | ||
}, | ||
setMetaData: (instanceId, tableId, familyId, callback) => { | ||
const instance = bigtable.instance(instanceId); | ||
const table = instance.table(tableId); | ||
const family = table.family(familyId); | ||
// [START bigtable_set_family_meta] | ||
var metadata = { | ||
rule: { | ||
versions: 2, | ||
union: true, | ||
}, | ||
}; | ||
family | ||
.setMetadata(metadata) | ||
.then(result => { | ||
const apiResponse = result[0]; | ||
callback(null, apiResponse); | ||
}) | ||
.catch(err => { | ||
callback(err); | ||
}); | ||
// [END bigtable_set_family_meta] | ||
}, | ||
delFamily: (instanceId, tableId, familyId, callback) => { | ||
const instance = bigtable.instance(instanceId); | ||
const table = instance.table(tableId); | ||
const family = table.family(familyId); | ||
// [START bigtable_del_family] | ||
family | ||
.delete() | ||
.then(result => { | ||
const apiResponse = result[0]; | ||
callback(null, apiResponse); | ||
}) | ||
.catch(err => { | ||
callback(err); | ||
}); | ||
// [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,93 @@ | ||
/** | ||
* 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 FAMILY_ID = `nodejs-bigtable-samples-${uuid.v4()}`.substr(0, 30); // 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', function(done) { | ||
familySnippets.createColmFamily(INSTANCE_ID, TABLE_ID, FAMILY_ID, err => { | ||
assert.ifError(err); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should check family exists', function(done) { | ||
familySnippets.existsFamily(INSTANCE_ID, TABLE_ID, FAMILY_ID, err => { | ||
assert.ifError(err); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should get the family', function(done) { | ||
familySnippets.getFamily(INSTANCE_ID, TABLE_ID, FAMILY_ID, err => { | ||
assert.ifError(err); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should get family meta-data', function(done) { | ||
familySnippets.getMetaData(INSTANCE_ID, TABLE_ID, FAMILY_ID, err => { | ||
assert.ifError(err); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should set family meta-data', function(done) { | ||
familySnippets.setMetaData(INSTANCE_ID, TABLE_ID, FAMILY_ID, err => { | ||
assert.ifError(err); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should delete family', function(done) { | ||
familySnippets.delFamily(INSTANCE_ID, TABLE_ID, FAMILY_ID, err => { | ||
assert.ifError(err); | ||
done(); | ||
}); | ||
}); | ||
}); |
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