IDBDatabaseSync - 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 DatabaseSync interface in the IndexedDB API represents a synchronous connection to a database.

Method overview

IDBObjectStoreSync createObjectStore (in DOMString name, in DOMString keypath, in optional boolean autoIncrement) raises (IDBDatabaseException);
IDBObjectStoreSync openObjectStore (in DOMString name, in optional unsigned short mode) raises (IDBDatabaseException);
void removeObjectStore (in DOMString storeName) raises (IDBDatabaseException);
void setVersion (in DOMString version);
IDBTransactionSync transaction (in optional DOMStringList storeNames, in optional unsigned int timeout) raises (IDBDatabaseException);

Attributes

AttributeTypeDescription
descriptionreadonly DOMStringThe human-readable description of the connected database.
namereadonly DOMStringThe name of the connected database.
objectStoresreadonly DOMStringListThe names of the object stores that exist in the connected database.
versionreadonly DOMStringThe version of the connected database. Has the null value when the database is first created.

Methods

createObjectStore()

Creates and returns a new object store with the given name in the connected database.

 IDBObjectStoreSync createObjectStore(
  in DOMString name,
  in DOMString keypath,
  in optional boolean autoIncrement
) raises  (IDBDatabaseException);
Parameters
name
The name of a new object store.
keypath
The key path used by the new object store. If a null path is specified, then the object store does not have a key path, and uses out-of-line keys.
autoIncrement
If true, the object store uses a key generator; if false, it does not use one.
Returns
IDBObjectStoreSync
An object to access the newly created object store.
Exceptions

This method can raise an IDBDatabaseException with the following code:

CONSTRAINT_ERR
If an object store with the same name (based on case-sensitive comparison) already exists in the connected database.

openObjectStore()

Opens the object store with the given name in the connected database using the specified mode.

IDBObjectStoreSync openObjectStore (
  in DOMString name,
  in optional unsigned short mode
) raises (IDBDatabaseException);
Parameters
name
The name of the object store to open.
mode
The mode that is used to access the object store.
Returns
IDBObjectStoreSync
An object to access the opened object store.
Exceptions

This method can raise an IDBDatabaseException with the following code:

NOT_FOUND_ERR
If an object store with the given name (based on case-sensitive comparison) already exists in the connected database.

removeObjectStore()

Destroys an object store with the given name, as well as all indexes that reference that object store.

void removeObjectStore (
  in DOMString storeName
) raises (IDBDatabaseException);
Parameters
storeName
The name of an existing object store to remove.
Returns

void

Exceptions

This method can raise an IDBDatabaseException with the following code:

NOT_FOUND_ERR
If the object store with the given name (based on case-sensitive comparison) does not exist in the connected database.

setVersion()

Sets the version of the connected database.

void setVersion (
  in DOMString version
);
Parameters
Returns

void

version
The version to store in the database.

transaction()

Creates and returns a transaction, acquiring locks on the given database objects, within the specified timeout duration, if possible.

IDBTransactionSync transaction (
  in optional DOMStringList storeNames,
  in optional unsigned int timeout
) raises (IDBDatabaseException);
Parameters
storeNames
The names of object stores and indexes in the scope of the new transaction.
timeout
The interval that this operation is allowed to take to acquire locks on all the objects stores and indexes identified in storeNames.
Returns
IDBTransactionSync
An object to access the newly created transaction.
Exceptions

This method can raise an IDBDatabaseException with the following code:

TIMEOUT_ERR
If reserving all the database objects identified in storeNames takes longer than the timeout interval.

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

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

发布评论

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

词条统计

浏览:80 次

字数:8826

最后编辑:7年前

编辑次数:0 次

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