cloud_firestore_dart_sqlite 0.1.1
cloud_firestore_dart_sqlite: ^0.1.1 copied to clipboard
The SQLite offline cache of cloud_firestore_dart on the Dart VM, in Flutter and in the browser (WebAssembly on IndexedDB or OPFS), on top of package:sqlite3.
0.1.1 #
- Fix: the IndexedDB storage in a browser could lose acknowledged writes with
sqlite33.x. Affected: browser apps on 0.1.0 that use the IndexedDB storage (sqliteOpener()withoutopfsWorker, or with it in a browser without synchronous OPFS in workers) and resolvesqlite33.4.0 or later (pub picks the newest 3.x on Dart 3.10 or later). When the tab was killed or crashed shortly after a write, that write could be missing on the next page load although its future had completed. Lost were whole transactions at the end, never a part of one: the database stayed intact. The opener waited for the IndexedDB file system ofsqlite3with oneflush(), which sincesqlite33.6.0 returns when the batch of writes in progress is stored, not the writes queued behind it. It now waits for those too (see the README for what eachsqlite3version does). Not affected:sqlite32.7.3 to 3.3.4, the OPFS storage, the Dart VM and Flutter. sqlite33.4.0 to 3.5.2 cannot be made safe this way: theirflush()does not wait at all while writes are in progress. Do not use them with the IndexedDB storage; pub only picks them when you pin them.- With
sqlite33.x a write transaction on the IndexedDB storage now waits for IndexedDB, which it did not before: in Chrome the median went from 0.6 to 1.3 ms to 1.2 to 1.7 ms per transaction (tool/web_storage_benchmarkof the repository, noisy). With 2.x the extraflush()made no measurable difference.
0.1.0 #
First version, for cloud_firestore_dart 0.2 (FirebaseFirestore, Settings,
FirestoreException). The SQLite openers that cloud_firestore_dart 0.1.1 kept in its example/ folder
for apps to copy (sqlite_database.dart, sqlite_database_web.dart, sqlite_opfs_worker.dart),
moved into a package. Their logic is unchanged; what differs:
- One function for every platform:
sqliteOpener({directory, pageCacheMb, sqlite3Wasm, opfsWorker, storagePrefix, lockTimeout})replacessqliteOpener(Directory, {pageCacheMb})on the VM andsqliteWebOpener(...)in the browser.directoryis a pathString(nodart:iotype, so the call compiles on the web);sqlite3Wasmdefaults tosqlite3.wasm. The storage names, the file names and the Web Lock names are the ones of the copied files, so a cache written by them is opened again. openWithMemoryFallbacktakes theOpenDatabaseto try (openDatabase: sqliteOpener(...)) instead ofsqlite3WasmandopfsWorker, and works on every platform.sqlite32.7.3 to 3.x. The VM opener no longer importspackage:sqlite3/open.dart, which 3.x removed, and so no longer overrides the library lookup on Linux. With 3.x the library comes from the build hook ofsqlite3. With 2.x the default lookup ofsqlite3applies: this fixes Flutter on Linux, where the override made the copied opener load the system SQLite instead of the onesqlite3_flutter_libsbundles; a plain Dart program on a Linux machine withoutlibsqlite3.soneeds the override the README shows.close()still callsdispose(), the only close of 2.x (deprecated, not removed, in 3.x).- The OPFS worker is the library
package:cloud_firestore_dart_sqlite/opfs_worker.dart(runOpfsWorker), anddart run cloud_firestore_dart_sqlite:setup_web [web dir]compiles it to<web dir>/sqlite_opfs_worker.jsand prints the URL of the matchingsqlite3.wasm. - The browser-only classes (
SqliteWebDatabase,SqliteOpfsDatabase,inspectOpfsDatabase,sqliteWebOpener) are inpackage:cloud_firestore_dart_sqlite/web.dart.