www.webOShelp.net

Get the latest on:webOS Developers' RSS FeedwebOS Facebook page webOS Twitter Feed

Home Getting Started with webOS Digging into the Depot

Digging into the Depot

The webOS Mojo object Depot provides a simplified interface to the native HTML 5 database API. Palm recommends using Depot instead of the native API if:

  • You are storing simple objects for offline data access
  • You don't need a schema design
  • You don't need to handle transactions or queries.

Depots are currently limited to 5 megabytes of data per object.

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

  • simpleGet() calls the provided success method, passing the object retrieved if it
    exists, or failure if no object matches the key.
  • simpleAdd() updates the value of the named object.
  • removeAll() removes the named depot and deletes the associated data.

Like cookies, you can use the Depot constructor to create a new Depot or open an existing one by providing a unique key to identify the Depot. Depot calls are asynchronous, so you will need to define a callback function to receive the returned data. Depot allows you to store and retrieve data in JSON format, automatically converting between JSON and SQL.

Palm warns that Depot is "not very efficient" and that using it for complex objects "can impact application performance and memory". Complex objects include:

  • Deep hierarchy
  • Multiple object layers
  • Array and object datatypes
  • Large strings

Click here for a detailed example of setting up and using a depot.

That concludes our coverage of Mojo's Depot API. Tomorrow we'll revisit the most powerful method of local data storage in webOS: the HTML5 database storage API.

This is one of many daily development-related webOS articles. Grab the RSS feed to stay in the know!

Much of the information in this article was presented in Chapter 6 of Palm webOS by Mitch Allen.

 

0 Comments

    Add Comment


      • >:o
      • :-[
      • :'(
      • :-(
      • :-D
      • :-*
      • :-)
      • :P
      • :\
      • 8-)
      • ;-)