You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Multiple operations in one transaction (atomic)awaitdb.transaction(['users','logs'],'readwrite',async(tx)=>{awaittx.put('users',{id: 1,name: 'Bob',balance: 100});awaittx.put('users',{id: 2,name: 'Carol',balance: 100});awaittx.put('logs',{action: 'init',timestamp: Date.now()});});// If any operation fails, all are rolled back
import{Result}from'@zappzarapp/browser-utils/core';constresult=awaitIndexedDBManager.openResult({name: 'app',version: 1,stores: {data: {keyPath: 'id'}},});if(Result.isErr(result)){switch(result.error.code){case'NOT_SUPPORTED':
useFallbackStorage();break;case'BLOCKED':
showMessage('Please close other tabs');break;default:
console.error('Database error:',result.error);}}else{constdb=result.value;// Use database}
Schema Migration
constdb=awaitIndexedDBManager.open({name: 'app',version: 2,// Increment version to trigger upgradestores: {users: {keyPath: 'id',indexes: {byEmail: {keyPath: 'email',unique: true},// New index in version 2byRole: {keyPath: 'role'},},},},onUpgrade: (db,oldVersion,newVersion)=>{if(oldVersion<2){// Migration logic for version 2console.log('Adding role index');}},});
IndexedDBError
Error Codes
Code
Description
NOT_SUPPORTED
IndexedDB not available in environment
OPEN_FAILED
Failed to open database
STORE_NOT_FOUND
Object store does not exist
TRANSACTION_FAILED
Transaction aborted or failed
OPERATION_FAILED
Individual operation (get/put/delete) failed
VERSION_ERROR
Version number issue (e.g., downgrade attempt)
BLOCKED
Upgrade blocked by open connections
Security Considerations
Same-Origin Only - IndexedDB is bound to the page origin
No Encryption - Data is stored in plain text; encrypt sensitive data
before storing