-
Notifications
You must be signed in to change notification settings - Fork 0
/
dumpDB.js
41 lines (34 loc) · 1.25 KB
/
dumpDB.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Helper function to create and append a button
function createButton(id, text, onClick) {
var button = document.createElement('button');
button.id = id;
button.textContent = text;
document.body.appendChild(button);
button.addEventListener('click', onClick);
}
// Function to list all IndexedDB databases
function listIndexedDBDatabases() {
indexedDB.databases().then(databases => {
const dbNames = databases.map(db => db.name);
console.log('IndexedDB Databases:', dbNames);
dbNames.forEach(dbName => {
listObjectStores(dbName);
});
}).catch(err => {
console.error('Error accessing IndexedDB:', err);
});
}
// Function to list all object stores in a given database
function listObjectStores(dbName) {
const request = indexedDB.open(dbName);
request.onsuccess = function(event) {
const db = event.target.result;
const objectStoreNames = Array.from(db.objectStoreNames);
console.log(`Object Stores in ${dbName}:`, objectStoreNames);
};
request.onerror = function(event) {
console.error(`Error opening database ${dbName}:`, event);
};
}
// Create buttons to list IndexedDB databases and their object stores
createButton('listIndexedDBDatabasesButton', 'List IndexedDB Databases', listIndexedDBDatabases);