aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/idbfactory
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/idbfactory
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/idbfactory')
-rw-r--r--files/zh-cn/web/api/idbfactory/index.html143
-rw-r--r--files/zh-cn/web/api/idbfactory/open/index.html79
2 files changed, 222 insertions, 0 deletions
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
+---
+<p>{{APIRef("IndexedDB")}}</p>
+
+<div>
+<p><a href="/en-US/docs/IndexedDB">IndexedDB API</a> 的<code>IDBFactory</code> 接口让程序可以异步存取 indexed databases。<code>window.indexedDB</code> 对象实现了这个接口。你可以通过这个对象而不是直接使用<code>IDBFactory</code>接口打开—— 创建或者连接 —— 和删除一个数据库。</p>
+</div>
+
+<h2 id="Methods">Methods</h2>
+
+<dl>
+ <dt>{{domxref("IDBFactory.open")}}</dt>
+ <dd>请求打开一个数据库的连接(<a href="https://developer.mozilla.org/en-US/docs/IndexedDB#gloss_database_connection">connection to a database</a>)。</dd>
+ <dt>{{domxref("IDBFactory.deleteDatabase")}}</dt>
+ <dd>请求删除数据库。</dd>
+ <dt>{{domxref("IDBFactory.cmp")}}</dt>
+ <dd>比较两个键的方法并返回一个结果,表明哪个值更大。</dd>
+ <dt>
+ <h3 id="过时的Methods">过时的Methods</h3>
+ </dt>
+ <dt><code><a href="https://developer.mozilla.org/en-US/docs/Web/API/IDBFactory.open-obsolete">IDBFactory.open</a></code>, the original version {{ obsolete_inline }}</dt>
+ <dd>一个被废弃的方法请求打开一个数据库的连接,仍然在一些浏览器中被实施(<a href="https://developer.mozilla.org/en-US/docs/IndexedDB#gloss_database_connection">connection to a database</a>).</dd>
+</dl>
+
+<h2 id="Example">Example</h2>
+
+<p>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 <a class="external" href="https://github.com/mdn/to-do-notifications/tree/gh-pages">To-do Notifications</a> app (<a class="external" href="http://mdn.github.io/to-do-notifications/">view example live</a>.)</p>
+
+<pre class="brush:js;highlight:[10]">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 += '&lt;li&gt;Error loading database.&lt;/li&gt;';
+};
+
+DBOpenRequest.onsuccess = function(event) {
+  note.innerHTML += '&lt;li&gt;Database initialised.&lt;/li&gt;';
+
+  // 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;
+};
+</pre>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('IndexedDB', '#idl-def-IDBFactory', 'IDBFactory')}}</td>
+ <td>{{Spec2('IndexedDB')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>23{{property_prefix("webkit")}}<br>
+ 24</td>
+ <td>10 {{property_prefix("moz")}}<br>
+ {{CompatGeckoDesktop("16.0")}}</td>
+ <td>10, partial</td>
+ <td>15</td>
+ <td>7.1</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>Firefox OS</th>
+ <th>IE Phone</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>4.4</td>
+ <td>{{CompatGeckoMobile("22.0")}}</td>
+ <td>1.0.1</td>
+ <td>10</td>
+ <td>22</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div class="warning">
+<p>Be careful in Chrome as it still implements the old specification along with the new one. Similarly it still has the prefixed <code>webkitIndexedDB</code> property even if the unprefixed <code>indexedDB</code> is present.</p>
+</div>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB">Using IndexedDB</a></li>
+ <li>Starting transactions: {{domxref("IDBDatabase")}}</li>
+ <li>Using transactions: {{domxref("IDBTransaction")}}</li>
+ <li>Setting a range of keys: {{domxref("IDBKeyRange")}}</li>
+ <li>Retrieving and making changes to your data: {{domxref("IDBObjectStore")}}</li>
+ <li>Using cursors: {{domxref("IDBCursor")}}</li>
+ <li>Reference example: <a class="external" href="https://github.com/mdn/to-do-notifications/tree/gh-pages">To-do Notifications</a> (<a class="external" href="http://mdn.github.io/to-do-notifications/">view example live</a>.)</li>
+</ul>
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
+---
+<p>{{APIRef("IDBFactory")}}</p>
+<div class="summary">
+ <p><strong><code>IDBFactory.open</code></strong> 方法用于<a href="/en-US/docs/IndexedDB#gloss_database_connection">打开一个数据库连接</a>。本方法立即返回一个 {{domxref("IDBOpenDBRequest")}} 对象,但打开数据库的操作是异步执行的。</p>
+</div>
+<p>连接数据库在一个单独的线程中进行,包括以下几个步骤:</p>
+<ol>
+ <li>指定数据库已经存在时:
+ <ul>
+ <li>等待 {{domxref("versionchange")}} 操作完成。</li>
+ <li>如果数据库已计划删除,那等着删除完成。</li>
+ </ul>
+ </li>
+ <li>如果已有数据库版本高于给定的 <code>version,中止操作并返回</code>类型为 <code style="font-size: 14px;">VersionError 的</code> <code>DOMError</code> 。</li>
+ <li>如果已有数据库版本低于给定的 <code>version,触发一个</code> <code>versionchange</code> 操作。</li>
+ <li>如果数据库不存在,创建指定名称的数据库,将版本号设置为给定版本,如果给定版本号,则设置为1,and no object stores.</li>
+ <li>创建数据库连接。</li>
+</ol>
+<p>如果操作成功执行,将触发 <code>success</code> 事件 on the request object that is returned from this method, with its <code>result</code> attribute set to the new {{domxref("IDBDatabase")}} object for the connection.</p>
+<p>If an error occurs while the database connection is being opened, then an <a href="/en-US/docs/IndexedDB/IDBErrorEvent">error event</a> is fired on the request object returned from this method.</p>
+<h2 id="Syntax">Syntax</h2>
+<p>For the current standard:</p>
+<pre class="syntaxbox"><span class="idlInterface" id="idl-def-IDBFactory"><span class="idlMethod"> <span class="idlMethType"><a class="idlType" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl-def-IDBOpenDBRequest"><code>IDBOpenDBRequest</code></a></span> <span class="idlMethName"><a href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBFactory-open-IDBOpenDBRequest-DOMString-name-unsigned-long-long-version">open</a></span> (<span class="idlParam"><span class="idlParamType">DOMString</span> <span class="idlParamName">name</span></span>, <span class="idlParam">[<span class="extAttr">EnforceRange</span>] optional <span class="idlParamType">unsigned long long</span> <span class="idlParamName">version</span></span>);</span></span></pre>
+<p>For the experimental version with <code>options</code> (see below):</p>
+<pre class="syntaxbox"><span class="idlInterface"><span class="idlMethod">IDBOpenDBRequest open (DOMString name, optional IDBOpenDBOptions options);</span></span></pre>
+<h2 id="示例">示例</h2>
+<p>For the current standard:</p>
+<pre class="brush: js">var request = window.indexedDB.open("toDoList", 4);</pre>
+<p>For the experimental version with <code>options</code> (see below):</p>
+<pre class="brush:js;"><code>var request = window.indexedDB.open("toDoList", {version: 4, storage: "temporary"});</code></pre>
+<h2 id="参数">参数</h2>
+<dl>
+ <dt>
+ name</dt>
+ <dd>
+ 数据库名称</dd>
+ <dt>
+ version</dt>
+ <dd>
+ 指定数据库版本,当你想要更改数据库格式(比如增加对象存储,非增加记录),必须指定更高版本,通过 <span style="font-family: 'Courier New', 'Andale Mono', monospace; line-height: normal;">versionchange 来更改</span></dd>
+ <dt>
+ options (version and storage) {{ NonStandardBadge() }}</dt>
+ <dd>
+ In Gecko, since <a href="/en-US/Firefox/Releases/26">version 26</a>, you can include an <code>options</code> object as a parameter of {{ domxref("IDBFactory.open") }} that contains the <code>version</code> number of the database, plus a storage value that specifies whether you want to use <code>permanent</code> (the default value) storage for the IndexedDB, or <code>temporary</code> 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.</dd>
+</dl>
+<div class="note">
+ <p><strong>Note</strong>: 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.</p>
+</div>
+<h2 id="返回">返回</h2>
+<dl>
+ <dt>
+ {{domxref("IDBOpenDBRequest")}}</dt>
+ <dd>
+ The request object on which subsequent events related to this request are fired.</dd>
+</dl>
+<h2 id="Exceptions">Exceptions</h2>
+<p>This method may raise a {{domxref("DOMException")}} with a <a href="/en-US/docs/DOM/DOMError">DOMError</a> of the following types:</p>
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Exception</th>
+ <th scope="col">描述</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><code>TypeError</code></td>
+ <td>The value of version is zero or a negative number or not a number.</td>
+ </tr>
+ </tbody>
+</table>
+<h2 id="Specifications">Specifications</h2>
+<p>{{page("/en-US/docs/Web/API/IDBFactory","Specifications")}}</p>
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+<p>{{page("/en-US/docs/Web/API/IDBFactory","Browser_compatibility")}}</p>