Cross-platform implementation to delete the database entirely? #3595
|
During dev I sometimes encounter a corrupted database. That's likely related to hot-reloads or exceptions, but since I can't be entirely sure that this doesn't happen in production, I want a way for the user to manually reset the database. I'm getting this error as soon as I start a transaction or query on the database: At the moment I'm only supporting web, but there will be iOS in the future. I already found this discussion #2821, which looks helpful, but (1) is only for web and (2) only for wasm. For me, drift is currently using IndexedDB and outputs this warning: To reset IndexedDB I could use Then what about the other platforms? This is how I open the connection final connection = driftDatabase(
name: name,
native: const DriftNativeOptions(),
web: DriftWebOptions(
sqlite3Wasm: Uri.parse('sqlite3.wasm'),
driftWorker: Uri.parse('drift_worker.dart.js'),
),
);Since I don't explicitly pass a file argument, I don't know where the sqlite database is located. I think it would be really great if drift would support purging the database out of the box. |
Replies: 1 comment 1 reply
So just to be clear, wasm here refers to the fact that SQLite is compiled to a WebAssembly bundle. So the snippet from the linked discussion should work correctly (using I'm trying to keep the api in |
So just to be clear, wasm here refers to the fact that SQLite is compiled to a WebAssembly bundle. So the snippet from the linked discussion should work correctly (using
WasmDatabase.probe+deleteDatabaseactually works for all storage modes drift can use on the web, with your setup you'd get OPFS on Firefox and IndexedDB on other browsers).I'm trying to keep the api in
drift_fluttersomewhat minimal, but I agree that a cross-platform way to delete databases might be helpful. I'll take a look!