Working with the Depot

If you are only interested in a simple object store without any database queries or structure, Depot will likely meet your needs. You can store up to 1 MB of data in a depot by default. Mojo provides a few simple functions that wrap the HTML 5 APIs to create, read, update, or delete a database.

Mojo.Depot() opens the depot that matches the name argument. If there is no match, it creates a new depot with that name. There are four methods:

get()

Calls the provided onSuccess handler with the retrieved object (or null if nothing matches the key). onFailure is called if an error occurs in accessing the database.

discard()

Removes the data associated with the key from the database.

add()

Updates the value of the named object.

removeAll()

Removes all data in the database by dropping the tables.

The Depot is simple to use. As with Cookie, you call Depot’s constructor with a unique name to create a new store or open an existing one. Unlike Cookie, Depot calls are asynchronous, so you will do most of your handling in callback functions. Once opened, you can save and retrieve any JavaScript object. To simplify your data handling, the Depot function will flatten the object so that it can be stored using SQL.

You do need to keep this to simple objects, as Depot is not very efficient, and if you extend it to complex objects it can impact application performance and memory. JSON objects are recommended as the best-performing. Beyond that you’ll have to experiment to see how the Depot ...

Get Palm webOS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.