Open a database with Database.openPersistent(name) and every write is mirrored to IndexedDB. Close the tab, reload, quit the browser — your data is still there next time. The in-memory backend, in contrast, vanishes with the page.
new Database() creates an in-memory database. Fast, no I/O, dies on reload.Database.openPersistent(dbName) backs the same API with IndexedDB. Creates the object store on first open.data/{entity}/{id} and meta/{type}/…. Values are the same JSON your code sees — no envelope, no encryption (see Encrypted page for that).createSync, …) are not available on IndexedDB — persistent storage is inherently asynchronous. Check db.isMemoryBackend() before calling them.
flowchart LR
M["new Database()"] --> MB[In-memory map]
P["openPersistent('name')"] --> IDB[(IndexedDB)]
W1["db.create(...)"] --> MB
W2["db.create(...)"] --> IDB
R1[Page reload] --> MB2[Empty — data gone]
R2[Page reload] --> IDB
IDB --> MB3[Data restored]
style MB fill:#fff3e0,stroke:#ef6c00
style IDB fill:#e3f2fd,stroke:#1565c0
style MB2 fill:#ffcdd2,stroke:#c62828
style MB3 fill:#c8e6c9,stroke:#2e7d32
+1 Increment a few times — the counter is stored in IndexedDB.Reload page to test persistence. The counter value stays where you left it.Stored in the counter entity of the current database. Reload the page to test whether it survives.
IndexedDB — data persists across page reloads.
| ID | Data |
|---|
Look at what MQDB has actually written to IndexedDB — keys and JSON payloads.
Click "Inspect IndexedDB" to view raw data
Run all tests runs 6 steps; the last one tests round-tripping the counter so you can then reload the page to confirm persistence.