--- title: IDBFactory slug: Web/API/IDBFactory translation_of: Web/API/IDBFactory ---

{{APIRef("IndexedDB")}}

A interface IDBFactory, pertencente a IndexedDB API , 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. 

{{AvailableInWorkers}}

Métodos

{{domxref("IDBFactory.open")}}
Realizar a abertura de uma conexão com uma base de dados.
{{domxref("IDBFactory.deleteDatabase")}}
Remove uma base de dados.
{{domxref("IDBFactory.cmp")}}
Compara dois valores chaves e determina se elas são iguais e se não, quem é a maior.

Métodos Obsoletos

IDBFactory.open, a versão original {{ obsolete_inline }}
Este método realizava conexão com uma base de dados, ele ainda é usado em alguns navegadores.

Exemplo

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 To-do Notifications app como exemplo (Visualizar exemplo.)

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;
};

Specifications

Specification Status Comment
{{SpecName('IndexedDB', '#idl-def-IDBFactory', 'IDBFactory')}} {{Spec2('IndexedDB')}}  
{{SpecName("IndexedDB 2", "#factory-interface", "IDBFactory")}} {{Spec2("IndexedDB 2")}}  

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatChrome(23)}} {{property_prefix("webkit")}}
{{CompatChrome(24)}} (unprefixed)
{{CompatChrome(38)}} (prefixes deprecated)
{{CompatChrome(57)}} (prefixes removed)
{{CompatVersionUnknown}} 10 {{property_prefix("moz")}}
{{CompatGeckoDesktop("16.0")}}
10, partial 15
{{CompatOpera(44)}} (prefixes removed)
7.1
Available in workers {{CompatVersionUnknown}} (unprefixed)
{{CompatChrome(38)}} (prefixes deprecated)
{{CompatChrome(57)}} (prefixes removed)
{{CompatVersionUnknown}} {{CompatGeckoMobile("37.0")}} {{CompatUnknown}} {{CompatVersionUnknown}}
{{CompatOpera(44)}} (prefixes removed)
{{CompatUnknown}}
Indexed Database 2.0 {{CompatChrome(58)}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatOpera(45)}} {{CompatUnknown}}
Feature Android Webview Chrome for Android Edge Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}}
{{CompatChrome(38)}} (prefixes deprecated)
{{CompatChrome(57)}} (prefixes removed)
{{CompatVersionUnknown}}
{{CompatChrome(38)}} (prefixes deprecated)
{{CompatChrome(57)}} (prefixes removed)
{{CompatVersionUnknown}} {{CompatGeckoMobile("22.0")}} 1.0.1 10 22
{{CompatOperaMobile(44)}} (prefixes removed)
8
Available in workers {{CompatVersionUnknown}} (unprefixed)
{{CompatChrome(38)}} (prefixes deprecated)
{{CompatChrome(57)}} (prefixes removed)
{{CompatVersionUnknown}} (unprefixed)
{{CompatChrome(38)}} (prefixes deprecated)
{{CompatChrome(57)}} (prefixes removed)
{{CompatVersionUnknown}} {{CompatGeckoMobile("37.0")}} {{CompatVersionUnknown}} {{CompatUnknown}} {{CompatVersionUnknown}}
{{CompatOperaMobile(44)}} (prefixes removed)
{{CompatUnknown}}
Indexed Database 2.0 {{CompatChrome(58)}} {{CompatChrome(58)}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatOperaMobile(45)}} {{CompatUnknown}}

See also