Constructor

Instance

new Instance(bigtable, name)

Create an Instance object to interact with a Compute instance.

Parameter

bigtable

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

Cluster 

create

create(options)

Create an instance.

Parameter

options

Optional

object

See Bigtable#createInstance.

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 options have the following properties:

Parameter

location

Optional

string

The location where this cluster's nodes and storage reside. For best performance clients should be located as as close as possible to this cluster. Currently only zones are supported.

nodes

Optional

number

The number of nodes allocated to this cluster. More nodes enable higher throughput and more consistent performance.

storage

Optional

string

The type of storage used by this cluster to serve its parent instance's tables. Options are 'hdd' or 'ssd'.

callback

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

cluster

Cluster

The newly created cluster.

operation

Operation

An operation object that can be used to check the status of the request.

apiResponse

object

The full API response.

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 options have the following properties:

Parameter

families

Optional

(object or Array of string)

Column families to be created within the table.

splits

Optional

Array of string

Initial split keys.

callback

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

table

Table

The newly created table.

apiResponse

object

The full API response.

See also

Designing Your Schema

Splitting Keys

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 callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

apiResponse

object

The full API response.

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 callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

exists

boolean

Whether the instance exists or not.

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 query have the following properties:

Parameter

autoPaginate

Optional

boolean

Have pagination handled automatically.

maxApiCalls

Optional

number

Maximum number of API calls to make.

maxResults

Optional

number

Maximum number of results to return.

pageToken

Optional

string

Token returned from a previous call, to request the next page of results.

callback

function()

The callback function.

Values in callback have the following properties:

Parameter

error

error

An error returned while making this request.

Value may be null.

clusters

Array of Cluster

List of all Clusters.

apiResponse

object

The full API response.

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 callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

metadata

object

The metadata.

apiResponse

object

The full API response.

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 query have the following properties:

Parameter

autoPaginate

Optional

boolean

Have pagination handled automatically.

maxApiCalls

Optional

number

Maximum number of API calls to make.

maxResults

Optional

number

Maximum number of items to return.

pageToken

Optional

string

A previously-returned page token representing part of a larger set of results to view.

view

Optional

string

View over the table's fields. Possible options are 'name', 'schema' or 'full'. Default: 'name'.

callback

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

tables

Array of Table

List of all Tables.

apiResponse

object

The full API response.

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 metadata have the following properties:

Parameter

displayName

string

The descriptive name for this instance as it appears in UIs. It can be changed at any time, but should be kept globally unique to avoid confusion.

callback

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

apiResponse

object

The full API response.

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

Table 

Example

const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
const table = instance.table('presidents');