Got KRUD? In this KRL safari we will be using persistance variables as a database. While most web developers have written code to access a database, most Kynetx applications retrieve their data via RESTful web services. But there are times when a persistant data store is needed. Building a one off web service to host the data is certainly an option, but if the storage needs are moderate you can simply use a persistant variable. After all 2 million bytes of data can be stored in a persistant variable!

To keep the focus on the mechanics a simple data structure is used to demonstrate KRL CRUD ... an array of strings which will be used to implement a tag cloud. The demo provides a web interface to see all of the strings in the tag cloud, add new tags and delete tags. To permit the demo to be accessible to a broad audience, it has been distributed using a site tag. Just visit the demo page to see all of the current tags which have been entered by all who have used the application. You can add a new tag by entering text into the form, then click the Add button. To delete a existing tag simply click on the text of the tag.

While the KRL code has comments thoughout, it should be emphasized that application persistent variables accessed in the rule prelude:
TagCloud = app:TagCloud;
And the updated persistent variable are saved in the postlude:
set app:TagCloud TagCloud;
Adding a new value to the persistent variable is performed using the union operator:
newCloud = TagCloud.union(cleanTag);
Removing a value from the persistent variable is done using the difference operator:
newCloud = TagCloud.difference(tagText);
To see the implementation using a complex data structure take a look at Kynetx App A Day 28 Updating User's List When User Joins App.

Hey! Where's the U in KRUD? Multiple choice response:
  1. Left as an exercise for the reader
  2. Updated was not needed for demo
  3. I'm lazy :)