CKTIS / JavaScript
indexedDB.open — opening a database and upgrading its schema
indexedDB.open asynchronously opens or creates a local database. It returns an event-driven request; schema changes belong in the upgradeneeded handler.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
indexedDB.open(name)
indexedDB.open(name, version)indexedDB.open(name, version) returns an IDBOpenDBRequest, not a Promise. In success, request.result holds an IDBDatabase connection. Omitting version uses the existing database version, or 1 for a new database.
The version is a positive integer. A higher version triggers upgradeneeded: create object stores and indexes within this upgrade transaction. success follows only after the upgrade commits. A lower version causes an asynchronous VersionError; 0 throws a synchronous TypeError.
Other open connections can cause blocked; this means waiting, not terminal failure. Close them with db.close() in response to versionchange. Handle both error and synchronous exceptions.
This is a Web API, not part of ECMAScript. Check availability in the target browser; Node 24 does not establish it. Storage policy can deny access. If the open succeeds, the example closes the connection and requests deletion with indexedDB.deleteDatabase(name). In the shown SecurityError case, no database is created.
Examples
(() => {
const name = `cktis-open-${crypto.getRandomValues(new Uint32Array(4)).join('-')}`;
const failed = error => console.log(`Open failed: ${error.name}`);
try {
const request = indexedDB.open(name, 1);
let upgradedFrom;
request.onupgradeneeded = event => {
upgradedFrom = event.oldVersion;
request.result.createObjectStore('notes');
};
request.onblocked = () => console.log('Open blocked by an open connection');
request.onerror = () => failed(request.error);
request.onsuccess = () => {
const db = request.result;
const version = db.version;
const hasNotes = db.objectStoreNames.contains('notes');
db.close();
indexedDB.deleteDatabase(name);
console.log(`Opened version ${version} from ${upgradedFrom}; notes store: ${hasNotes}`);
};
} catch (error) {
failed(error);
}
})();Result
Open failed: SecurityError
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.