v141 · indexeddb
Bulk Export / Import
getAllRecords() is the natural fit for database snapshots: one call returns every key–value pair ready for JSON serialisation. Import flows can bulk-insert the JSON back with a single transaction. No cursor loop, no accumulation boilerplate.
Feature detection: checking…
A 200-record contacts database is seeded automatically. Export it to JSON, edit the snapshot, and import it back. Each step shows the exact API call used.
database state
contacts store
Records: —
Indexes: —
Store:
Indexes: —
Store:
contacts · keyPath: idlast operation
No operation yet.
export
import
Drop a JSON file here or click to select · must match export format
// Export: getAllRecords() → JSON (Chrome 141)
async function exportDB(db) {
const tx = db.transaction('contacts', 'readonly');
const store = tx.objectStore('contacts');
const records = await store.getAllRecords();
return JSON.stringify({ version: 1, records });
}
// Import: JSON → bulk put in one transaction
async function importDB(db, json) {
const { records } = JSON.parse(json);
const tx = db.transaction('contacts', 'readwrite');
const store = tx.objectStore('contacts');
for (const { key, value } of records) {
store.put(value); // key is embedded in value.id
}
await new Promise((res, rej) => {
tx.oncomplete = res;
tx.onerror = e => rej(e.target.error);
});
}
see also
- getAllRecords basics
- Index Range Query — secondary index + IDBKeyRange
- Pagination Demo — forward/reverse paging
- ChromeStatus entry