Interface nsIKeyValueDatabaseType

A key/value database.

All methods are asynchronous and take a callback as their first argument. The types of the callbacks vary, but they can all be implemented in JS via an object literal with the relevant methods.

Hierarchy

Methods

  • Increases the reference count for this interface. The associated instance will not be deleted unless the reference count is returned to zero.

    Returns

    The resulting reference count.

    Returns number

  • Parameters

    • aIID: object
    • Optional aInstancePtr: object

    Returns any

  • A run time mechanism for interface discovery.

    Returns

    NS_OK if the interface is supported by the associated instance, NS_NOINTERFACE if it is not.

    aInstancePtr must not be null.

    Parameters

    • aIID: object

      [in] A requested interface IID

    • aInstancePtr: object

      [out] A pointer to an interface pointer to receive the result.

    Returns void

  • Decreases the reference count for this interface. Generally, if the reference count returns to zero, the associated instance is deleted.

    Returns

    The resulting reference count.

    Returns number

  • Clear all the key/value pairs from the database.

    Parameters

    • callback: nsIKeyValueVoidCallback

    Returns void

  • Remove the key/value pair with the given key from the database.

    If the given key doesn't exist in the database, this operation doesn't fail; or rather, it fails silently, calling the resolve() method of its callback rather than reject(). If you want to know whether or not a key exists when deleting it, call the has() method first.

    Parameters

    • callback: nsIKeyValueVoidCallback
    • key: string

    Returns void

  • Enumerate key/value pairs, starting with the first key equal to or greater than the "from" key (inclusive) and ending with the last key less than the "to" key (exclusive) sorted lexicographically.

    If either key is omitted, the range extends to the first and/or last key in the database.

    Parameters

    • callback: nsIKeyValueEnumeratorCallback
    • fromKey: string
    • toKey: string

    Returns void

  • Retrieve the value of the specified key from the database.

    If the key/value pair doesn't exist in the database, and you specify a default value, then the default value will be returned. Otherwise, the callback's resolve() method will be called with a variant of type VTYPE_EMPTY, which translates to the JS null value.

    Parameters

    • callback: nsIKeyValueVariantCallback
    • key: string
    • defaultValue: nsIVariant

    Returns void

  • Determine whether or not the key exists in the database.

    Parameters

    • callback: nsIKeyValueVariantCallback
    • key: string

    Returns void

  • Write the specified key/value pair to the database.

    Parameters

    • callback: nsIKeyValueVoidCallback
    • key: string
    • value: nsIVariant

    Returns void

  • Write multiple key/value pairs to the database.

    It supports two types of write:

    • Put a key/value pair into the database. It takes a nsIKeyValuePair where its key and value follow the same types as the put() method.
    • Delete a key/value pair from database. It takes a nsIkeyValuePair where its value property must be null or undefined.

    This features the "all-or-nothing" semantics, i.e. if any error occurs during the call, it will rollback the previous writes and terminate the call. In addition, writeMany should be more efficient than calling "put" or "delete" for every single key/value pair since it does all the writes in a single transaction.

    Note:

    • If there are multiple values with the same key in the specified pairs, only the last value will be stored in the database.
    • Deleting a key that is not in the database will be silently ignored.
    • If the same key gets put and deleted for multiple times, the final state of that key is subject to the ordering of the put(s) and delete(s).

    Parameters

    • callback: nsIKeyValueVoidCallback
    • pairs: invalid

    Returns void

Generated using TypeDoc