Tutorial: Data navigation

Step by step Data navigation

Before doing any [[service]] operations you need a Webcom reference which is a pointer to a location inside your [[service]] database.

You create a new Webcom reference by specifying the location you would like to access, as a URL

var sampleChatRef = new Webcom('[[baseUrl]]/base/samplechat');
Webcom sampleChatRef = new Webcom("[[baseUrl]]/base/samplechat");
var sampleChatRef: WCWebcom = WCWebcom(url: "[[baseUrl]]/base/samplechat")!

Creating a Webcom reference is an extremely light-weight operation, so you can create as many as you like without worrying about wasting bandwidth or memory.

Since references are created so often in [[service]] applications, there are a couple of helper functions to make constructing them easier.

First, each reference has a function that takes the path to a child and returns a reference pointing to that child location

var childRef = sampleChatRef.child('users');
// This is equivalent to:
var childRef = new Webcom('[[baseUrl]]/base/samplechat/users');
Webcom childRef = sampleChatRef.child("users");
// This is equivalent to:
Webcom childRef = new Webcom("[[baseUrl]]/base/samplechat/users");
var childRef : WCWebcom =  sampleChatRef.child("users")!
// This is equivalent to:
var childRef: WCWebcom = WCWebcom(url: "[[baseUrl]]/base/samplechat/users")!

Second, each reference has a function that returns a reference to its parent location.

var parentRef = childRef.parent();
// parentRef and sampleChatRef now point to the same location.
Webcom parentRef = childRef.parent();
// parentRef and sampleChatRef now point to the same location.
var parentRef: WCWebcom = childRef.parent!
// parentRef and sampleChatRef now point to the same location.

Here are several ways of creating a reference that points to the same [[service]] location.

var usersRef = sampleChatRef.child('users');
var fredRef = usersRef.child('fred');
// is equivalent to:
var fredRef = sampleChatRef.child('users/fred');

var messageListRef = fredRef.parent().parent().child('message_list');
// is equivalent to:
var messageListRef = new Webcom('[[baseUrl]]/base/samplechat/message_list');
Webcom usersRef = sampleChatRef.child("users");
Webcom fredRef = usersRef.child("fred");
// is equivalent to:
Webcom fredRef = sampleChatRef.child("users/fred");

Webcom messageListRef = fredRef.parent().parent().child("message_list");
// is equivalent to:
Webcom messageListRef = new Webcom("[[baseUrl]]/base/samplechat/message_list");
var usersRef : WCWebcom =  sampleChatRef.child("users")!
var fredRef : WCWebcom =  usersRef.child("fred")!
// is equivalent to:
var fredRef: WCWebcom = sampleChatRef.child("users/fred")!

var messageListRef : WCWebcom = fredRef.parent.parent.child("message_List")!
// is equivalent to:
var messageListRef : WCWebcom = WCWebcom(url:"[[baseUrl]]/base/samplechat/message_list")!

Once you have a Webcom reference, you can use it to read, write, and query that location using the other Webcom API functions.