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

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];
});
```

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.