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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
---
title: IndexedDB
slug: Web/API/IndexedDB_API
translation_of: Web/API/IndexedDB_API
---
<div class="summary">
<p>IndexedDB è una API per la memorizzazione client-side di una considerevole quantità di dati strutturati (inclusi file e blob) e per una ricerca performante su questi dati mediante gli indici. Se <a href="/it/docs/Web/API/Web_Storage_API" title="en-US/docs/DOM/Storage">Web Storage</a> è utile per memorizzare piccole quantità di dati, non lo è invece per memorizzare grandi quantità di dati strutturati. IndexedDB fornisce la soluzione. Questa è la pagina principale su IndexedDB di MDN — qui vengono forniti link a tutti i riferimenti API e guide all'uso, dettagli di supporto al browser ed alcune spiegazioni dei concetti chiave.</p>
</div>
<h2 id="Concetti_chiave_ed_uso">Concetti chiave ed uso</h2>
<p>IndexedDB è un sistema di database transazionale, che inizialmente potrebbe creare confusione se si è abituati a lavorare solo con i database relazionali, ma presto diverrà abbastanza chiaro. IndexedDB permette di memorizzare e recuperare oggetti indicizzati con una <strong>chiave</strong>. E' necessario specificare lo schema del database, aprire una connessione al proprio database e poi recuperare ed aggiornare i dati attraverso una serie di <strong>transazioni</strong>.</p>
<ul>
<li>Apprendere maggiori info sui <a href="/en-US/docs/Web/API/IndexedDB_API/Basic_Concepts_Behind_IndexedDB">concetti dietro a IndexedDB</a>.</li>
<li>Imparare ad usare IndexedDB in modo asincrono dai primi principi con la nostra guida <a href="/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB">Usare IndexedDB</a>.</li>
<li>Trova le raccomandazioni degli sviluppatori per far lavorare le apps web offline alla pagina <a href="/en-US/Apps/Build/Offline">Offline Apps</a>.</li>
</ul>
<div class="note">
<p><strong>Nota</strong>: Come molte soluzioni web storage, IndexedDB segue una <a class="external" href="http://www.w3.org/Security/wiki/Same_Origin_Policy" title="http://www.w3.org/Security/wiki/Same_Origin_Policy">same-origin policy</a>. Quindi mentre si può accedere ai dati memorizzati sotto un dominio, non è possibile accedere ai dati attraverso domini differenti.</p>
</div>
<h3 id="Sincrono_e_asincrono">Sincrono e asincrono</h3>
<p>IndexedDB include sia una API asincrona che una API sincrona. La API asincrona può essere usata in molti casi, incluso <a href="https://developer.mozilla.org/En/DOM/Using_web_workers" title="https://developer.mozilla.org/En/Using_web_workers">WebWorkers</a>, mentre la API sincrona è designata ad essere utilizzata solo con <a href="/en-US/docs/Web/Guide/Performance/Using_web_workers">Web Workers</a> e sarà usata molto raramente.</p>
<div class="note">
<p><strong>Nota</strong>: Attualmente, nessuno dei principali browser supporta la API sincrona.</p>
</div>
<h3 id="Limiti_di_memorizzazione">Limiti di memorizzazione</h3>
<p>Non c'è alcun limite alla dimensione di un singolo elemento del database, tuttavia ci potrebbe essere un limite ad ogni dimensione complessiva del database IndexedDB. Questo limite (ed il modo con cui l'interfaccia utente lo supporterà) potrebbe variare da un browser ad un altro:</p>
<ul>
<li>Firefox non ha limite sulla dimensione del database IndexedDB. The user interface will just ask permission for storing blobs bigger than 50 MB. This size quota can be customized through the <code>dom.indexedDB.warningQuota</code> preference (which is defined in <a href="http://mxr.mozilla.org/mozilla-central/source/modules/libpref/src/init/all.js" title="http://mxr.mozilla.org/mozilla-central/source/modules/libpref/src/init/all.js">http://mxr.mozilla.org/mozilla-central/source/modules/libpref/src/init/all.js</a>).</li>
<li>Google Chrome: see <a class="link-https" href="https://developers.google.com/chrome/whitepapers/storage#temporary" rel="freelink">https://developers.google.com/chrome...rage#temporary</a>.</li>
</ul>
<h2 id="Asynchronous_API">Asynchronous API</h2>
<p>The asynchronous API methods return without blocking the calling thread. To get asynchronous access to a database, call <a href="/en-US/docs/Web/API/IDBFactory.open"><code>open()</code></a> on the <a href="/en-US/docs/Web/API/IDBEnvironment.indexedDB"><code>indexedDB</code></a> attribute of a <a href="/en-US/docs/DOM/window" title="en-US/docs/DOM/window">window</a> object. This method returns an {{domxref("IDBRequest")}} object; asynchronous operations communicate to the calling application by firing events on {{domxref("IDBRequest")}} objects.</p>
<h3 id="Connecting_to_a_database">Connecting to a database</h3>
<dl>
<dt>{{domxref("IDBEnvironment")}}</dt>
<dd>Provides access to a client-side database. It is implemented by the {{ domxref("window") }} and {{ domxref("worker") }} objects.</dd>
<dt>{{domxref("IDBFactory")}}</dt>
<dd>Provides access to a database. This is the interface implemented by the global object <a href="/en-US/docs/Web/API/IDBEnvironment.indexedDB"><code>indexedDB</code></a> and is therefore the entry point for the API.</dd>
<dt>{{domxref("IDBOpenDBRequest")}}</dt>
<dd>Represents a request to open a database.</dd>
<dt>{{domxref("IDBDatabase")}}</dt>
<dd>Represents a connection to a database. It's the only way to get a transaction on the database.</dd>
</dl>
<h3 id="Accessing_results_of_database_requests">Accessing results of database requests</h3>
<dl>
<dt>{{domxref("IDBRequest")}}</dt>
<dd>Provides access to results of asynchronous requests to databases and database objects. It is what you get when you call an asynchronous method.</dd>
</dl>
<h3 id="Retrieving_and_modifying_data">Retrieving and modifying data</h3>
<dl>
<dt>{{domxref("IDBTransaction")}}</dt>
<dd>Represents a transaction. You create a transaction on a database, specify the scope (such as which object stores you want to access), and determine the kind of access (read only or write) that you want.</dd>
<dt>{{domxref("IDBObjectStore")}}</dt>
<dd>Represents an object store.</dd>
<dt>{{domxref("IDBIndex")}}</dt>
<dd>Provides access to the metadata of an index.</dd>
<dt>{{domxref("IDBCursor")}}</dt>
<dd>Iterates over object stores and indexes.</dd>
<dt>{{domxref("IDBCursorWithValue")}}</dt>
<dd>Iterates over object stores and indexes and returns the cursor's current value.</dd>
<dt>{{domxref("IDBKeyRange")}}</dt>
<dd>Defines a range of keys.</dd>
</dl>
<h3 id="Deprecated_interfaces">Deprecated interfaces</h3>
<p>An early version of the specification also defined these now removed interfaces. They are still documented in case you need to update previously written code:</p>
<dl>
<dt>{{domxref("IDBVersionChangeRequest")}}</dt>
<dd>Represents a request to change the version of a database. The way to change the version of the database has since changed (by calling {{domxref("IDBFactory.open")}} without also calling {{domxref("IDBDatabase.setVersion")}}), and the interface {{domxref("IDBOpenDBRequest")}} now has the functionality of the removed {{domxref("IDBVersionChangeRequest")}}.</dd>
<dt>{{domxref("IDBDatabaseException")}} {{ obsolete_inline() }}</dt>
<dd>Represents exception conditions that can be encountered while performing database operations.</dd>
</dl>
<h2 id="Synchronous_API">Synchronous API</h2>
<div class="warning">
<p><strong>Important</strong>: This is a reminder that the synchronous version of IndexedDB is not yet implemented in any browser.</p>
</div>
<p>To get synchronous access to a database, call <a href="https://developer.mozilla.org/en-US/docs/IndexedDB/IDBFactorySync#open" title="en-US/docs/IndexedDB/IDBFactorySync#open"><code>open()</code></a> on the <span class="inlineIndicator unimplemented unimplementedInline">Unimplemented</span> <a href="https://developer.mozilla.org/en-US/docs/IndexedDB/IDBEnvironmentSync#indexedDBSync" title="en-US/docs/IndexedDB/EnvironmentSync#indexedDBSync"><code>indexedDBSync</code></a> attribute of a <a href="https://developer.mozilla.org/en-US/docs/DOM/Worker" title="en-US/docs/DOM/Worker">worker</a> object. This returns an <code><a href="https://developer.mozilla.org/en-US/docs/IndexedDB/IDBDatabaseSync" title="en-US/docs/IndexedDB/DatabaseSync">IDBDatabaseSync</a></code> object, which enables you to create, open, and remove object stores and indexes, set the version of the database, and create transactions.</p>
<ul>
<li><code><a href="https://developer.mozilla.org/en-US/docs/IndexedDB/IDBCursorSync" title="en-US/docs/IndexedDB/IDBCursorSync">IDBCursorSync</a></code> iterates over object stores and indexes.</li>
<li><code><a href="https://developer.mozilla.org/en-US/docs/IndexedDB/IDBDatabaseSync" title="en-US/docs/IndexedDB/DatabaseSync">IDBDatabaseSync</a></code> represents a connection to a database. It's the only way to get a transaction on the database.</li>
<li><a href="https://developer.mozilla.org/en-US/docs/IndexedDB/IDBEnvironmentSync" title="IDBEnvironmentSync"><code>IDBEnvironmentSync</code></a> provides access to a client-side database. It is implemented by <a class="new" href="https://developer.mozilla.org/en-US/docs/Web/API/en-US/docs/DOM/Worker" title="en-US/docs/DOM/Worker">worker</a> objects.</li>
<li><code><a href="https://developer.mozilla.org/en-US/docs/IndexedDB/IDBFactorySync" title="en-US/docs/IndexedDB/IndexedDatabase">IDBFactorySync </a></code>provides access to a database.</li>
<li><code><a href="https://developer.mozilla.org/en-US/docs/IndexedDB/IDBIndexSync" title="en-US/docs/IndexedDB/IndexSync">IDBIndexSync</a></code> provides access to the metadata of an index.</li>
<li><code><a href="https://developer.mozilla.org/en-US/docs/IndexedDB/IDBObjectStoreSync" title="en-US/docs/IndexedDB/ObjectStoreSync">IDBObjectStoreSync</a></code> represents an object store.</li>
<li><code><a href="https://developer.mozilla.org/en-US/docs/IndexedDB/IDBTransactionSync" title="en-US/docs/IndexedDB/TransactionSync">IDBTransactionSync</a></code> creates a transaction in the database.</li>
</ul>
<h2 id="Example" name="Example">Examples</h2>
<ul>
<li><a href="/en-US/demos/detail/elibri" title="https://developer.mozilla.org/en-US/demos/detail/elibri">eLibri:</a> A powerful library and eBook reader application, written by Marco Castelluccio, winner of the IndexedDB Mozilla DevDerby.</li>
<li><a class="external" href="https://github.com/chrisdavidmills/to-do-notifications/tree/gh-pages">To-do Notifications</a> (<a class="external" href="http://chrisdavidmills.github.io/to-do-notifications/">view example live</a>): The reference application for the examples in the reference docs: Not every snippet appears in this example, but every example uses the same data structure and syntax, and will make sense in the context of this application.</li>
<li><a class="external" href="http://hacks.mozilla.org/2012/02/storing-images-and-files-in-indexeddb/" title="http://hacks.mozilla.org/2012/02/storing-images-and-files-in-indexeddb/">Storing images and files in IndexedDB</a></li>
<li><a class="external" href="http://nparashuram.com/IndexedDB/trialtool/index.html" title="http://nparashuram.com/IndexedDB/trialtool/index.html">IndexedDB Examples</a></li>
</ul>
<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>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari (WebKit)</th>
</tr>
<tr>
<td>Asynchronous API</td>
<td>
<p>11.0 {{ property_prefix("webkit") }}<br>
24</p>
</td>
<td>{{ CompatGeckoDesktop("2.0") }} {{ property_prefix("moz") }}<br>
{{ CompatGeckoDesktop("16.0") }}</td>
<td>10</td>
<td>17</td>
<td>{{ CompatNo() }}</td>
</tr>
<tr>
<td>Synchronous API<br>
(used with <a href="/en-US/docs/DOM/Using_web_workers" title="https://developer.mozilla.org/en-US/docs/Using_web_workers">WebWorkers</a>)</td>
<td>{{ CompatNo() }}</td>
<td>{{ CompatNo() }}<br>
See {{ bug(701634) }}</td>
<td>{{ CompatNo() }}</td>
<td>{{ CompatNo() }}</td>
<td>{{ CompatNo() }}</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>IE Phone</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Asynchronous API</td>
<td>4.4</td>
<td>{{ CompatGeckoDesktop("6.0") }} {{ property_prefix("moz") }}<br>
{{ CompatGeckoDesktop("16.0") }}</td>
<td>10</td>
<td>17</td>
<td>{{ CompatNo() }}</td>
</tr>
</tbody>
</table>
</div>
<div class="note">
<p><strong>Note</strong>: Some browsers don't yet support IndexedDB but <a href="http://caniuse.com/sql-storage" title="http://caniuse.com/sql-storage">do support WebSQL</a>, most notably Safari/Webkit on desktop and iOS. One way around this problem is to use an IndexedDB Polyfill or Shim that falls back to <a href="http://www.w3.org/TR/webdatabase/">WebSQL</a> or even <a href="/en-US/docs/Web/Guide/API/DOM/Storage#localStorage">localStorage</a> for non-supporting browsers. The best available polyfill at present is <a href="https://github.com/mozilla/localForage">localForage</a>.</p>
</div>
<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-IDBEnvironment', 'IDBEnvironment')}}</td>
<td>{{Spec2('IndexedDB')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<section id="Quick_Links">
<ol>
<li data-default-state="open"><strong><a href="#">Guides and recommendations</a></strong>
<ol>
<li><a href="/en-US/docs/Web/API/IndexedDB_API/Basic_Concepts_Behind_IndexedDB">Basic concepts behind IndexedDB</a></li>
<li><a href="/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB">Using IndexedDB</a></li>
<li><a href="/en-US/Apps/Build/Offline">Offline guide on App Center</a></li>
</ol>
</li>
<li data-default-state="open"><strong><a href="#">Asynchronous interfaces</a></strong>
<ol>
<li>{{ domxref("IDBCursor") }}</li>
<li>{{ domxref("IDBCursorWithValue") }}</li>
<li>{{ domxref("IDBDatabase") }}</li>
<li>{{ domxref("IDBEnvironment") }}</li>
<li>{{ domxref("IDBFactory") }}</li>
<li>{{ domxref("IDBIndex") }}</li>
<li>{{ domxref("IDBKeyRange") }}</li>
<li>{{ domxref("IDBObjectStore") }}</li>
<li>{{ domxref("IDBOpenDBRequest") }}</li>
<li>{{ domxref("IDBRequest") }}</li>
<li>{{ domxref("IDBTransaction") }}</li>
</ol>
</li>
<li data-default-state="open"><strong><a href="#">Synchronous interfaces</a></strong>
<ol>
<li>{{ domxref("IDBCursorSync") }}</li>
<li>{{ domxref("IDBDatabaseSync") }}</li>
<li>{{ domxref("IDBEnvironmentSync") }}</li>
<li>{{ domxref("IDBFactorySync") }}</li>
<li>{{ domxref("IDBIndexSync") }}</li>
<li>{{ domxref("IDBObjectStoreSync") }}</li>
<li>{{ domxref("IDBTransactionSync") }}</li>
</ol>
</li>
</ol>
</section>
|