Skip to main content

realm

Realm Usage

Once you've retrieved a realm using client.realm.get('realmId'), you can use it to access other concepts within it via e.g. realm.object.get(id) or realm.area.create(...) - or you can manipulate the realm itself using the following methods:

realm.getData(key)

Retrieve metadata associated with a realm.

  • key (optional) If ommited, returns the entire realm data, otherwise returns the data for the given key.
tip

The metadata for realms is extremely useful when it comes to storing data that's global to a given realm. For our own app, we use realm metadata to store object categories, colors, icons and the UI widget configuration for each category. But it's also useful to store other things that are not directly related to a single object, area or other entity.

realm.setData(key,value)

Sets an entry in the realm's metadata. Returns a promise that resolves once writing the data was succesful.

  • key the key under which to store the data
  • value a string, number or object to be stored under that key

realm.setLabel(label)

Update the label for the given realm. Returns a promise that resolves once setting the label was succesful.

Searching

Hivekit makes it easy to search through objects and areas within a realm.

realm.search(searchString, options)

  • searchString a string value you want to search for
  • options (optional) an object with search options. Defaults are
    • field: ['data', 'label', 'id' ] where to search
    • maxObjectResults: 999 the max amount of object matches to return
    • maxAreaResults: 999 the max amount of object matches to return
const searchResult = await realm.search('Jeff');

// search result now gives us a series of matches
[
{
// this data describes the object or area that matched the search term
"id": "object-bCLulCjqG9AXis6DVcClN",
"type": "object",
"label": "Jeff Goldblum",

// field is where the match was found. In this case in the label
"field": "label",

// the value of the field that matched the query
"value": "Jeff Goldblum",

// the string position of the match. Useful if you want to
// do substring highlighting in your search results.
"start": 0,
"end": 4,

//If the matching field is an entry in data (like below) this
//specifies in which property the match was found.
"dataProperty": ""
},

// here, the result was found in the property "best_friend"
// within the data of an object
{
"id": "object-4tNJBFThw_x0pmmBlwwZ5",
"type": "object",
"label": "Mike Smith",

// Result was found in data
"field": "data",
// In the value "Jeff Stein"
"value": "Jeff Stein",
"start": 0,
"end": 4,

// in the data property best_fried
"dataProperty": "best_friend"
}
]