Datastore API

Notes

  • For all functions, enter the parameters in the order listed.
  • Italicized parameters are optional.
  • Received Events are events of the "wrangler" domain that Wrangler will respond to
  • Raised Events are events that can be selected on within any ruleset in the pico when they occur
  • Sent Events are events that the pico will send elsewhere as a result of triggering a Wrangler event.

"io.picolabs.ds" must be installed on your pico for these to work

Functions


getItem

Returns the value mapped to the key under the given domain.

Returns

A KRL value. Can be NULL.

Parameters

ParameterDatatypeDescription
domainStringThe domain to query
keyStringThe key mapped to a requested value

Returns 

The value located for the key-value combination under that domain. Can be null if the value does not exist.

Example
item = getItem(meta:rid, numUsers)
/*
3723
*/

allDomainData

Returns all the key-value mappings for a certain datastore domain as a KRL map.

Parameters

ParameterDatatypeDescription
domainStringThe domain of the data to query for

viewStore

Returns the entire datastore as a KRL map.

Parameters

None

Returns 

A KRL map representing the entire datastore. Domains are mapped to maps of key-value pairs.

Received Events


ds_update

wrangler:ds_update

This event is used to update the datastore asynchronously.

Attributes

AttributeDatatypeDescription
domainStringThe domain of data to update

key

StringThe key whose corresponding value will be updated
valueAnyThe new value for the datastore entry.

Directives Returned

Will return empty directives.

Corresponding Raised Events


ds_clear_data

wrangler:ds_clear_data

Used to clear a value in the datastore. Has the same effect as passing nothing to the value attribute in wrangler:ds_update.

Attributes

AttributeDatatypeDescription
domainStringThe domain of data to update
keyStringThe key whose corresponding value will be deleted

Directives Returned

Will return empty directives.

ds_assign_map_to_domain

wrangler:ds_assign_map_to_domain

This event is used to update all data under a given domain. It takes a KRL map of key-value pairings to use as the new data for that domain. wrangler:ds_domain_updated is raised as a response. This event should be used sparingly, such as for migration purposes.

AttributeDatatypeDescription
domainStringThe domain of data to update with the map
mapMapThe new key-value mappings for the given domain

Corresponding Raised Events


Raised Events


ds_updated

wrangler:ds_updated

Raised as a response to wrangler:ds_update. It informs the listener of the new value in the datastore for the given domain and key.

AttributeDatatypeDescription
domainStringThe domain of the updated data
keyStringThe key for the updated data
valueAnyThe new value for the data at the given domain and key


ds_updated

wrangler:ds_domain_updated

Raised as a response to wrangler:ds_assign_map_to_domain. It informs the listener that all values for a domain have been updated with an entirely new map.

AttributeDatatypeDescription
domainStringThe domain whose data has been updated

Copyright Picolabs | Licensed under Creative Commons.