aboutsummaryrefslogtreecommitdiff
path: root/files/tr/web/api/idbindex/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/tr/web/api/idbindex/index.html')
-rw-r--r--files/tr/web/api/idbindex/index.html337
1 files changed, 337 insertions, 0 deletions
diff --git a/files/tr/web/api/idbindex/index.html b/files/tr/web/api/idbindex/index.html
new file mode 100644
index 0000000000..a14089a7f3
--- /dev/null
+++ b/files/tr/web/api/idbindex/index.html
@@ -0,0 +1,337 @@
+---
+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 = '&lt;td&gt;' + cursor.value.id + '&lt;/td&gt;'
+ + '&lt;td&gt;' + cursor.value.lName + '&lt;/td&gt;'
+ + '&lt;td&gt;' + cursor.value.fName + '&lt;/td&gt;'
+ + '&lt;td&gt;' + cursor.value.jTitle + '&lt;/td&gt;'
+ + '&lt;td&gt;' + cursor.value.company + '&lt;/td&gt;'
+ + '&lt;td&gt;' + cursor.value.eMail + '&lt;/td&gt;'
+ + '&lt;td&gt;' + cursor.value.phone + '&lt;/td&gt;'
+ + '&lt;td&gt;' + cursor.value.age + '&lt;/td&gt;';
+ 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>{{ CompatibilityTable() }}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Edge</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatChrome(23.0)}}{{property_prefix("webkit")}}<br>
+ {{CompatChrome(24.0)}} (unprefixed)<br>
+ {{CompatChrome(38)}} (prefixes deprecated)<br>
+ {{CompatChrome(57)}} (prefixes removed)</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>10 {{property_prefix("moz")}}<br>
+ {{CompatGeckoDesktop("16.0")}}</td>
+ <td>10, partial</td>
+ <td>{{CompatOpera(15)}}<br>
+ {{CompatOpera(44)}} (prefixes removed)</td>
+ <td>7.1</td>
+ </tr>
+ <tr>
+ <td><code>count()</code></td>
+ <td>{{CompatChrome(23.0)}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{ CompatGeckoDesktop("22.0") }}</td>
+ <td>10, partial</td>
+ <td>{{CompatOpera(15)}}</td>
+ <td>7.1</td>
+ </tr>
+ <tr>
+ <td><code>getAll()</code> and <code>getAllKeys()</code></td>
+ <td>{{CompatChrome(48.0)}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{ CompatGeckoDesktop("24.0") }}<br>
+ behind <code>dom.indexedDB.experimental</code>  pref</td>
+ <td>{{ CompatNo() }}</td>
+ <td>{{ CompatNo() }}</td>
+ <td>{{ CompatNo() }}</td>
+ </tr>
+ <tr>
+ <td>Available in workers</td>
+ <td>{{CompatVersionUnknown}} (unprefixed)<br>
+ {{CompatChrome(38)}} (prefixes deprecated)<br>
+ {{CompatChrome(57)}} (prefixes removed)</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoDesktop("37.0")}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatVersionUnknown}}<br>
+ {{CompatOpera(44)}} (prefixes removed)</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>isAutoLocale</code> and <code>locale</code></td>
+ <td>{{ CompatNo() }}</td>
+ <td>{{CompatNo}}</td>
+ <td>
+ <p>{{CompatGeckoDesktop("43.0")}}<br>
+ behind <code>dom.indexedDB.experimental</code>  pref</p>
+ </td>
+ <td>{{ CompatNo() }}</td>
+ <td>{{ CompatNo() }}</td>
+ <td>{{ CompatNo() }}</td>
+ </tr>
+ <tr>
+ <td><code>name</code> setter available</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoDesktop(49)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td>Indexed Database 2.0</td>
+ <td>{{CompatChrome(58)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatOpera(45)}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android Webview</th>
+ <th>Chrome for Android </th>
+ <th>Edge</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>{{CompatVersionUnknown}}<br>
+ {{CompatChrome(38)}} (prefixes deprecated)<br>
+ {{CompatChrome(57)}} (prefixes removed)</td>
+ <td>{{CompatVersionUnknown}}<br>
+ {{CompatChrome(38)}} (prefixes deprecated)<br>
+ {{CompatChrome(57)}} (prefixes removed)</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{ CompatGeckoMobile("22.0") }}</td>
+ <td>1.0.1</td>
+ <td>10</td>
+ <td>{{CompatOperaMobile(22)}}<br>
+ {{CompatOperaMobile(44)}} (prefixes removed)</td>
+ <td>{{ CompatNo() }}</td>
+ </tr>
+ <tr>
+ <td><code>count()</code></td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{ CompatGeckoMobile("22.0") }}</td>
+ <td>1.0.1</td>
+ <td>10</td>
+ <td>{{CompatOperaMobile(22)}}</td>
+ <td>{{ CompatNo() }}</td>
+ </tr>
+ <tr>
+ <td><code>getAll()</code> and <code>getAllKeys()</code></td>
+ <td>{{CompatChrome(48.0)}}</td>
+ <td> </td>
+ <td>{{CompatNo}}</td>
+ <td>{{ CompatGeckoMobile("24.0") }}<br>
+ behind <code>dom.indexedDB.experimental</code>  pref</td>
+ <td>1.1 behind<br>
+ <code>dom.indexedDB.experimental</code>  pref</td>
+ <td>{{ CompatNo() }}</td>
+ <td>{{ CompatNo() }}</td>
+ <td>{{ CompatNo() }}</td>
+ </tr>
+ <tr>
+ <td>Available in workers</td>
+ <td>{{CompatVersionUnknown}} (unprefixed)<br>
+ {{CompatChrome(38)}} (prefixes deprecated)<br>
+ {{CompatChrome(57)}} (prefixes removed)</td>
+ <td>{{CompatVersionUnknown}} (unprefixed)<br>
+ {{CompatChrome(38)}} (prefixes deprecated)<br>
+ {{CompatChrome(57)}} (prefixes removed)</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoMobile("37.0")}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatVersionUnknown}}<br>
+ {{CompatOperaMobile(44)}} (prefixes removed)</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>isAutoLocale</code> and <code>locale</code></td>
+ <td>{{ CompatNo()}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoMobile("43.0")}}<br>
+ behind <code>dom.indexedDB.experimental</code>  pref</td>
+ <td>2.5<br>
+ behind <code>dom.indexedDB.experimental</code>  pref</td>
+ <td>{{ CompatNo() }}</td>
+ <td>{{ CompatNo() }}</td>
+ <td>{{ CompatNo() }}</td>
+ </tr>
+ <tr>
+ <td><code>name</code> setter available</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoMobile(49)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td>Indexed Database 2.0</td>
+ <td>{{CompatChrome(58)}}</td>
+ <td>{{CompatChrome(58)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatOperaMobile(45)}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</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>