Instance
Constructor
Instance
new Instance(bigtable, name)
Create an Instance object to interact with a Compute instance.
Parameter |
|
---|---|
bigtable |
The parent Bigtable object of this instance. |
name |
string Name of the instance. |
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
Properties
getClustersStream
Get Cluster objects for all of your clusters as a readable object stream.
Parameter |
|
---|---|
query |
Optional object Configuration object. See Instance#getClusters for a complete list of options. |
- Returns
-
stream
Example
instance.getClustersStream()
.on('error', console.error)
.on('data', function(cluster) {
// `cluster` is a Cluster object.
})
.on('end', function() {
// All clusters retrieved.
});
//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
instance.getClustersStream()
.on('data', function(cluster) {
this.end();
});
getTablesStream
Get Table objects for all the tables in your Compute 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
cluster
cluster(name) returns Cluster
Get a reference to a Bigtable Cluster.
Parameter |
|
---|---|
name |
string The name of the cluster. |
- Returns
create
create(options)
Create an instance.
Parameter |
|
---|---|
options |
Optional object |
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];
});
createCluster
createCluster(name, options, callback)
Create a cluster.
Parameter |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
name |
string The name to be used when referring to the new cluster within its instance. |
||||||||||
options |
Optional 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(name, options, callback)
Create a table on your Bigtable instance.
Parameter |
|||||||||
---|---|---|---|---|---|---|---|---|---|
name |
string The name of the table. |
||||||||
options |
Optional object Table creation options. Values in
|
||||||||
callback |
function() The callback function. Values in
|
- See also
- Throws
-
error
If a name 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(callback)
Delete the instance.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
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(callback)
Check if an instance exists.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
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()
Get an instance if it exists.
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];
});
getClusters
getClusters(query, callback)
Get Cluster objects for all of your clusters.
Parameter |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
query |
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.getClusters(function(err, clusters) {
if (!err) {
// `clusters` is an array of Cluster objects.
}
});
//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to false.
//-
const callback = function(err, clusters, nextQuery, apiResponse) {
if (nextQuery) {
// More results exist.
instance.getClusters(nextQuery, calback);
}
};
instance.getClusters({
autoPaginate: false
}, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
instance.getClusters().then(function(data) {
const clusters = data[0];
});
getMetadata
getMetadata(callback)
Get the instance metadata.
Parameter |
|||||||||
---|---|---|---|---|---|---|---|---|---|
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, apiResponse) {});
//-
// 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(query, callback)
Get Table objects for all the tables in your Compute instance.
Parameter |
|||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
query |
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, callback)
Set the instance metadata.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
metadata |
object Metadata 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');
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(name) returns Table
Get a reference to a Bigtable table.
Parameter |
|
---|---|
name |
string The name 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');