new Bigtable([options])

Examples

<caption>Create a client that uses <a
href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application
Default Credentials (ADC)</a>:</caption> const Bigtable =
require('@google-cloud/bigtable'); const bigtable = new Bigtable();
<caption>Create a client with <a
href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit
credentials</a>:</caption> const Bigtable =
require('@google-cloud/bigtable'); const bigtable = new Bigtable({ projectId:
'your-project-id', keyFilename: '/path/to/keyfile.json'
});
//<h4> The Bigtable Emulator</h4>
//
// Make sure you have the <a href="https://cloud.google.com/sdk/downloads">
// gcloud SDK installed</a>, then run:
//
// <pre>
//   $ gcloud beta emulators bigtable start
// </pre>
//
// Before running your Node.js app, set the environment variables that this
// library will look for to connect to the emulator:
//
// <pre>
//   $ $(gcloud beta emulators bigtable env-init)
// </pre>
//-

//-
// <h4>Creating a Bigtable Instance and Cluster</h4>
//
// Before you create your table, you first need to create a Bigtable Instance
// and cluster for the table to be served from.
//-
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();

const callback = function(err, instance, operation) {
  operation
    .on('error', console.log)
    .on('complete', function() {
      // `instance` is your newly created Instance object.
    });
};

const instance = bigtable.instance('my-instance');

instance.create({
  clusters: [
    {
      id: 'my-cluster',
      location: 'us-central1-b',
      nodes: 3
    }
  ]
}, callback);

//-
// This can also be done from either the Google Cloud Platform Console or the
// `gcloud` cli tool. Please refer to the
// <a href="https://cloud.google.com/bigtable/docs/creating-instance">
// official Bigtable documentation</a> for more information.
//-

//-
// <h4>Creating Tables</h4>
//
// After creating your instance and enabling the Bigtable APIs, you are now
// ready to create your table with {@link Instance#createTable}.
//-
instance.createTable('prezzy', function(err, table) {
  // `table` is your newly created Table object.
});

//-
// <h4>Creating Column Families</h4>
//
// Column families are used to group together various pieces of data within
// your table. You can think of column families as a mechanism to categorize
// all of your data.
//
// We can create a column family with {@link Table#createFamily}.
//-
const table = instance.table('prezzy');

table.createFamily('follows', function(err, family) {
  // `family` is your newly created Family object.
});

//-
// It is also possible to create your column families when creating a new
// table.
//-
const options = {
  families: ['follows']
};

instance.createTable('prezzy', options, function(err, table) {});

//-
// <h4>Creating Rows</h4>
//
// New rows can be created within your table using
// {@link Table#insert}. You must provide a unique key for each row
// to be inserted, this key can then be used to retrieve your row at a later
// time.
//
// With Bigtable, all columns have a unique id composed of a column family
// and a column qualifier. In the example below `follows` is the column
// family and `tjefferson` is the column qualifier. Together they could be
// referred to as `follows:tjefferson`.
//-
const rows = [
  {
    key: 'wmckinley',
    data: {
      follows: {
        tjefferson: 1
      }
    }
  }
];

table.insert(rows, function(err) {
  if (!err) {
    // Your rows were successfully inserted.
  }
});

//-
// <h4>Retrieving Rows</h4>
//
// If you're anticipating a large number of rows to be returned, we suggest
// using the {@link Table#getRows} streaming API.
//-
table.createReadStream()
  .on('error', console.error)
  .on('data', function(row) {
    // `row` is a Row object.
  });

//-
// If you're not anticpating a large number of results, a callback mode
// is also available.
//-
const callback = function(err, rows) {
  // `rows` is an array of Row objects.
};

table.getRows(callback);

//-
// A range of rows can be retrieved by providing `start` and `end` row keys.
//-
const options = {
  start: 'gwashington',
  end: 'wmckinley'
};

table.getRows(options, callback);

//-
// Retrieve an individual row with {@link Row#get}.
//-
const row = table.row('alincoln');

row.get(function(err) {
  // `row.data` is now populated.
});

//-
// <h4>Accessing Row Data</h4>
//
// When retrieving rows, upon success the `row.data` property will be
// populated by an object. That object will contain additional objects
// for each family in your table that the row has data for.
//
// By default, when retrieving rows, each column qualifier will provide you
// with all previous versions of the data. So your `row.data` object could
// resemble the following.
//-
// {
//   follows: {
//     wmckinley: [
//       {
//         value: 1,
//         timestamp: 1466017315951
//       }, {
//         value: 2,
//         timestamp: 1458619200000
//       }
//     ]
//   }
// }

//-
// The `timestamp` field can be used to order cells from newest to oldest.
// If you only wish to retrieve the most recent version of the data, you
// can specify the number of cells with a {@link Filter} object.
//-
const filter = [
  {
    column: {
      cellLimit: 1
    }
  }
];

table.getRows({
  filter: filter
}, callback);

//-
// <h4>Deleting Row Data</h4>
//
// We can delete all of an individual row's cells using
// {@link Row#delete}.
//-
const callback = function(err) {
  if (!err) {
    // All cells for this row were deleted successfully.
  }
};

row.delete(callback);

//-
// To delete a specific set of cells, we can provide an array of
// column families and qualifiers.
//-
const cells = [
  'follows:gwashington',
  'traits'
];

row.delete(cells, callback);

//-
// <h4>Deleting Rows</h4>
//
// If you wish to delete multiple rows entirely, we can do so with
// {@link Table#deleteRows}. You can provide this method with a
// row key prefix.
//-
const options = {
  prefix: 'gwash'
};

table.deleteRows(options, function(err) {
  if (!err) {
    // Rows were deleted successfully.
  }
});

//-
// If you omit the prefix, you can delete all rows in your table.
//-
table.deleteRows(function(err) {
  if (!err) {
    // All rows were deleted successfully.
  }
});

Parameter

Name Type Optional Description

options

 

Yes

Configuration options.

See also

Creating a Cloud Bigtable Cluster

Cloud Bigtable Concepts Overview

Properties

static

AppProfile  Constructor

AppProfile class.

See also
AppProfile
static

Cluster  Constructor

Cluster class.

See also
Cluster
static

Instance  Constructor

Instance class.

See also
Instance

Methods

createInstance(id, options, callback)

Create a Cloud Bigtable instance.

Example

const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();

const callback = function(err, instance, operation, apiResponse) {
  if (err) {
    // Error handling omitted.
  }

  operation
    .on('error', console.log)
    .on('complete', function() {
      // The instance was created successfully.
    });
};

const options = {
  displayName: 'my-sweet-instance',
  labels: {env: 'prod'},
  clusters: [
    {
      id: 'my-sweet-cluster',
      nodes: 3,
      location: 'us-central1-b',
      storage: 'ssd'
    }
  ]
};

bigtable.createInstance('my-instance', options, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
bigtable.createInstance('my-instance', options).then(function(data) {
  const instance = data[0];
  const operation = data[1];
  const apiResponse = data[2];
});

Parameters

Name Type Optional Description

id

string

 

The unique id of the instance.

options

object

 

Instance creation options.

Values in options have the following properties:

Name Type Optional Description

clusters

Array of object

 

The clusters to be created within the instance.

displayName

string

 

The descriptive name for this instance as it appears in UIs.

labels

Object with string properties

Yes

Labels are a flexible and lightweight mechanism for organizing cloud resources into groups that reflect a customer's organizational needs and deployment strategies. They can be used to filter resources and aggregate metrics.

  • Label keys must be between 1 and 63 characters long and must conform to the regular expression: [\p{Ll}\p{Lo}][\p{Ll}\p{Lo}\p{N}_-]{0,62}.
  • Label values must be between 0 and 63 characters long and must conform to the regular expression: [\p{Ll}\p{Lo}\p{N}_-]{0,63}.
  • No more than 64 labels can be associated with a given resource.
  • Keys and values must both be under 128 bytes.

type

string

Yes

The type of the instance. Options are 'production' or 'development'.

gaxOptions

object

Yes

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:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can 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.

See also

Creating a Cloud Bigtable Instance

getInstances([gaxOptions], callback)

Get Instance objects for all of your Cloud Bigtable instances.

Example

const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();

bigtable.getInstances(function(err, instances) {
  if (!err) {
    // `instances` is an array of Instance objects.
  }
});

//-
// If the callback is omitted, we'll return a Promise.
//-
bigtable.getInstances().then(function(data) {
  const instances = data[0];
});

Parameters

Name Type Optional Description

gaxOptions

object

Yes

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:

Name Type Optional Description

error

error

 

An error returned while making this request.

Value can be null.

instances

Array of Instance

 

List of all instances.

apiResponse

object

 

The full API response.

instance(id) → Instance

Get a reference to a Cloud Bigtable instance.

Parameter

Name Type Optional Description

id

string

 

The id of the instance.

Returns

Instance 

request(config[, callback])

Funnel all API requests through this method, to be sure we have a project ID.

Parameters

Name Type Optional Description

config

object

 

Configuration object.

Values in config have the following properties:

Name Type Optional Description

gaxOpts

object

 

GAX options.

method

function()

 

The gax method to call.

reqOpts

object

 

Request options.

callback

function()

Yes

Callback function.