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
|
---
title: IDBFactory
slug: Web/API/IDBFactory
translation_of: Web/API/IDBFactory
---
<p>{{APIRef("IndexedDB")}}</p>
<div>
<p>A interface IDBFactory, pertencente a <a href="/en-US/docs/IndexedDB">IndexedDB API</a> , permite que aplicativos acessem de forma assíncrona os bancos de dados indexados. O objeto que implementa a interface é o window.indexedDB, com este objeto é possível criar, acessar, modificar e excluir informações de um banco de dados. </p>
<p>{{AvailableInWorkers}}</p>
</div>
<h2 id="Métodos">Métodos</h2>
<dl>
<dt>{{domxref("IDBFactory.open")}}</dt>
<dd>Realizar a abertura de uma <a href="https://developer.mozilla.org/en-US/docs/IndexedDB#gloss_database_connection">conexão com uma base de dados</a>.</dd>
<dt>{{domxref("IDBFactory.deleteDatabase")}}</dt>
<dd>Remove uma base de dados.</dd>
<dt>{{domxref("IDBFactory.cmp")}}</dt>
<dd>Compara dois valores chaves e determina se elas são iguais e se não, quem é a maior.</dd>
</dl>
<h3 id="Métodos_Obsoletos">Métodos Obsoletos</h3>
<dl>
<dt><code><a href="/en-US/docs/Web/API/IDBFactory.open-obsolete">IDBFactory.open</a></code>, a versão original {{ obsolete_inline }}</dt>
<dd>Este método realizava <a href="https://developer.mozilla.org/en-US/docs/IndexedDB#gloss_database_connection">conexão com uma base de dados</a>, ele ainda é usado em alguns navegadores.</dd>
</dl>
<h2 id="Exemplo">Exemplo</h2>
<p>No código abaixo, realizamos uma conexão com um banco de dados e incluímos manipuladores para os casos de sucesso e erro. Você pode obter o <a class="external" href="https://github.com/mdn/to-do-notifications/tree/gh-pages">To-do Notifications</a> app como exemplo (<a class="external" href="http://mdn.github.io/to-do-notifications/">Visualizar exemplo</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 += '<li>Error loading database.</li>';
};
DBOpenRequest.onsuccess = function(event) {
note.innerHTML += '<li>Database initialised.</li>';
// store the result of opening the database in the db variable. This is used a lot later on, for opening transactions and suchlike.
db = DBOpenRequest.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>
<tr>
<td>{{SpecName("IndexedDB 2", "#factory-interface", "IDBFactory")}}</td>
<td>{{Spec2("IndexedDB 2")}}</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>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)}} {{property_prefix("webkit")}}<br>
{{CompatChrome(24)}} (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>15<br>
{{CompatOpera(44)}} (prefixes removed)</td>
<td>7.1</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>{{CompatGeckoMobile("37.0")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatVersionUnknown}}<br>
{{CompatOpera(44)}} (prefixes removed)</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>22<br>
{{CompatOperaMobile(44)}} (prefixes removed)</td>
<td>8</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>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">Usando IndexedDB</a></li>
<li>Inicializando uma Transaction: {{domxref("IDBDatabase")}}</li>
<li>Usando uma Transaction: {{domxref("IDBTransaction")}}</li>
<li>Configurando um Intervalo de chaves: {{domxref("IDBKeyRange")}}</li>
<li>Recuperando e modificando dados: {{domxref("IDBObjectStore")}}</li>
<li>Usando cursors: {{domxref("IDBCursor")}}</li>
<li>Exemplo de referência: <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/">Visualizar exemplo</a>.)</li>
</ul>
|