Constructor
new Table(instance, id)
Parameters:
Name | Type | Description |
---|---|---|
instance |
Instance |
Instance Object. |
id |
string |
Unique identifier of the table. |
Methods
checkConsistency(token, callback)
Checks consistency for given ConsistencyToken
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
token |
string |
consistency token |
||||||||||||
callback |
function |
The callback function. Properties
|
create(optionsopt, callback)
Create a table.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
See Instance#createTable. Properties
|
||||||||||||||||
callback |
function |
The callback function. Properties
|
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
|
|||||||||||||||||||||
callback |
CreateBackupCallback |
<optional> |
The callback function. Properties
|
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
|
||||||||||||||||||||||||||||||||
callback |
function |
The callback function. Properties
|
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
|
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
|
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
|
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
|
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
generateConsistencyToken(callback)
Generates Consistency-Token
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
The callback function. Properties
|
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
|
|||||||||||||||
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
|
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
|
||||||||||||
callback |
function |
<optional> |
The callback function. Properties
|
||||||||||||
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
|
||||||||||||
callback |
function |
<optional> |
The callback function. Properties
|
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
|
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
|
||||||||||||
callback |
function |
The callback function. Properties
|
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
|
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
|
||||||||||||||
callback |
function |
The callback function. Properties
|
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
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
|
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
|
||||||||
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
|
||||||||
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
|
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
|