IDBIndexSync - Web APIs 编辑

Draft

This page is not complete.

Important: The synchronous version of the IndexedDB API was originally intended for use only with Web Workers, and was eventually removed from the spec because its need was questionable. It may however be reintroduced in the future if there is enough demand from web developers.

The IDBIndexSync interface of the IndexedDB API provides synchronous access to an index in a database.

Method overview

any add (in any value, in optional any key) raises (IDBDatabaseException);
any get (in any key) raises (IDBDatabaseException);
any getObject (in any key) raises (IDBDatabaseException);
void openCursor (in optional IDBKeyRange range, in optional unsigned short direction) raises (IDBDatabaseException);
void openObjectCursor (in optional IDBKeyRange range, in optional unsigned short direction) raises (IDBDatabaseException);
any put (in any value, in optional any key) raises (IDBDatabaseException);
void remove (in any key) raises (IDBDatabaseException);

Attributes

AttributeTypeDescription
keyPathreadonly DOMStringThe key path of this index. If this attribute is null, this index is not auto-populated.
namereadonly DOMStringThe name of this index.
storeNamereadonly DOMStringThis index's referenced object store.
uniquereadonly booleanIf true, a key can have only one value within the index; if false, a key can have duplicate values.

Methods

add()

Stores the given value into this index, optionally with the specified key. If a record already exists with the given key, an exception is raised.

any add(
  in any value,
  in optional any key
) raises (IDBDatabaseException);
Parameters
Returns
Exceptions

This method can raise a IDBDatabaseException with the following code:

value
The value to store into the index.
key
A key to use for identifying the record.
any
The key for the stored record.
CONSTRAINT_ERR
If a record exists in this index with a key corresponding to the key parameter or the index is auto-populated, or if no record exists with a key corresponding to the value parameter in the index's referenced object store.

get()

Retrieves the value from this index for the record that corresponds to the given key.

any get (
  in any key
) raises (IDBDatabaseException);
Parameters
key
The key that identifies the record to be retrieved.
Returns
any
The retrieved value from the index.
Exceptions

This method can raise an IDBDatabaseException with the following code:

NOT_FOUND_ERR
If no record exists in this index for the given key.

getObject()

Retrieves and returns the value from this index's referenced object store that corresponds to the given key.

any getObject (
  in any key
) raises (IDBDatabaseException);
Parameters
key
The key that identifies the record to be retrieved.
Returns
any
The retrieved value from the referenced object store.
Exceptions

This method can raise a IDBDatabaseException with the following code:

NOT_FOUND_ERR
If no record exists in this index for the given key.

openCursor()

Creates a cursor over the records of this index. The range of the new cursor matches the specified key range; if the key range is not specified or is null, then the range includes all the records.

void openCursor (
  in optional IDBKeyRange range,
  in optional unsigned short direction
) raises (IDBDatabaseException);
Parameters
range
The key range to use as the cursor's range.
direction
The cursor's required direction.
Returns

void

Exceptions

This method can raise an IDBDatabaseException with the following code:

NOT_FOUND_ERR
If no records exist in this index for the requested key range.

openObjectCursor()

Creates a cursor over the records of this index's referenced object store, as arranged by this index. The range of the new cursor matches the specified key range; if the key range is not specified or is null, then the range includes all the records.

void openObjectCursor (
  in optional IDBKeyRange range,
  in optional unsigned short direction
) raises (IDBDatabaseException);
Parameters
range
The key range to use as the cursor's range.
direction
The cursor's required direction.
Returns

void

Exceptions

This method can raise an IDBDatabaseException with the following code:

NOT_FOUND_ERR
If no records exist in this index for the requested key range.

put()

Stores the given value in this index and returns the key for the stored record. If a record already exists with the given key, the record is overwritten.

any put (
  in any value,
  in optional any key) raises (IDBDatabaseException);
Parameters
value
The value to be stored in the record.
key
The key to be used to identify the record.
Returns
any
The key for the stored record.

remove()

Removes from this index any records that correspond to the given key.

void remove (
  in any key
) raises (IDBDatabaseException);
Parameters
key
Key of the records to be removed.
Exceptions

This method can raise a DatabaseException with the following code:

NOT_FOUND_ERR
If a record does not exist in this index with the given key.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:59 次

字数:10439

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文