I've been using Dexie for a small production app. Today by opening the app I noticed that all the data was gone. I doubt that my app is the culprit, as it doesn't have a way to erase all the data at once.
I can only recall that my browser (Arc, based on Chromium) crashed earlier in the day, so I had to force-quit it.
Therefore I was wondering:
Thanks in advance!
My Dexie implementation:
import Dexie, { Table } from 'dexie'
class CustomDatabase extends Dexie {
projects!: Table<Project, string>
versions!: Table<Version, string>
templates!: Table<Template, string>
images!: Table<Image, string>
constructor() {
super('app-designer')
this.version(1.4)
.stores({
projects: 'id, createdAt',
versions: 'id, projectId, submitted',
templates: 'id',
images: 'id, projectId, createdAt',
})
.upgrade((tx) => {
tx.table('projects')
.toCollection()
.modify((proj) => {
proj.pinnedVersions = proj.pinnedVersions || []
})
})
}
}
export const db = new CustomDatabase()
Browsers behave differently but Chrome seem to keep it unless the device is low on disk space - then it may delete it. There's an API StorageManager that can be used to request the database to remain persistent and never evict it. In your case a browser crash could also have made the data corrupt and the browser has choosen to evict it for that reason though.
Dexie offers an addon for exporting and importing data, dexie-export-import but it will be a manual step to export data regurlarly to backup the data. Another option is Dexie Cloud which continously backs up the data and keeps it in sync with the cloud service.
I do not have an answer on this. This is probably a very browser-implementation-specific topic and depends on where the browser stores the data on the hard drive.