Constructor

Row

new Row(table, key)

Create a Row object to interact with your table rows.

Parameter

table

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(entry, callback)

Create a new row in your table.

Parameter

entry

Optional

object

An entry. See Table#insert.

callback

function()

The callback function.

Example

var callback = function(err, apiResponse) {
  if (!err) {
    // Row successfully created
  }
};

row.create(callback);

//-
// Optionally, you can supply entry data.
//-
row.create({
  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, 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.

callback

function()

The callback function.

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(callback)

Deletes all cells in the row.

Parameter

callback

function()

The callback function.

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, callback)

Delete specified cells from the row. See Table#mutate.

Parameter

columns

Array of string

Column names for the cells to be deleted.

callback

function()

The callback function.

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(callback)

Check if the table row exists.

Parameter

callback

function()

The callback function.

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, onMatch, onNoMatch, 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

Filter ot be applied to the contents of the row.

onMatch

Array of object

A list of entries to be ran if a match is found.

Value may be null.

onNoMatch

Optional

Array of object

A list of entries to be ran if no matches are found.

callback

function()

The callback function.

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 entries = [
  {
    method: 'insert',
    data: {
      follows: {
        jadams: 1
      }
    }
  }
];

row.filter(filter, entries, callback);

//-
// Optionally, you can pass in an array of entries to be ran in the event
// that a match is not made.
//-
row.filter(filter, null, entries, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
row.filter(filter, null, entries).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.

callback

function()

The callback function.

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.

callback

function()

The callback function.

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, 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.

callback

function()

The callback function.

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, value, options, callback)

Update the row cells.

Parameter

key

(string or object)

Either a column name or an entry object to be inserted into the row. See Table#insert.

value

Optional

any type

This can be omitted if using entry object.

options

Optional

object

Configuration options. See Table#mutate.

callback

function()

The callback function.

Example

//-
// Update a single cell.
//-
var callback = function(err, apiResponse) {
  if (!err) {
    // The row has been successfully updated.
  }
};

row.save('follows:jadams', 1, callback);

//-
// Or update several cells at once.
//-
row.save({
  follows: {
    jadams: 1,
    wmckinley: 1
  }
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
row.save('follows:jadams', 1).then(function(data) {
  var apiResponse = data[0];
});