LocalStorage: Difference between revisions

Jump to navigation Jump to search
4,859 bytes removed ,  1 August 2005
remove the API and try to quickly describe the propsals
(remove the API and try to quickly describe the propsals)
Line 198: Line 198:
===APIs===
===APIs===


The apis have a few easy rules:
====The apis have a few easy rules====


1. Think about the use cases.
1. Think about the use cases.
Line 207: Line 207:
will) add those later through their own libraries.
will) add those later through their own libraries.


Known use cases:
====Known use cases====


1. Storage <-> XML-RPC bridge.  It's clear that people will want to
1. Storage <-> XML-RPC bridge.  It's clear that people will want to
Line 223: Line 223:
that XML document.
that XML document.


Deployment APIs
====Deployment APIs====


  window.supportsCapability(string aCapability);
A few different APIs have been proposed:


    Check to see if the api supports aCapability.
1. A database api that's based on a classic relational databaes model.  That is, tables and rows.


  Storage-related APIs
2. A simple dictionary system.  A single-level lookup based on a simple string key.


  Creating and querying storage types.
3. No APIJust the ability to just cache local pages.
 
  window.storage.create(string aName, dict aDescription)
 
    aName is the name of the storage.  The description is an array of
    dictionaries that describes the structure of the storageFor
    example:
 
    var desc = [ { name: "col1", type: "int", key: true },
                  { name: "col2", type: "string" },
                  { name: "col3", type: "cache" ]
    window.storage.create("foo", desc);
 
    The key: entry in the dictionary notes that this column will hold
    primary keys.
 
    Supported types include:
 
      int - An integer of size XXX.
 
      double - A floating point number of size XXX.
 
      string - A string in unicode format (UCS-2?  Should be at least
        UTF-8.)
 
      blob - A binary chunk of data.  Each entry can have its own
      mime type.  This mime type can be set by the application or is
      automatically set when the blob is filled from the network.
 
      cache - this special type is actually a double saying that the
      storage module should manage caching in this particular storage
      module.  If the application starts to fill to the maximum
      storage capacity, entries with lower values will be deleted
      before entries with higher values.  However, entries with
      negative values will never be deleted.  Applications can not
      predict when entries will be removed from the storage unit.
 
      Note: add a default mime type above to a column descriptor?
 
  window.storage.delete(string aName);
 
    Deletes a particular piece of storage by name.
 
  window.storage.getNames()
 
    Returns an array of strings with the names of all of the storage
    units defined.
 
  window.storage.getDesc(string aName);
 
    Returns an array of dictionaries describing the storage unit
    defined.  See window.storage.create() above.
 
  window.storage.addDataByName(string aName, dictionary aValues);
 
    This will add a new row to aName storage and the column names
    will be specified as the keys in aValues.
 
  window.storage.addData(string aName, array aValues);
 
    This will add a new row using the offset in the aValues array as
    the offset in the aName storage.
 
  window.storage.deleteDataByName(string aName, dictionary aValues);
 
    This will delete any rows in aName storage that match the
    key/value pairs in aValues.
 
  window.storage.deleteData(string aName, array aValues);
 
    This will delete any rows in aName storage that match the values
    specified in aValues.
 
  window.storage.getRowsByName(string aName, dictionary aValues);
 
    This will return any rows that match the specified values.  Note
    that there's no equiv. getRows() call.  This is because you have
    to be able to leave out rows for which you don't know the value
    and 'null' is the only way to pass that information in an array,
    and you should still be able to match against the 'null' value in
    the database.
 
  window.storage.search(string aName, searchDesc aSearchDescriptor);
 
    This is the powerful search function.  You will need to build a
    query object that allows you to search.
 
    The search descriptor is an array of dictionaries that includes
    arbitrarily complex search functions in reverse polish notion.
    For example:
 
    var foo = [ {and: [ {name: {equals: "bob"}}, {addr: {equals: "bar"}} ] }
                {or:  [ {status: {equals: "on"}} ] } ];
 
    This is the same as
 
    if ((name == "bob" && addr == "bar") || status == "on")
 
    Note: Ugly!  Can we just pass JS evals and then get the decision
    tree?  Also, string matching using substrings and regex?  How
    about user-defined functions?
 
  window.storage.getByName(string aName, object key)
 
    This assumes that you set the key attribute when you created the
    storage.  It will return the row that matches the key.
 
  window.storage.getByOffset(string aName, number offset)
 
    This will get the n-th offset item in the storage.
 
  window.storage.getCount(string aName)
 
    This will get the number of rows in aName storage.
 
  window.storage.iterate(string aName, func callback)
 
    This will iterate over every row in aName storage calling your
    callback for each one.
 
  window.storage.getUsageAllowed();
  window.storage.getUsage(string aName);
 
    getUsageAllowed() returns the number of bytes that the app can
    use for storage.  If you pass 'null' to getUsage it will return
    the total number of bytes in use.  getUsage with a storage name
    will give the number of bytes in use for a specific piece of
    storage.
 
  Notes:
 
    add .sort to sort a table?
 
    How about updates?
 
  Networking APIs
 
    How to specificy which specific row to download?  Maybe with a
    add()?  Should be something like:
 
    window.storage.addFromNetwork(aName, rowdesc, url);
 
    Same problem with setting the mime type for a particular row in a
    particular column - need a way to specify that.
6

edits

Navigation menu