Table
Source: table.
Create a Table object to interact with a Cloud Bigtable table.
Methods
new Table(instance, id)
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
const table = instance.table('prezzy');
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
|
instance |
|
|
Instance Object. |
|
id |
|
|
Unique identifier of the table. |
Methods
checkConsistency(token, callback)
Checks consistency for given ConsistencyToken
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
token |
string |
|
consistency token |
||||||||||||
|
callback |
function(nullable error, nullable boolean) |
|
The callback function. Values in
|
create([options], callback)
Create a table.
Example
include:samples/document-snippets/table.js
region_tag:bigtable_create_table
Parameters
| Name | Type | Optional | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
object |
Yes |
See Instance#createTable. Values in
|
||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
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.
Example
include:samples/document-snippets/table.js
region_tag:bigtable_create_family
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
id |
string |
|
The unique identifier of column family. |
||||||||||||||||||||||||||||
|
options |
object |
Yes |
Configuration object. Values in
|
||||||||||||||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
- See also
- Throws
-
errorIf a name is not provided.
createReadStream([options]) → stream
Get Row objects for the rows currently in your table as a readable object stream.
Example
include:samples/document-snippets/table.js
region_tag:bigtable_table_readstream
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
object |
Yes |
Configuration object. Values in
|
- Returns
-
stream
delete([gaxOptions][, callback])
Delete the table.
Example
include:samples/document-snippets/table.js
region_tag:bigtable_del_table
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
gaxOptions |
object |
Yes |
Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||||||||
|
callback |
function() |
Yes |
The callback function. Values in
|
deleteRows(prefix[, gaxOptions], callback)
Delete all rows in the table, optionally corresponding to a particular prefix.
Example
include:samples/document-snippets/table.js
region_tag:bigtable_del_rows
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
prefix |
string |
|
Row key prefix. |
||||||||||||
|
gaxOptions |
object |
Yes |
Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
- Throws
-
errorIf a prefix is not provided.
exists([gaxOptions], callback)
Check if a table exists.
Example
include:samples/document-snippets/table.js
region_tag:bigtable_exists_table
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
gaxOptions |
object |
Yes |
Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
family(id) → Family
Get a reference to a Table Family.
Example
const family = table.family('my-family');
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
id |
string |
|
The family unique identifier. |
- Throws
-
errorIf a name is not provided.
- Returns
generateConsistencyToken(callback)
Generates Consistency-Token
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
callback |
function(nullable error, nullable boolean) |
|
The callback function. Values in
|
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.
Example
include:samples/document-snippets/table.js
region_tag:bigtable_get_table
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
object |
Yes |
Configuration object. Values in
|
||||||||||||
|
callback.error |
error |
|
An error returned while making this request. Value can be null. |
||||||||||||
|
callback.table |
|
The Table object. |
|||||||||||||
|
callback.apiResponse |
object |
|
The resource as it exists in the API. |
getFamilies([gaxOptions], callback)
Get Family objects for all the column familes in your table.
Example
include:samples/document-snippets/table.js
region_tag:bigtable_get_families
Parameters
| Name | Type | Optional | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
gaxOptions |
object |
Yes |
Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
getMetadata([options][, callback])
Get the table's metadata.
Example
include:samples/document-snippets/table.js
region_tag:bigtable_get_table_meta
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
object |
Yes |
Table request options. Values in
|
||||||||||||
|
callback |
function() |
Yes |
The callback function. Values in
|
getReplicationStates([gaxOptions], callback)
Get replication states of the clusters for this table.
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];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
gaxOptions |
object |
Yes |
Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
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.
Example
include:samples/document-snippets/table.js
region_tag:bigtable_get_rows
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
object |
Yes |
Configuration object. See Table#createReadStream for a complete list of options. Values in
|
||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
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.
Example
include:samples/document-snippets/table.js
region_tag:bigtable_insert_rows
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
entries |
(object or Array of object) |
|
List of entries to be inserted. See Table#mutate. |
||||||||||||
|
gaxOptions |
object |
Yes |
Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
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.
Example
include:samples/document-snippets/table.js
region_tag:bigtable_mutate_rows
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
entries |
(object or Array of object) |
|
List of entities to be inserted or deleted. |
||||||||||||
|
options |
object |
Yes |
Configuration object. Values in
|
||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
row(key) → Row
Get a reference to a table row.
Example
var row = table.row('lincoln');
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
key |
string |
|
The row key. |
- Throws
-
errorIf a key is not provided.
- Returns
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.
Example
include:samples/document-snippets/table.js
region_tag:bigtable_sample_row_keys
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
gaxOptions |
object |
Yes |
Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||||||||
|
callback |
function() |
Yes |
The callback function. Values in
|
sampleRowKeysStream([gaxOptions]) → stream
Returns a sample of row keys in the table as a readable object stream.
See Table#sampleRowKeys for more details.
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();
});
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
gaxOptions |
object |
Yes |
Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
- Returns
-
stream
truncate([gaxOptions], callback)
Truncate the table.
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];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
gaxOptions |
object |
Yes |
Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
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 | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
callback |
function(nullable error, nullable boolean) |
|
The callback function. Values in
|