Constructor
new Instance(bigtable, id)
Parameters:
Name | Type | Description |
---|---|---|
bigtable |
Bigtable |
The parent Bigtable object of this instance. |
id |
string |
Id of the instance. |
Methods
appProfile(name) → {AppProfile}
Get a reference to a Bigtable App Profile.
Parameters:
Name | Type | Description |
---|---|---|
name |
string |
The name of the app profile. |
Returns:
Type | Description |
---|---|
AppProfile |
cluster(id) → {Cluster}
Get a reference to a Bigtable Cluster.
Parameters:
Name | Type | Description |
---|---|---|
id |
string |
The id of the cluster. |
Returns:
Type | Description |
---|---|
Cluster |
create(options, callback)
Create an instance.
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Properties
|
||||||||||||||||||||
callback |
function |
The callback function. Properties
|
Example
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
// options for a PRODUCTION Instance
// const options = {
// clusters: [
// {
// id: clusterId,
// nodes: 3,
// location: 'us-central1-f',
// storage: 'ssd',
// },
// ],
// type: 'PRODUCTION', // Optional as default type is PRODUCTION
// };
// options for a DEVELOPMENT Instance
const options = {
clusters: [
{
id: clusterId,
location: 'us-central1-f',
storage: 'hdd',
},
],
type: 'DEVELOPMENT',
};
// creates a new Instance
instance
.create(options)
.then(result => {
const newInstance = result[0];
// let operations = result[1];
// let apiResponse = result[2];
})
.catch(err => {
// Handle the error.
});
createAppProfile(id, options, callback)
Create an app profile.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
string |
The name to be used when referring to the new app profile within its instance. |
||||||||||||||||||||||||
options |
object |
AppProfile creation options. Properties
|
||||||||||||||||||||||||
callback |
function |
The callback function. Properties
|
Example
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const cluster = instance.cluster(clusterId);
const options = {
routing: cluster,
allowTransactionalWrites: true,
ignoreWarnings: true,
};
instance.createAppProfile(appProfileId, options, (err, appProfile) => {
if (err) {
// Handle the error.
return callback(err);
}
return callback(appProfile);
});
createCluster(id, options, callback)
Create a cluster.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
string |
The id to be used when referring to the new cluster within its instance. |
||||||||||||||||||||||||||||||||||
options |
object |
Cluster creation options. Properties
|
||||||||||||||||||||||||||||||||||
callback |
function |
The callback function. Properties
|
Example
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
// const options = {
// location: 'us-central1-b',
// nodes: 3,
// storage: 'ssd',
// };
const options = {
location: 'us-central1-b',
storage: 'hdd',
};
instance
.createCluster(clusterId, options)
.then(result => {
const newCluster = result[0];
// const operations = result[1];
// const apiResponse = result[2];
})
.catch(err => {
// Handle the error.
});
createTable(id, optionsopt, callback)
Create a table on your Bigtable instance.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
string |
Unique identifier of the table. |
|||||||||||||||||
options |
object |
<optional> |
Table creation options. Properties
|
||||||||||||||||
callback |
function |
The callback function. Properties
|
Throws:
-
If a id is not provided.
- Type
- error
Example
table
.create()
.then(result => {
const table = result[0];
// let apiResponse = result[1];
})
.catch(err => {
// Handle the error.
});
createTableFromBackup(config, cbopt) → {void|Promise.<RestoreTableResponse>}
Create a new table by restoring from a completed backup.
The new table must be in the same instance as the instance containing the backup. The returned table long-running operation can be used to track the progress of the operation, and to cancel it.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
CreateTableFromBackupConfig |
Configuration object. Properties
|
|||||||||||||||||
cb |
RestoreTableCallback |
<optional> |
Returns:
Type | Description |
---|---|
void | Promise.<RestoreTableResponse> |
Example
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
async function restoreBackup() {
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const instanceId = 'YOUR_INSTANCE_ID';
// const tableId = 'YOUR_TABLE_ID';
// const backupId = 'YOUR_BACKUP_ID';
const instance = bigtable.instance(instanceId);
// Restore a table to an instance.
const [table, operation] = await instance.createTableFromBackup({
table: tableId,
backup: backupId,
});
await operation.promise();
console.log(`Table restored to ${table.id} successfully.`);
}
await restoreBackup();
delete(gaxOptionsopt, callbackopt)
Delete the instance.
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
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
instance
.delete()
.then(result => {
const apiResponse = result[0];
})
.catch(err => {
// Handle the error.
});
exists(gaxOptionsopt, callback)
Check if an instance 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
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
instance
.exists()
.then(result => {
const exists = result[0];
})
.catch(err => {
// Handle the error.
});
get(gaxOptionsopt, callback)
Get an instance if it 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
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
instance
.get()
.then(result => {
const instance = result[0];
// const apiResponse = result[1];
})
.catch(err => {
// Handle the error.
});
getAppProfiles(gaxOptionsopt, callback)
Get App Profile objects for this instance.
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(instanceId);
instance
.getAppProfiles()
.then(result => {
const appProfiles = result[0];
})
.catch(err => {
// Handle the error.
});
getAppProfilesStream(gaxOptionsopt) → {stream}
Get AppProfile objects for all the App Profiles in your Cloud Bigtable instance as a readable object stream.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
gaxOptions |
object |
<optional> |
Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. Instance#getAppProfiles for a complete list of options. |
Returns:
Type | Description |
---|---|
stream |
Example
```
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
instance.getAppProfilesStream()
.on('error', console.error)
.on('data', function(appProfile) {
// appProfile is a AppProfile object.
})
.on('end', () => {
// All appProfiles retrieved.
});
//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
instance.getAppProfilesStream()
.on('data', function(appProfile) {
this.end();
});
```
getBackups(optionsOrCallbackopt, callbackopt) → {void|Promise.<ListBackupsResponse>}
Get Cloud Bigtable Backup instances within this instance. This returns both completed and pending backups.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
optionsOrCallback |
GetBackupsOptions | GetBackupsCallback |
<optional> |
|||||||||||||||||
callback |
GetBackupsResponse |
<optional> |
The callback function. Properties
|
Returns:
Type | Description |
---|---|
void | Promise.<ListBackupsResponse> |
Example
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
async function listBackups() {
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const instanceId = 'YOUR_INSTANCE_ID';
// const tableId = 'YOUR_TABLE_ID';
// const clusterId = 'YOUR_CLUSTER_ID';
const instance = bigtable.instance(instanceId);
const table = instance.table(tableId);
const cluster = table.cluster(clusterId);
const [backupsFromInstance] = await instance.listBackups();
console.log(
`${backupsFromInstance.length} backups returned from the instance.`
);
const [backupsFromCluster] = await cluster.listBackups();
console.log(
`${backupsFromCluster.length} backups returned from the cluster.`
);
}
await listBackups();
getBackupsStream(optionsopt) → {ReadableStream.<Backup>}
Get Cloud Bigtable Backup instances within this instance. This returns both completed and pending backups as a readable stream.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
GetBackupsOptions |
<optional> |
Configuration object. See Instance#getBackups for a complete list of options. |
Returns:
Type | Description |
---|---|
ReadableStream.<Backup> |
Example
```
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
instance.getBackupsStream()
.on('error', console.error)
.on('data', function(backup) {
// backup is a Backup object.
})
.on('end', () => {
// All backups retrieved.
});
//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
instance.getBackupsStream()
.on('data', function(backup) {
this.end();
});
```
getClusters(gaxOptionsopt, callback)
Get Cluster objects for all of your clusters.
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(instanceId);
instance
.getClusters()
.then(result => {
const clusters = 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);
instance
.getIamPolicy()
.then(result => {
const policy = result[0];
})
.catch(err => {
// Handle the error.
});
getMetadata(gaxOptionsopt, callback)
Get the instance metadata.
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(instanceId);
instance
.getMetadata()
.then(result => {
const metaData = result[0];
})
.catch(err => {
// Handle the error.
});
getTables(optionsopt, callback)
Get Table objects for all the tables in your Cloud Bigtable instance.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Query object. Properties
|
|||||||||||||||||||||||||||||||||||
callback |
function |
The callback function. Properties
|
Example
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to false.
const options = {
autoPaginate: false,
};
// const options = {
// autoPaginate: true
// };
instance
.getTables(options)
.then(result => {
const tables = result[0];
})
.catch(err => {
// Handle the error.
});
getTablesStream(optionsopt) → {stream}
Get Table objects for all the tables in your Cloud Bigtable instance as a readable object stream.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
object |
<optional> |
Query object. See Instance#getTables for a complete list of options. |
Returns:
Type | Description |
---|---|
stream |
Example
```
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
instance.getTablesStream()
.on('error', console.error)
.on('data', function(table) {
// table is a Table object.
})
.on('end', () => {
// All tables retrieved.
});
//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
instance.getTablesStream()
.on('data', function(table) {
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 policy = {
bindings: [
{
role: 'roles/bigtable.viewer',
members: ['user:mike@example.com', 'group:admins@example.com'],
},
],
};
instance
.setIamPolicy(policy)
.then(result => {
const setPolicy = result[0];
})
.catch(err => {
// Handle the error
});
setMetadata(metadata, gaxOptionsopt, callback)
Set the instance metadata.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
metadata |
object |
Metadata object. Properties
|
|||||||||||||
gaxOptions |
object |
<optional> |
Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions. |
||||||||||||
callback |
function |
The callback function. Properties
|
Example
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const metadata = {
displayName: 'updated-name',
};
instance
.setMetadata(metadata)
.then(result => {
const apiResponse = result[0];
})
.catch(err => {
// Handle the error.
});
table(id) → {Table}
Get a reference to a Bigtable table.
Parameters:
Name | Type | Description |
---|---|---|
id |
string |
Unique identifier of the table. |
Returns:
Type | Description |
---|---|
Table |
Example
```
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
const table = instance.table('presidents');
```
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 permissions = ['bigtable.tables.get', 'bigtable.tables.readRows'];
instance
.testIamPermissions(permissions)
.then(result => {
const grantedPermissions = result[0];
})
.catch(err => {
// Handle the error
});