blob: 9e56d3b408927bd85fe87ecc0ad0cbaeedbf7c53 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
---
title: IDBObjectStore.getKey()
slug: Web/API/IDBObjectStore/getKey
translation_of: Web/API/IDBObjectStore/getKey
---
<p>{{ APIRef("IndexedDB") }}</p>
<div>
<p>La méthode <strong><code>getKey()</code></strong> de l'interface {{domxref("IDBObjectStore")}} retourne un objet {{domxref("IDBRequest")}}, et, dans un <em>thread</em> séparé, retourne la clé sélectionnée par la requête spécifiée. Cela permet de retrouver un enregistrement spécifique depuis un espace de stockage déterminé.</p>
</div>
<p>Si la clé a bien été retrouvée, alors un clone structuré (une copie conforme) sera créée et servira comme résultat à l'objet de requête.</p>
<p>{{AvailableInWorkers}}</p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox">var request = <em>objectStore</em>.getKey(<em>key</em>);</pre>
<h3 id="Parameters">Parameters</h3>
<dl>
<dt><em>key</em></dt>
<dd>La clé ou l'intervale de clé qui identifie l'enregistrement à retrouver.</dd>
</dl>
<h3 id="Return_Value">Return Value</h3>
<p>An {{domxref("IDBRequest")}} object on which subsequent events related to this operation are fired.</p>
<h3 id="Exceptions">Exceptions</h3>
<p>This method may raise a {{domxref("DOMException")}} of one of the following types:</p>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Exception</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>TransactionInactiveError</code></td>
<td>This {{domxref("IDBObjectStore")}}'s transaction is inactive.</td>
</tr>
<tr>
<td><code>DataError</code></td>
<td>
<p>The key or key range provided contains an invalid key.</p>
</td>
</tr>
<tr>
<td><code>InvalidStateError</code></td>
<td>The {{domxref("IDBObjectStore")}} has been deleted or removed.<br>
</td>
</tr>
</tbody>
</table>
<h2 id="Example">Example</h2>
<pre class="brush: js">let openRequest = indexedDB.open("telemetry");
openRequest.onsuccess = (event) => {
let db = event.target.result;
let store = db.transaction("netlogs").objectStore("netlogs");
let today = new Date();
let yesterday = new Date(today);
yesterday.setDate(today.getDate() - 1);
let request = store.getKey(IDBKeyRange(yesterday, today));
request.onsuccess = (event) => {
let when = event.target.result;
alert("The 1st activity in last 24 hours was occurred at " + when);
};
};</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 2', '#dom-idbobjectstore-getkey', 'getKey()')}}</td>
<td>{{Spec2('IndexedDB 2')}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="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>{{CompatChrome(58)}}</td>
<td>{{CompatGeckoDesktop("51.0")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatOpera(45)}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td>Available in workers</td>
<td>{{CompatChrome(58)}}</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>Firefox Mobile (Gecko)</th>
<th>IE Phone</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{CompatChrome(58)}}</td>
<td>{{CompatChrome(58)}}</td>
<td>{{CompatGeckoMobile("51.0")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatOperaMobile(45)}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td>Available in workers</td>
<td>{{CompatChrome(58)}}</td>
<td>{{CompatChrome(58)}}</td>
<td>{{CompatVersionUnknown}}</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="https://mdn.github.io/to-do-notifications/">view example live</a>.)</li>
</ul>
|