[Sugar-devel] Datastore API for html activities
Daniel Narvaez
dwnarvaez at gmail.com
Mon May 27 16:16:33 EDT 2013
Hello,
I'm landing bits of the datastore API, a couple of patches still
outstanding.
You create an object like this.
function onStream(outputStream) {
outputStream.write(arrayBuffer);
outputStream.close();
}
datastore.create(metadata, onStream, onCreated);
Then you can load the data for an object with something like
function onRead(arrayBuffer) {
}
function onStream(inputStream) {
inputStream.read(8192, onRead);
inputStream.close();
}
datastore.loadData(objectId, onStream);
Finally you can get the metadata for an object with
function onGotMetadata(metadata) {
}
datastore.getMetadata(objectId, onGotMetadata);
I consider this a low level layer, exposing the basic datastore operations.
We will have to build a friendlier API on top. There are a couple of things
that should be easier:
* Use in memory structures like text and blob rather then streams to
load/save the data.
* Use the default actiivity object rather than always specifying an
objectId.
I'm thinking of something like this.
Save an object
textObject = datastore.TextObject();
textObject.setText("Hello");
textObject.setMetadata({"title": "hello"});
textObject.save(onWrote);
Load an object
textObject = datastore.TextObject();
textObject.load(onGotText);
textObject.getMetadata(onGotMetadata);
The TextObject constructor would take an optional objectId. If not
specified it is the default activity object. Other type of objects could be
made available, datastore.BlobObject for example, with similar API.
Thoughts?
--
Daniel Narvaez
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20130527/36ae5c48/attachment.html>
More information about the Sugar-devel
mailing list