function openDatabase(
name,
version,
onUpgrade?,
idbFactory?,
onBlocked?): Promise<IDBDatabase>;Defined in: packages/indexeddb-db-collection/src/wrapper.ts:88
Opens an IndexedDB database with the specified name and version. A blocked request stays pending until native success or error. The caller owns the returned connection and must close it when no longer needed.
string
The name of the database to open
number
The version number of the database schema
(db, oldVersion, newVersion, transaction) => void
Optional callback that runs during the onupgradeneeded event. Use this to create object stores and indexes.
IDBFactory
Optional IDBFactory for testing/mocking (defaults to window.indexedDB or globalThis.indexedDB)
(event) => void
Optional diagnostic callback for native blocked events. The request stays pending.
Promise<IDBDatabase>
A promise that resolves to the IDBDatabase instance
const db = await openDatabase('myApp', 1, (db, oldVersion, newVersion, transaction) => {
if (oldVersion < 1) {
db.createObjectStore('todos', { keyPath: 'id' })
}
})