Instance
Create an Instance object to interact with a Cloud Bigtable instance.
Constructor
Instance
new Instance(bigtable, id)
Parameter |
|
---|---|
bigtable |
The parent Bigtable object of this instance. |
id |
string Id of the instance. |
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
Property
getTablesStream
Get Table objects for all the tables in your Cloud Bigtable instance as a readable object stream.
Parameter |
|
---|---|
query |
Optional object Configuration object. See Instance#getTables for a complete list of options. |
- Returns
-
stream
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
instance.getTablesStream()
.on('error', console.error)
.on('data', function(table) {
// table is a Table object.
})
.on('end', function() {
// All tables retrieved.
});
//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
instance.getTablesStream()
.on('data', function(table) {
this.end();
});
Methods
appProfile
appProfile(name) returns AppProfile
Get a reference to a Bigtable App Profile.
Parameter |
|
---|---|
name |
string The name of the app profile. |
- Returns
cluster
cluster(id) returns Cluster
Get a reference to a Bigtable Cluster.
Parameter |
|
---|---|
id |
string The id of the cluster. |
- Returns
create
create(options, callback)
Create an instance.
Parameter |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
options |
object Values in
|
||||||||||
callback |
function() The callback function. Values in
|
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
instance.create(function(err, instance, operation, apiResponse) {
if (err) {
// Error handling omitted.
}
operation
.on('error', console.error)
.on('complete', function() {
// The instance was created successfully.
});
});
//-
// If the callback is omitted, we'll return a Promise.
//-
instance.create().then(function(data) {
var instance = data[0];
var operation = data[1];
var apiResponse = data[2];
});
createAppProfile
createAppProfile(id, options, callback)
Create an app profile.
Parameter |
|||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
string The name to be used when referring to the new app profile within its instance. |
||||||||||||
options |
object AppProfile creation options. Values in
|
||||||||||||
callback |
function() The callback function. Values in
|
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
const cluster = instance.cluster('my-cluster');
const callback = function(err, appProfile, apiResponse) {
// `appProfile` is an AppProfile object.
};
const options = {
routing: cluster,
allowTransactionalWrites: true,
ignoreWarnings: true,
};
instance.createAppProfile('my-app-profile', options, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
instance.createAppProfile('my-app-profile', options).then(function(data) {
const appProfile = data[0];
const apiResponse = data[1];
});
createCluster
createCluster(id, options, callback)
Create a cluster.
Parameter |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
id |
string The id to be used when referring to the new cluster within its instance. |
||||||||||
options |
object Cluster creation options. Values in
|
||||||||||
callback |
function() The callback function. Values in
|
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
const callback = function(err, cluster, operation, apiResponse) {
if (err) {
// Error handling omitted.
}
operation
.on('error', console.log)
.on('complete', function() {
// The cluster was created successfully.
});
};
const options = {
location: 'us-central1-b',
nodes: 3,
storage: 'ssd'
};
instance.createCluster('my-cluster', options, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
instance.createCluster('my-cluster', options).then(function(data) {
const cluster = data[0];
const operation = data[1];
const apiResponse = data[2];
});
createTable
createTable(id, options, callback)
Create a table on your Bigtable instance.
Parameter |
|||||||||
---|---|---|---|---|---|---|---|---|---|
id |
string Unique identifier of the table. |
||||||||
options |
Optional object Table creation options. Values in
|
||||||||
callback |
function() The callback function. Values in
|
- See also
- Throws
-
error
If a id is not provided.
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
const callback = function(err, table, apiResponse) {
// `table` is a Table object.
};
instance.createTable('prezzy', callback);
//-
// Optionally specify column families to be created within the table.
//-
const options = {
families: ['follows']
};
instance.createTable('prezzy', options, callback);
//-
// You can also specify garbage collection rules for your column families.
// See {@link Table#createFamily} for more information about
// column families and garbage collection rules.
//-
const options = {
families: [
{
name: 'follows',
rule: {
age: {
seconds: 0,
nanos: 5000
},
versions: 3,
union: true
}
}
]
};
instance.createTable('prezzy', options, callback);
//-
// Pre-split the table based on the row key to spread the load across
// multiple Cloud Bigtable nodes.
//-
const options = {
splits: ['10', '20']
};
instance.createTable('prezzy', options, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
instance.createTable('prezzy', options).then(function(data) {
const table = data[0];
const apiResponse = data[1];
});
delete
delete(gaxOptions, callback)
Delete the instance.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
gaxOptions |
Optional object Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||
callback |
Optional function() The callback function. Values in
|
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
instance.delete(function(err, apiResponse) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
instance.delete().then(function(data) {
var apiResponse = data[0];
});
exists
exists(gaxOptions, callback)
Check if an instance exists.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
gaxOptions |
Optional object Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||
callback |
function() The callback function. Values in
|
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
instance.exists(function(err, exists) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
instance.exists().then(function(data) {
var exists = data[0];
});
get
get(gaxOptions, callback)
Get an instance if it exists.
Parameter |
|||||||||
---|---|---|---|---|---|---|---|---|---|
gaxOptions |
Optional object Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||||
callback |
function() The callback function. Values in
|
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
instance.get(function(err, instance, apiResponse) {
// The `instance` data has been populated.
});
//-
// If the callback is omitted, we'll return a Promise.
//-
instance.get().then(function(data) {
var instance = data[0];
var apiResponse = data[1];
});
getAppProfiles
getAppProfiles(gaxOptions, callback)
Get App Profile objects for this instance.
Parameter |
|||||||||
---|---|---|---|---|---|---|---|---|---|
gaxOptions |
Optional object Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||||
callback |
function() The callback function. Values in
|
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
instance.getAppProfiles(function(err, appProfiles) {
if (!err) {
// `appProfiles` is an array of AppProfile objects.
}
});
//-
// If the callback is omitted, we'll return a Promise.
//-
instance.getAppProfiles().then(function(data) {
const appProfiles = data[0];
});
getClusters
getClusters(gaxOptions, callback)
Get Cluster objects for all of your clusters.
Parameter |
|||||||||
---|---|---|---|---|---|---|---|---|---|
gaxOptions |
Optional object Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||||
callback |
function() The callback function. Values in
|
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
instance.getClusters(function(err, clusters) {
if (!err) {
// `clusters` is an array of Cluster objects.
}
});
//-
// If the callback is omitted, we'll return a Promise.
//-
instance.getClusters().then(function(data) {
const clusters = data[0];
});
getMetadata
getMetadata(gaxOptions, callback)
Get the instance metadata.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
gaxOptions |
Optional object Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||
callback |
function() The callback function. Values in
|
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
instance.getMetadata(function(err, metadata) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
instance.getMetadata().then(function(data) {
var metadata = data[0];
var apiResponse = data[1];
});
getTables
getTables(options, callback)
Get Table objects for all the tables in your Cloud Bigtable instance.
Parameter |
|||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Optional object Query object. Values in
|
||||||||||||||
callback |
function() The callback function. Values in
|
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
instance.getTables(function(err, tables) {
if (!err) {
// `tables` is an array of Table objects.
}
});
//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to false.
//-
const callback = function(err, tables, nextQuery, apiResponse) {
if (nextQuery) {
// More results exist.
instance.getTables(nextQuery, calback);
}
};
instance.getTables({
autoPaginate: false
}, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
instance.getTables().then(function(data) {
const tables = data[0];
});
setMetadata
setMetadata(metadata, gaxOptions, callback)
Set the instance metadata.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
metadata |
object Metadata object. Values in
|
||||||
gaxOptions |
Optional object Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions. |
||||||
callback |
function() The callback function. Values in
|
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
var metadata = {
displayName: 'updated-name'
};
instance.setMetadata(metadata, function(err, apiResponse) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
instance.setMetadata(metadata).then(function(data) {
var apiResponse = data[0];
});
table
table(id) returns Table
Get a reference to a Bigtable table.
Parameter |
|
---|---|
id |
string Unique identifier of the table. |
- Returns
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
const table = instance.table('presidents');