The Skinny On...
Datastore
This is probably the one everybody wants to know about. How to I save and restore data?
The Reasonably Smart Platform operates with an object store rather than a traditional database, so you're not going to operate in quite the same way as a traditional SQL RDBMS.
All of the datastore methods are attached to the
system.datastore object.
The functions are as follows:
-
Boolean write( String type, Object obj, Boolean isTransient )The write function saves an object to the datastore. The first parameter the write function takes is the type parameter. This can be used to create classes of objects in the datastore.
The second paramter is the object you'd like written to the datastore. The only requirement is that object has an
String idproperty that will uniquely identify it in the system. You can create these yourself, or use the UUID extension.Finally the final, optional parameter is the isTransient parameter, which lets the datastore know if the data needs to be recorded into permanent storage, or if fast, memory based storage is acceptable. Obviously the data can be lost if the inTransient parameter is true, but it's useful for things like sessions.
-
Boolean write( [ String aType, Object, Boolean isTransient ], [ String aType, ... ] )Works in the same way as the one-object form of write with multiple objects. If one object fails no data will be written and write will return 0.
-
Boolean remove( String type, String id )The remove function removes an object from the datastore. Similar to the
write()function, it takes the objects type as its first parameter.The second parameter is the id of the object.
-
Array search(String type, Object query)The search function queries the datastore for objects of the type
typethat match your request. Your request takes the form of an object with key value pairs that represent the data you want to match.There are planned enhancements to the search function that will improve the types of searches you can perform.
-
Object get( String type, String id )The get function fetches a single object of a type
typefrom the datastore that has an id ofid.If no such object exists an empty object is returned.
