diff --git a/packages/sqlite_async/CHANGELOG.md b/packages/sqlite_async/CHANGELOG.md index 924097a..c00af79 100644 --- a/packages/sqlite_async/CHANGELOG.md +++ b/packages/sqlite_async/CHANGELOG.md @@ -2,6 +2,7 @@ - Native: Add the `NativeSqliteOpenFactory.beforeOpen` method, which can be overridden to configure SQLite asynchronously before opening databases. +- Web: Upgrade `package:sqlite3_web` to flush IndexedDB writes automatically, deprecate `flush()`. ## 0.14.3 diff --git a/packages/sqlite_async/lib/src/web/connection.dart b/packages/sqlite_async/lib/src/web/connection.dart index 475962e..2ac974f 100644 --- a/packages/sqlite_async/lib/src/web/connection.dart +++ b/packages/sqlite_async/lib/src/web/connection.dart @@ -6,6 +6,11 @@ import 'database.dart'; import 'update_notifications.dart'; import 'web_mutex.dart'; +const _deprecatedFlush = Deprecated( + 'The flush parameter no longer does anything, IndexedDB databases are ' + 'persisted after each write lock.', +); + /// An endpoint that can be used, by any running JavaScript context in the same /// website, to connect to an existing [WebSqliteConnection]. /// @@ -74,17 +79,19 @@ abstract class WebSqliteConnection implements SqliteConnection { /// to delay flushing changes to the database file, losing durability guarantees. /// This only has an effect when IndexedDB storage is used. /// - /// See [flush] for details. + /// See [WebSqliteConnection.flush] for details. @override Future writeLock(Future Function(SqliteWriteContext tx) callback, - {Duration? lockTimeout, String? debugContext, bool? flush}); + {Duration? lockTimeout, + String? debugContext, + @_deprecatedFlush bool? flush}); @override Future abortableWriteLock( Future Function(SqliteWriteContext tx) callback, {Future? abortTrigger, String? debugContext, - bool? flush}); + @_deprecatedFlush bool? flush}); /// Same as [SqliteConnection.writeTransaction]. /// @@ -92,18 +99,22 @@ abstract class WebSqliteConnection implements SqliteConnection { /// to delay flushing changes to the database file, losing durability guarantees. /// This only has an effect when IndexedDB storage is used. /// - /// See [flush] for details. + /// See [WebSqliteConnection.flush] for details. @override Future writeTransaction( Future Function(SqliteWriteContext tx) callback, {Duration? lockTimeout, - bool? flush}); + @_deprecatedFlush bool? flush}); /// Flush changes to the underlying storage. /// - /// When this returns, all changes previously written will be persisted - /// to storage. + /// In older versions of the `sqlite3` package, writes on IndexedDB databases + /// used to be asynchronous and might not complete if a tab writing to a + /// database was closed shortly after making its write. /// - /// This only has an effect when IndexedDB storage is used. + /// This is no longer an issue, recent versions persist changes in an + /// IndexedDB transaction before the transaction completes. Thus, this method + /// is deprecated and should not be used anymore. + @_deprecatedFlush Future flush(); } diff --git a/packages/sqlite_async/lib/src/web/database.dart b/packages/sqlite_async/lib/src/web/database.dart index 3e464f4..d374c39 100644 --- a/packages/sqlite_async/lib/src/web/database.dart +++ b/packages/sqlite_async/lib/src/web/database.dart @@ -103,7 +103,6 @@ final class WebDatabase extends SqliteDatabaseImpl (unscoped) => ScopedReadContext.assumeReadLock(unscoped, callback), abortTrigger: abortTrigger, debugContext: debugContext, - flush: false, ); } @@ -121,7 +120,6 @@ final class WebDatabase extends SqliteDatabaseImpl }, ); }, - flush: flush ?? true, abortTrigger: lockTimeout?.asTimeout, ); } @@ -133,7 +131,6 @@ final class WebDatabase extends SqliteDatabaseImpl callback, abortTrigger: lockTimeout?.asTimeout, debugContext: debugContext, - flush: flush, ); } @@ -147,7 +144,6 @@ final class WebDatabase extends SqliteDatabaseImpl (unscoped) { return ScopedWriteContext.assumeWriteLock(unscoped, callback); }, - flush: flush ?? true, debugContext: debugContext, abortTrigger: abortTrigger, ); @@ -155,32 +151,19 @@ final class WebDatabase extends SqliteDatabaseImpl Future _lockInternal( Future Function(_UnscopedContext) callback, { - required bool flush, Future? abortTrigger, String? debugContext, }) async { if (_mutex case var mutex?) { return await mutex.lock(abortTrigger: abortTrigger, () async { final context = _UnscopedContext(this, null); - try { - return await callback(context); - } finally { - if (flush) { - await this.flush(); - } - } + return await callback(context); }); } else { return await _database.requestLock(abortTrigger: abortTrigger, (token) async { final context = _UnscopedContext(this, token); - try { - return await callback(context); - } finally { - if (flush) { - await this.flush(); - } - } + return await callback(context); }).translateAbortExceptions(debugContext ?? 'lock'); } } diff --git a/packages/sqlite_async/lib/src/web/database/async_web_database.dart b/packages/sqlite_async/lib/src/web/database/async_web_database.dart index 6084c66..4a49836 100644 --- a/packages/sqlite_async/lib/src/web/database/async_web_database.dart +++ b/packages/sqlite_async/lib/src/web/database/async_web_database.dart @@ -101,7 +101,7 @@ final class AsyncWebDatabaseImpl extends SqliteDatabaseImpl await isInitialized; return _runZoned(() { return _connection.writeLock(callback, - lockTimeout: lockTimeout, debugContext: debugContext, flush: flush); + lockTimeout: lockTimeout, debugContext: debugContext); }, debugContext: debugContext ?? 'execute()'); } @@ -114,7 +114,7 @@ final class AsyncWebDatabaseImpl extends SqliteDatabaseImpl await isInitialized; return _runZoned(() { return _connection.abortableWriteLock(callback, - abortTrigger: abortTrigger, debugContext: debugContext, flush: flush); + abortTrigger: abortTrigger, debugContext: debugContext); }, debugContext: debugContext ?? 'execute()'); } @@ -125,8 +125,7 @@ final class AsyncWebDatabaseImpl extends SqliteDatabaseImpl bool? flush}) async { await isInitialized; return _runZoned( - () => _connection.writeTransaction(callback, - lockTimeout: lockTimeout, flush: flush), + () => _connection.writeTransaction(callback, lockTimeout: lockTimeout), debugContext: 'writeTransaction()'); } diff --git a/packages/sqlite_async/pubspec.yaml b/packages/sqlite_async/pubspec.yaml index 1c1fb00..be945a8 100644 --- a/packages/sqlite_async/pubspec.yaml +++ b/packages/sqlite_async/pubspec.yaml @@ -1,6 +1,6 @@ name: sqlite_async description: High-performance asynchronous interface for SQLite on Dart and Flutter. -version: 0.14.3 +version: 0.14.4 resolution: workspace repository: https://github.com/powersync-ja/sqlite_async.dart environment: @@ -13,8 +13,8 @@ topics: - flutter dependencies: - sqlite3: ^3.2.0 - sqlite3_web: '>=0.8.0 <0.10.0' + sqlite3: ^3.4.0 + sqlite3_web: ^0.9.3 sqlite3_connection_pool: ^0.2.4 async: ^2.10.0 collection: ^1.17.0