Class ydn.db.Key

An instance of the Key class represents a unique key for a object store record.

Constructor
Create a key from JSON formatted object.
Parameters:
{!Object} json
JSON formatted object.
var k1 = new ydn.db.Key({"store_name": "player", "id": 1});
ydn.db.Key(key_string)
Create a key from serialized key string.
var key_string = key.valueOf();
var same_key = new ydn.db.Key(key_string);
Parameters:
{string} key_string
Serialized key string object.
ydn.db.Key(store_name, id)
Create a key with store name and id.
Parameters:
{string} store_name
Store name.
{string|number|!Array} id
Id as specified in keyPath or auto generated.
ydn.db.Key(store_name, id, parent_key)
Create a key with a parent key.
var key = new ydn.db.Key('player', 1);
var child_key = new ydn.db.Key('game', 1, key);
Parameters:
{string} store_name
Store name.
{string|number} id
Id as specified in keyPath or auto generated.
{ydn.db.Key} parent_key
Parent key.
ydn.db.Key(store_name, id, parent_store_name, parent_id, ...)
Create a key with ancestor store name and id pairs.
Previous example with parent_key can be rewriten as:
var child_key = new ydn.db.Key('player', 1, 'game', 1);

Parameters:
{string} store_name
Store name.
{string|number} id
Id as specified in keyPath or auto generated.
Method
id()
Get id.
Returns:
{string} return id.

parent()
Get the parent key.
Returns:
{ydn.db.Key} return the parent key. null if no parent.

storeName()
Get store name.
Returns:
{string} return store name.

toJSON()
Get key in JSON format.
Returns:
{!Object} object JSON object. It is used to reconstruct the key.

valueOf(value)
Get key value as serialized string.
Returns:
{string} key value.