Constructor

Table

new Table(instance, id)

Parameter

instance

Instance

Instance Object.

id

string

Unique identifier 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

checkConsistency

checkConsistency(token, callback)

Checks consistency for given ConsistencyToken

Parameter

token

string

consistency token

callback

function(nullable error, nullable boolean)

The callback function.

Values in callback have the following properties:

Parameter

err

Error

An error returned while making this request.

Value may be null.

consistent

Boolean

Boolean value.

Value may be null.

create

create(options, callback)

Create a table.

Parameter

options

Optional

object

See Instance#createTable.

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.

table

Table

The newly created table.

apiResponse

object

The full API response.

Examples

table
  .create()
  .then(result => {
    const table = result[0];
    // let apiResponse = result[1];
  })
  .catch(err => {
    // Handle the error.
  });

createFamily

createFamily(id, options, 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

id

string

The unique identifier of column family.

options

Optional

object

Configuration object.

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.

rule

Optional

object

Garbage collection rule

rule.age

Optional

object

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

rule.versions

Optional

number

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

rule.intersect

Optional

boolean

Cells to delete should match all rules.

rule.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.

Examples

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

    table
      .createFamily(familyId, options)
      .then(result => {
        const family = result[0];
        // const apiResponse = result[1];
      })
      .catch(err => {
        // Handle the error.
      });
  },

  getFamilies: (instanceId, tableId) => {
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);

    table
      .getFamilies()
      .then(result => {
        const families = result[0];
      })
      .catch(err => {
        // Handle the error.
      });
  },

  insertRows: (instanceId, tableId) => {
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);

    const entries = [
      {
        key: 'alincoln',
        data: {
          follows: {
            gwashington: 1,
          },
        },
      },
    ];

    table
      .insert(entries)
      .then(result => {
        const apiResponse = result[0];
      })
      .catch(err => {
        // Handle the error.
      });
  },

  getRows: (instanceId, tableId) => {
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);

    const options = {
      keys: ['alincoln', 'gwashington'],
    };
    table
      .getRows(options)
      .then(result => {
        const rows = result[0];
      })
      .catch(err => {
        // Handle the error.
      });
  },

  mutate: (instanceId, tableId) => {
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);

    const entries = [
      {
        method: 'delete',
        key: 'alincoln',
      },
    ];
    table
      .mutate(entries)
      .then(() => {
        // handle success
      })
      .catch(err => {
        // Handle the error.
      });
  },

  createReadStream: (instanceId, tableId) => {
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);

    table
      .createReadStream()
      .on('error', err => {
        // Handle the 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
    //     }
    //   ]
    // });
    //
  },

  sampleRowKeys: (instanceId, tableId) => {
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);

    table
      .sampleRowKeys()
      .then(result => {
        const sampleRKeys = result[0];
      })
      .catch(err => {
        // Handle the error.
      });
  },

  delRows: (instanceId, tableId) => {
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);

    table
      .deleteRows('alincoln')
      .then(result => {
        const apiResponse = result[0];
      })
      .catch(err => {
        // Handle the error.
      });
  },

  delTable: (instanceId, tableId) => {
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);

    table
      .delete()
      .then(result => {
        const apiResponse = result[0];
      })
      .catch(err => {
        // Handle the error.
      });
  },
};

module.exports = snippets;

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.

encoding

Optional

boolean

The encoding to use when converting Buffer values to a string.

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.

gaxOptions

Optional

object

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

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.

prefixes

Optional

Array of string

List of prefixes that a row key must match.

ranges

Optional

Array of object

A list of key ranges.

start

Optional

string

Start value for key range.

Returns

stream 

Examples

table
  .createReadStream()
  .on('error', err => {
    // Handle the 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(gaxOptions, callback)

Delete the table.

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.

Examples

table
  .delete()
  .then(result => {
    const apiResponse = result[0];
  })
  .catch(err => {
    // Handle the error.
  });

deleteRows

deleteRows(prefix, gaxOptions, callback)

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

Parameter

prefix

string

Row key prefix.

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.

apiResponse

object

The full API response.

Throws

error 

If a prefix is not provided.

Examples

    table
      .deleteRows('alincoln')
      .then(result => {
        const apiResponse = result[0];
      })
      .catch(err => {
        // Handle the error.
      });
  },

  delTable: (instanceId, tableId) => {
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);

    table
      .delete()
      .then(result => {
        const apiResponse = result[0];
      })
      .catch(err => {
        // Handle the error.
      });
  },
};

module.exports = snippets;

exists

exists(gaxOptions, callback)

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

Examples

table
  .exists()
  .then(result => {
    const exists = result[0];
  })
  .catch(err => {
    // Handle the error.
  });

family

family(id) returns Family

Get a reference to a Table Family.

Parameter

id

string

The family unique identifier.

Throws

error 

If a name is not provided.

Returns

Family 

Example

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

generateConsistencyToken

generateConsistencyToken(callback)

Generates Consistency-Token

Parameter

callback

function(nullable error, nullable boolean)

The callback function.

Values in callback have the following properties:

Parameter

err

Error

An error returned while making this request.

Value may be null.

token

String

The generated consistency token.

Value may be null.

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 instance if it does not already exist.

gaxOptions

Optional

object

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

callback.error

error

An error returned while making this request.

Value may be null.

callback.table

Table

The Table object.

callback.apiResponse

object

The resource as it exists in the API.

Examples

table
  .get()
  .then(result => {
    const table = result[0];
    // const apiResponse = result[1];
  })
  .catch(err => {
    // Handle the error.
  });

getFamilies

getFamilies(gaxOptions, callback)

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

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.

families

Array of Family

The list of families.

apiResponse

object

The full API response.

Examples

table
  .getFamilies()
  .then(result => {
    const families = result[0];
  })
  .catch(err => {
    // Handle the error.
  });

getMetadata

getMetadata(options, callback)

Get the table's metadata.

Parameter

options

Optional

object

Table request options.

Values in options have the following properties:

Parameter

gaxOptions

Optional

object

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

view

Optional

string

The view to be applied to the table fields.

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.

metadata

object

The table's metadata.

Examples

table
  .getMetadata()
  .then(result => {
    const metaData = result[0];
    // const apiResponse = result[1];
  })
  .catch(err => {
    // Handle the error.
  });

getReplicationStates

getReplicationStates(gaxOptions, callback)

Get replication states of the clusters for this table.

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.

clusterStates

Array of Family

The map of clusterId and its replication state.

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

table.getReplicationStates(function(err, clusterStates, apiResponse) {
  // `clusterStates` is an map of clusterId and its replication state.
});

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

getRows

getRows(options, callback)

Get Row objects for the rows currently in your table.

This method is not recommended for large datasets as it will buffer all rows before returning the results. Instead we recommend using the streaming API via Table#createReadStream.

Parameter

options

Optional

object

Configuration object. See Table#createReadStream for a complete list of options.

Values in options have the following properties:

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.

rows

Array of Row

List of Row objects.

Examples

const options = {
  keys: ['alincoln', 'gwashington'],
};
table
  .getRows(options)
  .then(result => {
    const rows = result[0];
  })
  .catch(err => {
    // Handle the error.
  });

insert

insert(entries, gaxOptions, callback)

Insert or update rows in your table. It should be noted that gRPC only allows you to send payloads that are less than or equal to 4MB. If you're inserting more than that you may need to send smaller individual requests.

Parameter

entries

(object or Array of object)

List of entries to be inserted. See Table#mutate.

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.

err.errors

Array of object

If present, these represent partial failures. It's possible for part of your request to be completed successfully, while the other part was not.

Examples

const entries = [
  {
    key: 'alincoln',
    data: {
      follows: {
        gwashington: 1,
      },
    },
  },
];

table
  .insert(entries)
  .then(result => {
    const apiResponse = result[0];
  })
  .catch(err => {
    // Handle the error.
  });

mutate

mutate(entries, options, callback)

Apply a set of changes to be atomically applied to the specified row(s). Mutations are applied in order, meaning that earlier mutations can be masked by later ones.

Parameter

entries

(object or Array of object)

List of entities to be inserted or deleted.

options

Optional

object

Configuration object.

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.

rawMutation

Optional

boolean

If set to true will treat entries as a raw Mutation object. See Mutation#parse.

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.

err.errors

Array of object

If present, these represent partial failures. It's possible for part of your request to be completed successfully, while the other part was not.

Examples

const entries = [
  {
    method: 'delete',
    key: 'alincoln',
  },
];
table
  .mutate(entries)
  .then(() => {
    // handle success
  })
  .catch(err => {
    // Handle the error.
  });

row

row(key) returns Row

Get a reference to a table row.

Parameter

key

string

The row key.

Throws

error 

If a key is not provided.

Returns

Row 

Example

var row = table.row('lincoln');

sampleRowKeys

sampleRowKeys(gaxOptions, callback)

Returns a sample of row keys in the table. The returned row keys will delimit contigous sections of the table of approximately equal size, which can be used to break up the data for distributed tasks like mapreduces.

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.

keys

Array of object

The list of keys.

Examples

table
  .sampleRowKeys()
  .then(result => {
    const sampleRKeys = result[0];
  })
  .catch(err => {
    // Handle the error.
  });

sampleRowKeysStream

sampleRowKeysStream(gaxOptions) returns stream

Returns a sample of row keys in the table as a readable object stream.

See Table#sampleRowKeys for more details.

Parameter

gaxOptions

Optional

object

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

Returns

stream 

Example

table.sampleRowKeysStream()
  .on('error', console.error)
  .on('data', function(key) {
    // Do something with the `key` object.
  });

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

truncate

truncate(gaxOptions, callback)

Truncate the table.

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.

apiResponse

object

The full API response.

Example

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

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

waitForReplication

waitForReplication(callback)

Generates Consistency-Token and check consistency for generated token In-case consistency check returns false, retrial is done in interval of 5 seconds till 10 minutes, after that it returns false.

Parameter

callback

function(nullable error, nullable boolean)

The callback function.

Values in callback have the following properties:

Parameter

err

Error

An error returned while making this request.

Value may be null.

resp

Boolean

Boolean value.

Value may be null.