★ wanayoo — archive 1999 https://developer.mozilla.org/ja/docs/Web/API/Data_Store_APINouvelle recherche | Portail wanayoo
mozilla
Your Search Results

    Data Store API

    This article is in need of a technical review.

    This article is in need of an editorial review.

    この記事はまだ日本語に翻訳されていません。MDN の翻訳はボランティアによって行われています。是非 MDN に登録し、私たちの力になって下さい。

    Non-standard
    This feature is not on a current W3C standards track, but it is supported on the Firefox OS platform. Although implementations may change in the future and it is not supported widely across browsers, it is suitable for use in code dedicated to Firefox OS apps.

    This API is available on Firefox OS for certified applications only.

    The Data Store API provides a powerful, flexible storage mechanism for Firefox OS applications to use to store and share data. It is basically an intermediary store to allow multiple applications to share data between one another quickly, efficiently, and securely, in spite of differences between API data structures, formats, etc.

    Data Store API concepts and usage

    The Data Store API was created to allow multiple Firefox OS apps, with potentially different data structures and storage mechanisms, to create, maintain and share the same data objects efficiently between one another. Each app can then import the data into its own local IndexedDB to index according to their specific query needs. This is not necessary however, and you can just write directly to the Data Store API data store.

    Note: For more information on how Data Store API works, including a working example, consult the upcoming Using the Data Store API (TBD).

    There are several possible reasons to use this API, including:

    • It lets an application create data that it can then share with other applications.
    • It lets multiple applications supply data to the same data store.
    • It supports read-only data stores such as Facebook contacts (that is, it lets one app create and maintain the data while other apps can read the data from the store).
    • It supports read/write data stores, so that multiple applications can contribute data to the same data store. An example would be the device's standard contacts, which can be updated by both the built-in Contacts app and third-party apps.
    • It supports keeping an application-locale cache of a data store, with notifications to let the app know when there have been changes to the master data store so that the cache can be updated.

    This Data Store API datastore is owned by a specific app (as specified by the datastores-owned field in the app's manifest — see Manifest_fields, below), and this ownership gives the app the right to populate the data store and declare whether the data store is readonly (meaning other apps can only read the data) or readwrite (meaning other apps can modify the data as well as read it.) Other apps can gain access to a datastore by naming it in the datastores-access field of their app manifest.

    When an app wants to access a datastore, it has to call Navigator.getDataStores(); The result value of this method is a Promise object that will return an array of DataStore objects. From these DataStore objects, the app can read and modify values using various methods of the DataStore such as DataStore.get() and DataStore.insert().

    Note: The Data Store API currently has no imposed limitations on storage space. This is likely to be updated in the near future.

    Change management and conflict resolution

    When multiple apps make changes to a Data Store, it could create conflicts. However, any change you make (using DataStore.update(), DataStore.insert(), etc.) is given a revisionId, a UUID received in the change event fired whenever a operation is performed on the Data Store by any app with access to it. This can be read from the DataStore.revisionId property.

    The revisionId property can be included as an optional parameter in the DataStore.add(), DataStore.put(), DataStore.remove(), DataStore.clear(), and DataStore.sync() methods. Doing so basically uses that revisionId as a conflict avoider — the operation is aborted if that revisionId is not the last one known by the Data Store (i.e. if another app has made a more recent change).

    When the change event is fired, it receives a DataStoreChangeEvent object, giving the app access to:

    When an app wants to see what has changed, it can do it by asking for the ‘delta’ between the last known revisionId and the current one. This is done using the DataStore.sync() method. You can allow your apps to deal with data changes by running a sync() on application startup and onchange, passing it the current revisionId to check against.

    Filtering data

    As hinted at above, the Data Store API is not responsible for filtering data or building indexes; instead it leaves this up to the the app's local storage mechanism (usually an IndexedDB); The Data Store API simply allows the local indexes to be kept up to date, via the DataStoreCursor object, created when sync() is invoked.

    Manifest fields

    The data store owner's manifest MUST include the datastores-owned field to claim ownership, for example:

    {
      datastores-owned: {
        "myData": {
          "readonly": true,
          "description": "my data store"
        }
      }
    }

    You can include multiple properties to represent different data stores, and each one can use readonly/readwrite to specify whether the data store can be read/modified by other applications. A description is also included to describe the purpose of the data store.

    Applications that want to access the data store must include the datastores-access field, for example:

    {
      datastores-access: {
        "myData": {
          "access": "readwrite",
          "description": "Read and modify my data store"
        }
      }
    }

    Without this field being specified, the default behaviour is "no access". Again, multiple properties can be included if you want to access multiple data stores, and an access of readonly or readwrite can be set to declare what access type is needed by the app.

    In terms of permissions, the Data Store owner always wins against the 3rd party apps. if the owner declares "readonly": true in its manifest, any 3rd party app will be in readonly mode also, even if they declare "access": "readwrite" in their manifests. Of course, this isn’t much use if the owner allows the Data Store to be modified by third party apps, so for the moment, Data Store is a certified API. It is likely to come down to privileged when the security model is finalised.

    DataStore API Interfaces

    The Data Store API contains the following interfaces:

    DataStore
    The DataStore interface represents a retrieved set of data, and includes standard properties for accessing the store's name, owner, etc., methods for reading, modifying and syncing the data, and the onchange event handler for reacting to changes to the data.
    DataStoreCursor
    This interface allows the app to iterate through a list of DataStoreTask objects representing the change history of the data store, for use when synchronising the data.
    DataStoreChangeEvent
    This interface represents the event related to a date record changed in the data store, i.e. this is returned once the change event is fired.
    DataStoreTask
    This dictionary contains the information related to a data record changed in the data store.

    Example

    TBD

    Specifications

    Specification Status Comment
    Data Store API Draft  

    The discussion concerning this API's creation happened in various Mozilla mailing lists and other places. A summary of the discussion and further pointers can be found on the Mozilla Wiki. For further feedback and questions, send mail to the dev-webapi mailing list.

    Browser compatibility

    Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
    Basic support Not supported Not supported Not supported Not supported Not supported
    Feature Android Chrome Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
    Basic support Not supported Not supported Not supported 1.0.1 Not supported Not supported Not supported

    See also

    Document Tags and Contributors

    Contributors to this page: Ehsan, Sheppy, teoli, Subho612, chrisdavidmills
    最終更新者: chrisdavidmills,