Realtime Cloud Storage
Working with items

  • Feb 27, 2015
  • Starting Guide

In Realtime Cloud Storage, an item is a collection of attributes. Each attribute has a name and a value. An attribute value can be a number or a string or a set of any of these types. When you add an item, the key schema attribute(s) (primary key or primary key + secondary key) are the only required attributes. In addition to the primary key, an item can have any number of attributes, although there is a limit of 400 KB on the item size. An item size is the sum of lengths of its attribute names and values (UTF-8 lengths); it helps if you keep the attribute names short.

Except for the key schema, there is no predefined schema for the items in a table. This means different items in the same table can have different attributes. In a ProductCatalog table, among other common attributes like Price, you might have a book with the ISBN attribute and a bicycle with the Color attribute, like the following screenshot shows.

Here’s an example using the JavaScript SDK that retrieves every item in the ProductCatalog table and writes the Price attribute to the console:

// Get a reference for table ProductCatalog

var tableRef = storageRef.table("ProductCatalog");
 
// Get all items from table ProductCatalog
 
tableRef.getItems(function(itemSnapshot) {
  if (itemSnapshot) {
    console.log("Item retrieved: ", itemSnapshot.val().Price);
  } else {
    console.log("No more items in table");
  }
},
function(error) {
  console.log("Oops, error retrieving items:", error);
});

Realtime Cloud Storage provides APIs to add, retrieve, update, and delete items. For further details see the Complete Reference for your preferred programming language at http://framework.realtime.co/storage/#documentation

Back to Working with tables or proceed to Applying filters

If you find this interesting please share: