Dropbox Now Can Hold Structured Data with Datastore API
Dropbox has released Datastore API which provides access to key-value stores with support for synchronization between devices using the user’s Dropbox account and including automatic conflict resolution.
Datastore API allows applications to store structured data in user’s Dropbox account, with built-in support for synchronizing changes between various devices and automatic conflict resolution. The API supports offline activities, operating updates when the Internet connection is back.
A Datastore is organized in tables which contain records consisting of an ID and a set of fields. Each field has a name and a value. Supported value types are:
- Integer. 64 bits, signed
- Floating point. IEEE double
- Date. POSIX millisecond timestamp
- Bytes. Binary data such as images or compressed data. Since each record has a size limit of 100KB, storing larger amounts of data can be done by using Dropbox files accessed through Sync API. The field would contain a reference to the file.
- List. A list of above mentioned values. It cannot contain other lists. They support basic operations: put, move, insert, and delete.
The datastore does not have a schema, allowing records with different number of fields, but it is recommended for “all the records in a table to have roughly the same fields so you can query over them.” Multiple tables and datastores can be created to accommodate developer’s needs.
An application is limited to 5MB across all its datastores without using a user’s storage quota. Above that limit, the application starts using the user’s Dropbox quota, and writing no longer works if its limit is reached.
Following is an Android sample showing how to open the default datastore, create a new table, insert a new record having two fields,
completed, then sync the in-memory data with Dropbox.
DbxDatastore store = DbxDatastore.openDefault(mAccount);
DbxTable tasksTbl = store.getTable("tasks");
DbxRecord firstTask = tasksTbl.insert().set("taskname", "Buy milk").set("completed", false);
Registered listeners will be informed when a sync operation takes place so they can proceed as needed. This is how datastore operations are propagated among devices.
Olav Maassen, Liz Keogh & Chris Matts Mar 08, 2014