Constructor

Table

new Table(instance, name)

Create a Table object to interact with a Cloud Bigtable table.

Parameter

instance

Instance

Name of the table.

name

string

Name of the table.

Example

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

Methods

create

create(options)

Create a table.

Parameter

options

Optional

object

See Instance#createTable.

Example

table.create(function(err, table, apiResponse) {
  if (!err) {
    // The table was created successfully.
  }
});

//-
// If the callback is omitted, we'll return a Promise.
//-
table.create().then(function(data) {
  var table = data[0];
  var apiResponse = data[1];
});

createFamily

createFamily(name, rule, callback)

Create a column family.

Optionally you can send garbage collection rules and when creating a family. Garbage collection executes opportunistically in the background, so it's possible for reads to return a cell even if it matches the active expression for its family.

Parameter

name

string

The name of column family.

rule

Optional

object

Garbage collection rule.

Values in rule have the following properties:

Parameter

age

Optional

object

Delete cells in a column older than the given age. Values must be at least 1 millisecond.

versions

Optional

number

Maximum number of versions to delete cells in a column, except for the most recent.

intersect

Optional

boolean

Cells to delete should match all rules.

union

Optional

boolean

Cells to delete should match any of the rules.

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.

family

Family

The newly created Family.

apiResponse

object

The full API response.

See also

Garbage Collection Proto Docs

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 table = instance.table('prezzy');

const callback = function(err, family, apiResponse) {
  // `family` is a Family object
};

const rule = {
  age: {
    seconds: 0,
    nanos: 5000
  },
  versions: 3,
  union: true
};

table.createFamily('follows', rule, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
table.createFamily('follows').then(function(data) {
  const family = data[0];
  const apiResponse = data[1];
});

createReadStream

createReadStream(options) returns stream

Get Row objects for the rows currently in your table as a readable object stream.

Parameter

options

Optional

object

Configuration object.

Values in options have the following properties:

Parameter

decode

Optional

boolean

If set to false it will not decode Buffer values returned from Bigtable.

end

Optional

string

End value for key range.

filter

Optional

Filter

Row filters allow you to both make advanced queries and format how the data is returned.

keys

Optional

Array of string

A list of row keys.

limit

Optional

number

Maximum number of rows to be returned.

prefix

Optional

string

Prefix that the row key must match.

ranges

Optional

Array of object

A list of key ranges.

start

Optional

string

Start value for key range.

Returns

stream 

Example

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

table.createReadStream()
  .on('error', console.error)
  .on('data', function(row) {
    // `row` is a Row object.
  })
  .on('end', function() {
    // All rows retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing.
//-
table.createReadStream()
  .on('data', function(row) {
    this.end();
  });

//-
// Specify arbitrary keys for a non-contiguous set of rows.
// The total size of the keys must remain under 1MB, after encoding.
//-
table.createReadStream({
  keys: [
    'alincoln',
    'gwashington'
  ]
});

//-
// Scan for row keys that contain a specific prefix.
//-
table.createReadStream({
  prefix: 'gwash'
});

//-
// Specify a contiguous range of rows to read by supplying `start` and `end`
// keys.
//
// If the `start` key is omitted, it is interpreted as an empty string.
// If the `end` key is omitted, it is interpreted as infinity.
//-
table.createReadStream({
  start: 'alincoln',
  end: 'gwashington'
});

//-
// Specify multiple ranges.
//-
table.createReadStream({
  ranges: [{
    start: 'alincoln',
    end: 'gwashington'
  }, {
    start: 'tjefferson',
    end: 'jadams'
  }]
});

//-
// Apply a {@link Filter} to the contents of the specified rows.
//-
table.createReadStream({
  filter: [
    {
      column: 'gwashington'
    }, {
      value: 1
    }
  ]
});

delete

delete(callback)

Delete the table.

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

table.delete(function(err, apiResponse) {});

//-
// If the callback is omitted, we'll return a Promise.
//-
table.delete().then(function(data) {
  var apiResponse = data[0];
});

deleteRows

deleteRows(options, callback)

Delete all rows in the table, optionally corresponding to a particular prefix.

Parameter

options

Optional

object

Configuration object.

Values in options have the following properties:

Parameter

prefix

Optional

string

Row key prefix, when omitted all rows will be deleted.

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');
const table = instance.table('prezzy');

//-
// You can supply a prefix to delete all corresponding rows.
//-
const callback = function(err, apiResponse) {
  if (!err) {
    // Rows successfully deleted.
  }
};

table.deleteRows({
  prefix: 'alincoln'
}, callback);

//-
// If you choose to omit the prefix, all rows in the table will be deleted.
//-
table.deleteRows(callback);

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

exists

exists(callback)

Check if a table 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 table exists or not.

Example

table.exists(function(err, exists) {});

//-
// If the callback is omitted, we'll return a Promise.
//-
table.exists().then(function(data) {
  var exists = data[0];
});

family

family(name) returns Family

Get a reference to a Table Family.

Parameter

name

string

The family name.

Throws

error 

If a name is not provided.

Returns

Family 

Example

const family = table.family('my-family');

get

get(options)

Get a table if it exists.

You may optionally use this to "get or create" an object by providing an object with autoCreate set to true. Any extra configuration that is normally required for the create method must be contained within this object as well.

Parameter

options

Optional

object

Configuration object.

Values in options have the following properties:

Parameter

autoCreate

Optional

boolean

Automatically create the object if it does not exist.

view

Optional

string

The view to be applied to the table fields. See Table#getMetadata.

Example

table.get(function(err, table, apiResponse) {
  // The `table` data has been populated.
});

//-
// If the callback is omitted, we'll return a Promise.
//-
table.get().then(function(data) {
  var table = data[0];
  var apiResponse = data[0];
});

getFamilies

getFamilies(callback)

Get Family objects for all the column familes in your table.

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.