Indexed Database API 3.0
Sat Aug 02 2025 19:47:15 GMT+0000 (Coordinated Universal Time)
Saved by
@Asneedarazali
#javascript
const request = indexedDB.open("library", 3); // Request version 3.
let db;
request.onupgradeneeded = function(event) {
const db = request.result;
if (event.oldVersion < 1) {
// Version 1 is the first version of the database.
const store = db.createObjectStore("books", {keyPath: "isbn"});
const titleIndex = store.createIndex("by_title", "title", {unique: true});
const authorIndex = store.createIndex("by_author", "author");
}
if (event.oldVersion < 2) {
// Version 2 introduces a new index of books by year.
const bookStore = request.transaction.objectStore("books");
const yearIndex = bookStore.createIndex("by_year", "year");
}
if (event.oldVersion < 3) {
// Version 3 introduces a new object store for magazines with two indexes.
const magazines = db.createObjectStore("magazines");
const publisherIndex = magazines.createIndex("by_publisher", "publisher");
const frequencyIndex = magazines.createIndex("by_frequency", "frequency");
}
};
request.onsuccess = function() {
db = request.result; // db.version will be 3.
};
content_copyCOPY
https://www.w3.org/TR/2025/WD-IndexedDB-3-20250731/
Comments