diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:52 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:52 -0500 |
commit | 074785cea106179cb3305637055ab0a009ca74f2 (patch) | |
tree | e6ae371cccd642aa2b67f39752a2cdf1fd4eb040 /files/ru/web/api/idbindex | |
parent | da78a9e329e272dedb2400b79a3bdeebff387d47 (diff) | |
download | translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.gz translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.bz2 translated-content-074785cea106179cb3305637055ab0a009ca74f2.zip |
initial commit
Diffstat (limited to 'files/ru/web/api/idbindex')
-rw-r--r-- | files/ru/web/api/idbindex/index.html | 139 | ||||
-rw-r--r-- | files/ru/web/api/idbindex/locale/index.html | 76 |
2 files changed, 215 insertions, 0 deletions
diff --git a/files/ru/web/api/idbindex/index.html b/files/ru/web/api/idbindex/index.html new file mode 100644 index 0000000000..96a9337966 --- /dev/null +++ b/files/ru/web/api/idbindex/index.html @@ -0,0 +1,139 @@ +--- +title: IDBIndex +slug: Web/API/IDBIndex +tags: + - API + - Database + - IDBIndex + - IndexedDB + - Interface + - NeedsTranslation + - Reference + - Storage + - TopicStub +translation_of: Web/API/IDBIndex +--- +<p>{{APIRef("IndexedDB")}}</p> + +<p><span class="seoSummary"><code>IDBIndex</code> interface of the <a href="/en/IndexedDB" title="en/IndexedDB">IndexedDB API</a> provides asynchronous access to an <a href="/en/IndexedDB/Basic_Concepts_Behind_IndexedDB#gloss_index" title="en/IndexedDB/Basic_Concepts_Behind_IndexedDB#gloss_index">index</a> in a database. An index is a kind of object store for looking up records in another object store, called the referenced object store. You use this interface to retrieve data.</span></p> + +<p>You can retrieve records in an object store through the primary key or by using an index. An index lets you look up records in an object store using properties of the values in the object stores records other than the primary key</p> + +<p>The index is a persistent key-value storage where the value part of its records is the key part of a record in the referenced object store. The records in an index are automatically populated whenever records in the referenced object store are inserted, updated, or deleted. Each record in an index can point to only one record in its referenced object store, but several indexes can reference the same object store. When the object store changes, all indexes that refers to the object store are automatically updated.</p> + +<p><span style="line-height: 1.5;">You can grab a set of keys within a range. To learn more, see {{domxref("IDBKeyRange")}}.</span></p> + +<p>{{AvailableInWorkers}}</p> + +<h2 id="Properties">Properties</h2> + +<dl> + <dt>{{domxref("IDBIndex.isAutoLocale")}} {{readonlyInline}} {{ Non-Standard_inline() }}</dt> + <dd>Returns a {{domxref("Boolean")}} indicating whether the index had a <code>locale</code> value of <code>auto</code> specified upon its creation (see <a href="https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/createIndex#Parameters"><code>createIndex()</code>'s optionalParameters</a>.)</dd> + <dt>{{domxref("IDBIndex.locale")}} {{readonlyInline}} {{ Non-Standard_inline() }}</dt> + <dd>Returns the locale of the index (for example <code>en-US</code>, or <code>pl</code>) if it had a <code>locale</code> value specified upon its creation (see <a href="https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/createIndex#Parameters"><code>createIndex()</code>'s optionalParameters</a>.)</dd> + <dt>{{domxref("IDBIndex.name")}}</dt> + <dd>The name of this index.</dd> + <dt>{{domxref("IDBIndex.objectStore")}} {{readonlyInline}}</dt> + <dd>The name of the object store referenced by this index.</dd> + <dt>{{domxref("IDBIndex.keyPath")}} {{readonlyInline}}</dt> + <dd>The <a href="/en/IndexedDB#gloss_key_path" title="en/IndexedDB#gloss key path">key path</a> of this index. If null, this index is not <a href="/en/IndexedDB/Index#gloss_auto-populated" title="en/IndexedDB/Index#gloss auto-populated">auto-populated</a>.</dd> + <dt>{{domxref("IDBIndex.multiEntry")}} {{readonlyInline}}</dt> + <dd>Affects how the index behaves when the result of evaluating the index's key path yields an array. If <code>true</code>, there is one record in the index for each item in an array of keys. If <code>false</code>, then there is one record for each key that is an array.</dd> + <dt>{{domxref("IDBIndex.unique")}} {{readonlyInline}}</dt> + <dd>If <code>true</code>, this index does not allow duplicate values for a key.</dd> +</dl> + +<h2 id="Methods">Methods</h2> + +<p>Inherits from: <a href="/en/DOM/EventTarget" title="en/DOM/EventTarget">EventTarget</a></p> + +<dl> + <dt>{{domxref("IDBIndex.count()")}}</dt> + <dd>Returns an {{domxref("IDBRequest")}} object, and in a separate thread, returns the number of records within a key range.</dd> + <dt>{{domxref("IDBIndex.get()")}}</dt> + <dd>Returns an {{domxref("IDBRequest")}} object, and, in a separate thread, finds either the value in the referenced object store that corresponds to the given key or the first corresponding value, if <code>key</code> is an {{domxref("IDBKeyRange")}}.</dd> + <dt>{{domxref("IDBIndex.getKey()")}}</dt> + <dd>Returns an {{domxref("IDBRequest")}} object, and, in a separate thread, finds either the given key or the primary key, if <code>key</code> is an {{domxref("IDBKeyRange")}}.</dd> + <dt>{{domxref("IDBIndex.getAll()")}}</dt> + <dd>Returns an {{domxref("IDBRequest")}} object, in a separate thread, finds all matching values in the referenced object store that correspond to the given key or are in range, if <code>key</code> is an {{domxref("IDBKeyRange")}}.</dd> + <dt>{{domxref("IDBIndex.getAllKeys()")}}</dt> + <dd>Returns an {{domxref("IDBRequest")}} object, in a separate thread, finds all matching keys in the referenced object store that correspond to the given key or are in range, if <code>key</code> is an {{domxref("IDBKeyRange")}}.</dd> + <dt>{{domxref("IDBIndex.openCursor()")}}</dt> + <dd>Returns an {{domxref("IDBRequest")}} object, and, in a separate thread, creates a <a href="/en/IndexedDB#gloss_cursor" title="en/IndexedDB#gloss cursor">cursor</a> over the specified key range.</dd> + <dt>{{domxref("IDBIndex.openKeyCursor()")}}</dt> + <dd>Returns an {{domxref("IDBRequest")}} object, and, in a separate thread, creates a cursor over the specified key range, as arranged by this index.</dd> +</dl> + +<h2 id="Example">Example</h2> + +<p>In the following example we open a transaction and an object store, then get the index <code>lName</code> from a simple contacts database. We then open a basic cursor on the index using {{domxref("IDBIndex.openCursor")}} — this works the same as opening a cursor directly on an <code>ObjectStore</code> using {{domxref("IDBObjectStore.openCursor")}} except that the returned records are sorted based on the index, not the primary key.</p> + +<p>Finally, we iterate through each record, and insert the data into an HTML table. For a complete working example, see our <a href="https://mdn.github.io/indexeddb-examples/idbindex/">IDBIndex-example demo repo</a> (<a href="https://github.com/mdn/indexeddb-examples/tree/master/idbindex">View the example live</a>.)</p> + +<pre class="brush: js" style="font-size: 14px;">function displayDataByIndex() { + tableEntry.innerHTML = ''; + var transaction = db.transaction(['contactsList'], 'readonly'); + var objectStore = transaction.objectStore('contactsList'); + + var myIndex = objectStore.index('lName'); + myIndex.openCursor().onsuccess = function(event) { + var cursor = event.target.result; + if(cursor) { + var tableRow = document.createElement('tr'); + tableRow.innerHTML = '<td>' + cursor.value.id + '</td>' + + '<td>' + cursor.value.lName + '</td>' + + '<td>' + cursor.value.fName + '</td>' + + '<td>' + cursor.value.jTitle + '</td>' + + '<td>' + cursor.value.company + '</td>' + + '<td>' + cursor.value.eMail + '</td>' + + '<td>' + cursor.value.phone + '</td>' + + '<td>' + cursor.value.age + '</td>'; + tableEntry.appendChild(tableRow); + + cursor.continue(); + } else { + console.log('Entries all displayed.'); + } + }; +};</pre> + +<h2 id="Specification">Specification</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-IDBIndex', 'IDBIndex')}}</td> + <td>{{Spec2('IndexedDB')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName("IndexedDB 2", "#index-interface", "IDBIndex")}}</td> + <td>{{Spec2("IndexedDB 2")}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("api.IDBIndex")}}</p> + +<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/ru/web/api/idbindex/locale/index.html b/files/ru/web/api/idbindex/locale/index.html new file mode 100644 index 0000000000..943e5a1ffe --- /dev/null +++ b/files/ru/web/api/idbindex/locale/index.html @@ -0,0 +1,76 @@ +--- +title: IDBIndex.locale +slug: Web/API/IDBIndex/locale +translation_of: Web/API/IDBIndex/locale +--- +<div>{{APIRef("IndexedDB")}}{{SeeCompatTable}}</div> + +<p>The <strong><code>locale</code></strong> read-only property of the {{domxref("IDBIndex")}} interface returns the locale of the index (for example <code>en-US</code>, or <code>pl</code>) if it had a <code>locale</code> value specified upon its creation (see <a href="https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/createIndex#Parameters"><code>createIndex()</code>'s optionalParameters</a>.) Note that this property always returns the current locale being used in this index, in other words, it never returns <code>"auto"</code>.</p> + +<h2 id="Syntax">Syntax</h2> + +<pre class="brush: js">var myIndex = objectStore.index('index'); +console.log(myIndex.locale);</pre> + +<h3 id="Value">Value</h3> + +<p>A {{domxref("DOMString")}}.</p> + +<h2 id="Example">Example</h2> + +<p>In the following example we open a transaction and an object store, then get the index <code>lName</code> from a simple contacts database. We then open a basic cursor on the index using {{domxref("IDBIndex.openCursor")}} — this works the same as opening a cursor directly on an <code>ObjectStore</code> using {{domxref("IDBObjectStore.openCursor")}} except that the returned records are sorted based on the index, not the primary key.</p> + +<p>The <code>locale</code> value is logged to the console.</p> + +<pre class="brush:js">function displayDataByIndex() { + tableEntry.innerHTML = ''; + var transaction = db.transaction(['contactsList'], 'readonly'); + var objectStore = transaction.objectStore('contactsList'); + + var myIndex = objectStore.index('lName'); + console.log(myIndex.locale); + + myIndex.openCursor().onsuccess = function(event) { + var cursor = event.target.result; + if(cursor) { + var tableRow = document.createElement('tr'); + tableRow.innerHTML = '<td>' + cursor.value.id + '</td>' + + '<td>' + cursor.value.lName + '</td>' + + '<td>' + cursor.value.fName + '</td>' + + '<td>' + cursor.value.jTitle + '</td>' + + '<td>' + cursor.value.company + '</td>' + + '<td>' + cursor.value.eMail + '</td>' + + '<td>' + cursor.value.phone + '</td>' + + '<td>' + cursor.value.age + '</td>'; + tableEntry.appendChild(tableRow); + + cursor.continue(); + } else { + console.log('Entries all displayed.'); + } + }; +};</pre> + +<h2 id="Specification">Specification</h2> + +<p>Not currently part of any specification.</p> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<div> + + +<p>{{Compat("api.IDBIndex.locale")}}</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> |