[Sugar-devel] Datastore API for html activities (Daniel Narvaez)

lionel at olpc-france.org lionel at olpc-france.org
Tue May 28 03:06:58 EDT 2013


Nice job Daniel.

Few quick remarks:
- What about the Datastore Activity API (i.e. read_file and write_file)?
it's the most common way for an activity to use the Datastore,
- A Find feature with metadata critera is need,
- May be we should also provide some callbacks for Created/Updated/Deleted
event on an object.

	Lionel.


------------------------------

Date: Mon, 27 May 2013 22:16:33 +0200
From: Daniel Narvaez <dwnarvaez at gmail.com>
To: "sugar-devel at lists.sugarlabs.org"
	<sugar-devel at lists.sugarlabs.org>
Subject: [Sugar-devel] Datastore API for html activities
Message-ID:
	<CANTHhvb+7P_hZbfqGw0GE3WU9rpOvHYTFzJ7HtGkYsBsEswduQ at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

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/36ae5c4
8/attachment-0001.html>



More information about the Sugar-devel mailing list