Constructor

Instance

new Instance(bigtable, id)

Parameter

bigtable

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

AppProfile 

cluster

cluster(id) returns Cluster

Get a reference to a Bigtable Cluster.

Parameter

id

string

The id of the cluster.

Returns

Cluster 

create

create(options, callback)

Create an instance.

Parameter

options

object

See Bigtable#createInstance.

Values in options have the following properties:

Parameter

gaxOptions

Optional

object

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.

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.

instance

Instance

The newly created instance.

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');

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

Parameter

routing

('any' or Cluster)

The routing policy for all read/write requests which use this app profile. This can be either the string 'any' or a cluster of an instance. This value is required when creating the app profile and optional when setting the metadata.

gaxOptions

Optional

object

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.

allowTransactionalWrites

Optional

boolean

Whether or not CheckAndMutateRow and ReadModifyWriteRow requests are allowed by this app profile. It is unsafe to send these requests to the same table/row/column in multiple clusters. This is only used when the routing value is a cluster.

description

Optional

string

The long form description of the use case for this AppProfile.

ignoreWarnings

Optional

string

Whether to ignore safety checks when creating the app profile

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.

appProfile

Cluster

The newly created app profile.

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

Parameter

gaxOptions

Optional

object

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.

location

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

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.

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

Parameter

families

Optional

(object or Array of string)

Column families to be created within the table.

gaxOptions

Optional

object

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

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

Parameter

error

error

An error returned while making this request.

Value may be null.

instance

Instance

The Instance object.

apiResponse

object

The resource as it exists in the API.

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

Parameter

error

error

An error returned while making this request.

Value may be null.

appProfiles

Array of AppProfile

List of all AppProfiles.

apiResponse

object

The full API response.

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 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.
  }
});

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

Parameter

err

error

An error returned while making this request.

Value may be null.

metadata

object

The metadata.

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

Parameter

autoPaginate

Optional

boolean

Have pagination handled automatically.

gaxOptions

Optional

object

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.

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, gaxOptions, 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.

gaxOptions

Optional

object

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.

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(id) returns Table

Get a reference to a Bigtable table.

Parameter

id

string

Unique identifier 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');