Row
Constructor
Row
new Row(table, key)
Create a Row object to interact with your table rows.
Parameter |
|
---|---|
table |
The row's parent Table instance. |
key |
string The key for this row. |
Example
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
const table = instance.table('prezzy');
const row = table.row('gwashington');
Methods
create
create(options, callback)
Create a new row in your table.
Parameter |
|||||||||
---|---|---|---|---|---|---|---|---|---|
options |
Optional object Configuration object. Values in
|
||||||||
callback |
function() The callback function. Values in
|
Example
var callback = function(err, apiResponse) {
if (!err) {
// Row successfully created
}
};
row.create(callback);
//-
// Optionally, you can supply entry data.
//-
row.create({
entry: {
follows: {
alincoln: 1
}
}
}, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
row.create().then(function(data) {
var apiResponse = data[0];
});
createRules
createRules(rules, gaxOptions, callback)
Update a row with rules specifying how the row's contents are to be transformed into writes. Rules are applied in order, meaning that earlier rules will affect the results of later ones.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
rules |
(object or Array of object) The rules to apply to this row. |
||||||
gaxOptions |
Optional object Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||
callback |
function() The callback function. Values in
|
- Throws
-
error
If no rules are provided.
Example
//-
// Add an increment amount to an existing value, if the targeted cell is
// unset, it will be treated as containing a zero.
//-
var callback = function(err, apiResponse) {
if (!err) {
// The rules have successfully been applied.
}
};
var rules = [
{
column: 'follows:gwashington',
increment: 1
}
];
row.createRules(rules, callback);
//-
// You can also create a rule that will append data to an existing value.
// If the targeted cell is unset, it will be treated as a containing an
// empty string.
//-
var rules = [
{
column: 'follows:alincoln',
append: ' Honest Abe!'
}
];
row.createRules(rules, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
row.createRules(rules).then(function(data) {
var apiResponse = data[0];
});
delete
delete(gaxOptions, callback)
Deletes all cells in the row.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
gaxOptions |
Optional object Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||
callback |
function() The callback function. Values in
|
Example
row.delete(function(err, apiResponse) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
row.delete().then(function(data) {
var apiResponse = data[0];
});
deleteCells
deleteCells(columns, gaxOptions, callback)
Delete specified cells from the row. See Table#mutate.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
columns |
Array of string Column names for the cells to be deleted. |
||||||
gaxOptions |
Optional object Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||
callback |
function() The callback function. Values in
|
Example
//-
// Delete individual cells.
//-
var callback = function(err, apiResponse) {
if (!err) {
// Cells were successfully deleted.
}
};
var cells = [
'follows:gwashington'
];
row.deleteCells(cells, callback);
//-
// Delete all cells within a family.
//-
var cells = [
'follows',
];
row.deleteCells(cells, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
row.deleteCells(cells).then(function(data) {
var apiResponse = data[0];
});
exists
exists(gaxOptions, callback)
Check if the table row exists.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
gaxOptions |
Optional object Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||
callback |
function() The callback function. Values in
|
Example
row.exists(function(err, exists) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
row.exists().then(function(data) {
var exists = data[0];
});
filter
filter(filter, config, callback)
Mutates a row atomically based on the output of a filter. Depending on whether or not any results are yielded, either the onMatch
or onNoMatch
callback will be executed.
Parameter |
|||||||||
---|---|---|---|---|---|---|---|---|---|
filter |
Filter to be applied to the contents of the row. |
||||||||
config |
object Configuration object. Values in
|
||||||||
callback |
function() The callback function. Values in
|
Example
var callback = function(err, matched) {
if (!err) {
// `matched` will let us know if a match was found or not.
}
};
var filter = [
{
family: 'follows'
},
{
column: 'alincoln',
},
{
value: 1
}
];
var config = {
onMatch: [
{
method: 'insert',
data: {
follows: {
jadams: 1
}
}
}
]
};
row.filter(filter, config, callback);
//-
// Optionally, you can pass in an array of entries to be ran in the event
// that a match is not made.
//-
var config = {
onNoMatch: [
{
method: 'insert',
data: {
follows: {
jadams: 1
}
}
}
]
};
row.filter(filter, config, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
row.filter(filter, config).then(function(data) {
var matched = data[0];
});
get
get(columns, options, callback)
Get the row data. See Table#getRows.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
columns |
Optional Array of string List of specific columns to retrieve. |
||||||
options |
Optional object Configuration object. Values in
|
||||||
callback |
function() The callback function. Values in
|
Example
//-
// Use this method to grab an entire row
//-
var callback = function(err, row, apiResponse) {
if (!err) {
// `row.cells` has been updated.
}
};
row.get(callback);
//-
// Or pass in an array of column names to populate specific cells.
// Under the hood this will create an interleave filter.
//-
row.get([
'follows:gwashington',
'follows:alincoln'
], callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
row.get().then(function(data) {
var row = data[0];
var apiResponse = data[1];
});
getMetadata
getMetadata(options, callback)
Get the row's metadata.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
options |
Optional object Configuration object. Values in
|
||||||
callback |
function() The callback function. Values in
|
Example
row.getMetadata(function(err, metadata, apiResponse) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
row.getMetadata().then(function(data) {
var metadata = data[0];
var apiResponse = data[1];
});
increment
increment(column, value, gaxOptions, callback)
Increment a specific column within the row. If the column does not exist, it is automatically initialized to 0 before being incremented.
Parameter |
|||||||||
---|---|---|---|---|---|---|---|---|---|
column |
string The column we are incrementing a value in. |
||||||||
value |
Optional number The amount to increment by, defaults to 1. |
||||||||
gaxOptions |
Optional object Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||||
callback |
function() The callback function. Values in
|
Example
var callback = function(err, value, apiResponse) {
if (!err) {
// `value` is the value of the updated column.
}
};
row.increment('follows:gwashington', callback);
//-
// Specify a custom amount to increment the column by.
//-
row.increment('follows:gwashington', 2, callback);
//-
// To decrement a column, simply supply a negative value.
//-
row.increment('follows:gwashington', -1, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
row.increment('follows:gwashington').then(function(data) {
var value = data[0];
var apiResponse = data[1];
});
save
save(key, gaxOptions, callback)
Update the row cells.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
key |
object An entry object to be inserted into the row. See Table#insert. |
||||||
gaxOptions |
Optional object Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||
callback |
function() The callback function. Values in
|
Example
var entry = {
follows: {
jadams: 1
}
};
//-
// Update a single cell.
//-
var callback = function(err, apiResponse) {
if (!err) {
// The row has been successfully updated.
}
};
row.save(entry, 1, callback);
//-
// Or update several cells at once.
//-
row.save(entry, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
row.save(entry).then(function(data) {
var apiResponse = data[0];
});