From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/idbfactory/index.html | 143 +++++++++++++++++++++++++ files/zh-cn/web/api/idbfactory/open/index.html | 79 ++++++++++++++ 2 files changed, 222 insertions(+) create mode 100644 files/zh-cn/web/api/idbfactory/index.html create mode 100644 files/zh-cn/web/api/idbfactory/open/index.html (limited to 'files/zh-cn/web/api/idbfactory') diff --git a/files/zh-cn/web/api/idbfactory/index.html b/files/zh-cn/web/api/idbfactory/index.html new file mode 100644 index 0000000000..d17304647b --- /dev/null +++ b/files/zh-cn/web/api/idbfactory/index.html @@ -0,0 +1,143 @@ +--- +title: IDBFactory +slug: Web/API/IDBFactory +translation_of: Web/API/IDBFactory +--- +

{{APIRef("IndexedDB")}}

+ +
+

IndexedDB API 的IDBFactory 接口让程序可以异步存取 indexed databases。window.indexedDB 对象实现了这个接口。你可以通过这个对象而不是直接使用IDBFactory接口打开—— 创建或者连接 —— 和删除一个数据库。

+
+ +

Methods

+ +
+
{{domxref("IDBFactory.open")}}
+
请求打开一个数据库的连接(connection to a database)。
+
{{domxref("IDBFactory.deleteDatabase")}}
+
请求删除数据库。
+
{{domxref("IDBFactory.cmp")}}
+
比较两个键的方法并返回一个结果,表明哪个值更大。
+
+

过时的Methods

+
+
IDBFactory.open, the original version {{ obsolete_inline }}
+
一个被废弃的方法请求打开一个数据库的连接,仍然在一些浏览器中被实施(connection to a database).
+
+ +

Example

+ +

In the following code snippet, we make a request to open a database, and include handlers for the success and error cases. For a full working example, see our To-do Notifications app (view example live.)

+ +
var note = document.querySelector("ul");
+
+// In the following line, you should include the prefixes of implementations you want to test.
+window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
+// DON'T use "var indexedDB = ..." if you're not in a function.
+// Moreover, you may need references to some window.IDB* objects:
+window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction;
+window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange;
+// (Mozilla has never prefixed these objects, so we don't need window.mozIDB*)
+
+// Let us open version 4 of our database
+var DBOpenRequest = window.indexedDB.open("toDoList", 4);
+
+// these two event handlers act on the database being opened successfully, or not
+DBOpenRequest.onerror = function(event) {
+  note.innerHTML += '<li>Error loading database.</li>';
+};
+
+DBOpenRequest.onsuccess = function(event) {
+  note.innerHTML += '<li>Database initialised.</li>';
+
+  // store the result of opening the database in the db variable. This is used a lot later on, for opening transactions and suchlike.
+  db = request.result;
+};
+
+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('IndexedDB', '#idl-def-IDBFactory', 'IDBFactory')}}{{Spec2('IndexedDB')}} 
+ +

Browser compatibility

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support23{{property_prefix("webkit")}}
+ 24
10 {{property_prefix("moz")}}
+ {{CompatGeckoDesktop("16.0")}}
10, partial157.1
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Basic support4.4{{CompatGeckoMobile("22.0")}}1.0.11022{{CompatNo}}
+
+ +
+

Be careful in Chrome as it still implements the old specification along with the new one. Similarly it still has the prefixed webkitIndexedDB property even if the unprefixed indexedDB is present.

+
+ +

See also

+ + diff --git a/files/zh-cn/web/api/idbfactory/open/index.html b/files/zh-cn/web/api/idbfactory/open/index.html new file mode 100644 index 0000000000..832a4ee7b2 --- /dev/null +++ b/files/zh-cn/web/api/idbfactory/open/index.html @@ -0,0 +1,79 @@ +--- +title: IDBFactory.open +slug: Web/API/IDBFactory/open +translation_of: Web/API/IDBFactory/open +--- +

{{APIRef("IDBFactory")}}

+
+

IDBFactory.open 方法用于打开一个数据库连接。本方法立即返回一个 {{domxref("IDBOpenDBRequest")}} 对象,但打开数据库的操作是异步执行的。

+
+

连接数据库在一个单独的线程中进行,包括以下几个步骤:

+
    +
  1. 指定数据库已经存在时: +
      +
    • 等待 {{domxref("versionchange")}} 操作完成。
    • +
    • 如果数据库已计划删除,那等着删除完成。
    • +
    +
  2. +
  3. 如果已有数据库版本高于给定的 version,中止操作并返回类型为 VersionError 的 DOMError 。
  4. +
  5. 如果已有数据库版本低于给定的 version,触发一个 versionchange 操作。
  6. +
  7. 如果数据库不存在,创建指定名称的数据库,将版本号设置为给定版本,如果给定版本号,则设置为1,and no object stores.
  8. +
  9. 创建数据库连接。
  10. +
+

如果操作成功执行,将触发 success 事件 on the request object that is returned from this method, with its result attribute set to the new {{domxref("IDBDatabase")}} object for the connection.

+

If an error occurs while the database connection is being opened, then an error event is fired on the request object returned from this method.

+

Syntax

+

For the current standard:

+
 IDBOpenDBRequest open (DOMString name, [EnforceRange] optional unsigned long long version);
+

For the experimental version with options (see below):

+
IDBOpenDBRequest open (DOMString name, optional IDBOpenDBOptions options);
+

示例

+

For the current standard:

+
var request = window.indexedDB.open("toDoList", 4);
+

For the experimental version with options (see below):

+
var request = window.indexedDB.open("toDoList", {version: 4, storage: "temporary"});
+

参数

+
+
+ name
+
+ 数据库名称
+
+ version
+
+ 指定数据库版本,当你想要更改数据库格式(比如增加对象存储,非增加记录),必须指定更高版本,通过 versionchange 来更改
+
+ options (version and storage) {{ NonStandardBadge() }}
+
+ In Gecko, since version 26, you can include an options object as a parameter of {{ domxref("IDBFactory.open") }} that contains the version number of the database, plus a storage value that specifies whether you want to use permanent (the default value) storage for the IndexedDB, or temporary storage (aka shared pool.) See {{ bug("785884") }} for more details. This is a non-standard feature that we are looking to standardise sometime in the future.
+
+
+

Note: Data in temporary storage persists until the global limit for the pool is reached. The global limit calculation is relatively complex, but we are considering changing it (see  {{ Bug("968272") }}). When the global limit is reached, then data for the least recently used origin is deleted. There's also a group limit (eTLD+1 group/domain) which is currently 20% of the global limit. All requets that would exceed the group limit are just rejected.

+
+

返回

+
+
+ {{domxref("IDBOpenDBRequest")}}
+
+ The request object on which subsequent events related to this request are fired.
+
+

Exceptions

+

This method may raise a {{domxref("DOMException")}} with a DOMError of the following types:

+ + + + + + + + + + + + + +
Exception描述
TypeErrorThe value of version is zero or a negative number or not a number.
+

Specifications

+

{{page("/en-US/docs/Web/API/IDBFactory","Specifications")}}

+

浏览器兼容性

+

{{page("/en-US/docs/Web/API/IDBFactory","Browser_compatibility")}}

-- cgit v1.2.3-54-g00ecf