Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Grammar fix

...

Data in a data store can be updated through two different paths. The first is by giving a key-value pair for a domain by raising wrangler:ds_update and then responding to wrangler:ds_updated. The second is by changing all the key-value mappings under a domain by raising wrangler:ds_assign_map_to_domain with a new key-value map and reacting to wrangler:ds_domain_updated. It is recommended to use the latter way of updating sparingly, such as for data migration purposes.

...

Code Block
languagejs
themeConfluence
titleOn Updating Datastore ReadyData
/* An example of a rule that increments a counter value in the datastore */
rule incrementDS {
  select when test incrementDS
  pre {
    currentCounter = datastore:getItem(meta:rid, "counter")o.picolabs.wrangler.profile that selects on the initialization of the datastore 
    newValue = currentCounter.isnull() => 0 | currentCounter + 1
  }
  always {
    raise wrangler event "ds_update" attributes {
      "domain":meta:rid,	// The domain of the key-value pairings you want to manipulate
      "key":"counter",		// The key of the value you want to change
      "value":newValue		// The new value for the store
    }
  }
}

/* This rule reacts to wrangler:ds_updated to ensure that the counter we are incrementing 
	above is always even by checking if the new value in the store is divisible by 2 */
rule makeCounterEven {
  select when wrangler ds_updated
  pre {
    domain = event:attr("domain")
    key = event:attr("key")
    value = event:attr("value")
  }
  if domain == meta:rid && key == "counter" && value % 2 == 1 then
  noop()
  fired {
    raise wrangler event "ds_update" attributes event:attrs.put("value", value + 1)
  }
}

...