Skip to content
This repository has been archived by the owner on Nov 9, 2024. It is now read-only.

Table Storage

pofallon edited this page Apr 19, 2012 · 19 revisions

The table storage API functionality can be put into two groups: (1) methods provided with 'storage' that allow manipulation of the tables themselves and (2) methods on the 'table' object used to manipulate table attributes and data.

Table-related 'storage' methods

These methods are accessible via the storage object. In reality, the functionality is found in static methods of the Table object -- these proxy methods are provided for convenience.

storage.createTable(tableName[, callback])

Creates a new table with the supplied tableName on this storage account. Optional callback is invoked with a reference to the newly created table as the second parameter.

storage.listTables([prefix][, options][, callback])

Lists all tables in this storage account. Optional 'prefix' will return only those tables starting with prefix. Passing the option {limit:n} will return only the first n tables. Optional callback is invoked with an array of table names as the second argument.

With no callback, an EventEmitter is immediately returned which will emit a 'data' event with each table name and an 'end' event with a total count of tables.

For example, a simple way to return a count of tabless:

storage.listTables().on('end', function(err, count) {
  console.log(count);
});

Because continuations are handled automatically, the above code will work for 5 containers, or 5000.

storage.removeTable(tableName[, callback])

Removes the table specified by tableName. Optional callback is invoked with any errors.

storage.table(tableName)

Returns a reference to a table (the same as returned by storage.createTable).

Table instance methods

The createTable and table methods above return an instance of the Table object. This object provides the following methods:

table.insert(partition, row, data[, callback])

Inserts the key/value pairs specified in data into the table using the supplied partition and row keys. Boolean, Number, String and DateTime datatypes are supported -- Number currently defaults to Edm.Double. Optional callback is invoked with any errors.

table.update(partition, row, data[, options][, callback])

Replaces any existing data at the supplied partition and row keys with the values provided in data. Passing the option {upsert:true} will insert the data when no row currently exists at partition and row.

table.del(partition, row[, callback])

Removes the table data at the supplied partition and row keys. Optional callback is invoked with any errors.

table.select()

table.whereKeys()

table.where()

table.and()

table.or()

table.filter(criteria)

Applies one or more equality filters to the data that will be returned from a call to rows(). It can be used in lieu of the above methods for simple matching queries. For example:

t.filter({'city':'Atlanta', 'fruit':'peach'}).rows();

table.rows([callback])

Applies any preceding criteria and retrieves the results. Optional callback is invoked with an array of rows as the second argument.

With no callback, an EventEmitter is immediately returned which will emit a 'data' event with each row and an 'end' event with a total count of rows.

Clone this wiki locally