Table

Table

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

Constructor

new Table(instance, id)

Parameters:
Name Type Description
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(token, callback)

Checks consistency for given ConsistencyToken

Parameters:
Name Type Description
token string

consistency token

callback function

The callback function.

Properties
Name Type Attributes Description
err Error <nullable>

An error returned while making this request.

consistent Boolean <nullable>

Boolean value.

create(optionsopt, callback)

Create a table.

Parameters:
Name Type Attributes Description
options object <optional>

See Instance#createTable.

Properties
Name Type Attributes Description
gaxOptions object <optional>

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

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

table Table

The newly created table.

apiResponse object

The full API response.

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

createBackup(id, config, callbackopt) → {void|Promise.<CreateBackupResponse>}

Backup a table with cluster auto selection.

Backups of tables originate from a specific cluster. This is a helper around Cluster.createBackup that automatically selects the first ready cluster from which a backup can be performed.

NOTE: This will make two API requests to first determine the most appropriate cluster, then create the backup. This could lead to a race condition if other requests are simultaneously sent or if the cluster availability state changes between each call.

Parameters:
Name Type Attributes Description
id string

A unique ID for the backup.

config CreateBackupConfig

Metadata to set on the Backup.

Properties
Name Type Attributes Description
expireTime BackupTimestamp

When the backup will be automatically deleted.

gaxOptions CallOptions <optional>

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

callback CreateBackupCallback <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

backup Backup

The newly created Backup.

operation Operation

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

apiResponse object

The full API response.

Returns:
Type Description
void | Promise.<CreateBackupResponse>

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

Parameters:
Name Type Attributes Description
id string

The unique identifier of column family.

options object <optional>

Configuration object.

Properties
Name Type Attributes Description
gaxOptions object <optional>

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

rule object <optional>

Garbage collection rule

Properties
Name Type Attributes Description
age object <optional>

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

versions number <optional>

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

intersect boolean <optional>

Cells to delete should match all rules.

union boolean <optional>

Cells to delete should match any of the rules.

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

family Family

The newly created Family.

apiResponse object

The full API response.

See:
Throws:

If a name is not provided.

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

createReadStream(optionsopt) → {stream}

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

Parameters:
Name Type Attributes Description
options object <optional>

Configuration object.

Properties
Name Type Attributes Default Description
decode boolean <optional>
true

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

encoding boolean <optional>

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

end string <optional>

End value for key range.

filter Filter <optional>

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

gaxOptions object <optional>

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

keys Array.<string> <optional>

A list of row keys.

limit number <optional>

Maximum number of rows to be returned.

prefix string <optional>

Prefix that the row key must match.

prefixes Array.<string> <optional>

List of prefixes that a row key must match.

ranges Array.<object> <optional>

A list of key ranges.

start string <optional>

Start value for key range.

Returns:
Type Description
stream
Example
    table
      .createReadStream()
      .on('error', err => {
        // Handle the error.
      })
      .on('data', row => {
        // `row` is a Row object.
      })
      .on('end', () => {
        // 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 Filter to the contents of the specified rows.
    //-
    // table.createReadStream({
    //   filter: [
    //     {
    //       column: 'gwashington'
    //     }, {
    //       value: 1
    //     }
    //   ]
    // });
    //

delete(gaxOptionsopt, callbackopt)

Delete the table.

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

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

callback function <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

apiResponse object

The full API response.

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

deleteRows(prefix, gaxOptionsopt, callback)

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

Parameters:
Name Type Attributes Description
prefix string

Row key prefix.

gaxOptions object <optional>

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

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

apiResponse object

The full API response.

Throws:

If a prefix is not provided.

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

exists(gaxOptionsopt, callback)

Check if a table exists.

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

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

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

exists boolean

Whether the table exists or not.

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

family(id) → {Family}

Get a reference to a Table Family.

Parameters:
Name Type Description
id string

The family unique identifier.

Returns:
Type Description
Family
Throws:

If a name is not provided.

Type
error
Example
```
const family = table.family('my-family');
```

generateConsistencyToken(callback)

Generates Consistency-Token

Parameters:
Name Type Description
callback function

The callback function.

Properties
Name Type Attributes Description
err Error <nullable>

An error returned while making this request.

token String <nullable>

The generated consistency token.

get(optionsopt)

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.

Parameters:
Name Type Attributes Description
options object <optional>

Configuration object.

Properties
Name Type Attributes Default Description
autoCreate boolean <optional>
false

Automatically create the instance if it does not already exist.

gaxOptions object <optional>

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

callback.error error <nullable>

An error returned while making this request.

callback.table Table

The Table object.

callback.apiResponse object

The resource as it exists in the API.

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

getFamilies(gaxOptionsopt, callback)

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

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

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

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

families Array.<Family>

The list of families.

apiResponse object

The full API response.

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

getIamPolicy(optionsopt, callbackopt, policy)

Parameters:
Name Type Attributes Description
options object <optional>

Configuration object.

Properties
Name Type Attributes Description
gaxOptions object <optional>

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

requestedPolicyVersion number <optional>

The policy format version to be returned. Valid values are 0, 1, and 3. Requests specifying an invalid value will be rejected. Requests for policies with any conditional bindings must specify version 3. Policies without any conditional bindings may specify any valid value or leave the field unset.

callback function <optional>

The callback function.

Properties
Name Type Attributes Description
error error <nullable>

An error returned while making this request.

policy Policy

The policy.

Example
    const {Bigtable} = require('@google-cloud/bigtable');
    const bigtable = new Bigtable();
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);

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

getMetadata(optionsopt, callbackopt)

Get the table's metadata.

Parameters:
Name Type Attributes Description
options object <optional>

Table request options.

Properties
Name Type Attributes Description
gaxOptions object <optional>

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

view string <optional>

The view to be applied to the table fields.

callback function <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

metadata object

The table's metadata.

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

getReplicationStates(gaxOptionsopt, callback)

Get replication states of the clusters for this table.

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

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

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

clusterStates Array.<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) {
  const clusterStates = data[0];
  const apiResponse = data[1];
});
```

getRows(optionsopt, 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.

Parameters:
Name Type Attributes Description
options object <optional>

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

Properties
Name Type Attributes Description
gaxOptions object <optional>

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

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

rows Array.<Row>

List of Row objects.

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

insert(entries, gaxOptionsopt, 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.

Parameters:
Name Type Attributes Description
entries object | Array.<object>

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

gaxOptions object <optional>

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

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

Properties
Name Type Description
errors Array.<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.

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

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

mutate(entries, optionsopt, 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.

Parameters:
Name Type Attributes Description
entries object | Array.<object>

List of entities to be inserted or deleted.

options object <optional>

Configuration object.

Properties
Name Type Attributes Description
gaxOptions object <optional>

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

rawMutation boolean <optional>

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

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

Properties
Name Type Description
errors Array.<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.

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

row(key) → {Row}

Get a reference to a table row.

Parameters:
Name Type Description
key string

The row key.

Returns:
Type Description
Row
Throws:

If a key is not provided.

Type
error
Example
```
const row = table.row('lincoln');
```

sampleRowKeys(gaxOptionsopt, callbackopt)

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

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

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

callback function <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

keys Array.<object>

The list of keys.

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

sampleRowKeysStream(gaxOptionsopt) → {stream}

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

See Table#sampleRowKeys for more details.

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

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

Returns:
Type Description
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();
  });
```

setIamPolicy(gaxOptionsopt, callbackopt, policy)

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

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

callback function <optional>

The callback function.

Properties
Name Type Attributes Description
error error <nullable>

An error returned while making this request.

policy Policy

The policy.

Example
    const {Bigtable} = require('@google-cloud/bigtable');
    const bigtable = new Bigtable();
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);

    const policy = {
      bindings: [
        {
          role: 'roles/bigtable.viewer',
          members: ['user:mike@example.com', 'group:admins@example.com'],
        },
      ],
    };

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

testIamPermissions(permissions, gaxOptionsopt, callbackopt, permissions)

Parameters:
Name Type Attributes Description
permissions string | Array.<string>

The permission(s) to test for.

gaxOptions object <optional>

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

callback function <optional>

The callback function.

Properties
Name Type Attributes Description
error error <nullable>

An error returned while making this request.

permissions Array.<string>

A subset of permissions that the caller is allowed.

Example
    const {Bigtable} = require('@google-cloud/bigtable');
    const bigtable = new Bigtable();
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);

    const permissions = ['bigtable.tables.get', 'bigtable.tables.readRows'];
    table
      .testIamPermissions(permissions)
      .then(result => {
        const grantedPermissions = result[0];
      })
      .catch(err => {
        // Handle the error
      });

truncate(gaxOptionsopt, callback)

Truncate the table.

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

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

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

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) {
  const apiResponse = data[0];
});
```

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.

Parameters:
Name Type Description
callback function

The callback function.

Properties
Name Type Attributes Description
err Error <nullable>

An error returned while making this request.

resp Boolean <nullable>

Boolean value.