From 5c0a08de2431c681ad8de25566c4abe33c76bb33 Mon Sep 17 00:00:00 2001 From: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> Date: Fri, 12 Sep 2025 01:26:01 +0530 Subject: [PATCH] add isolateDebugLog to DriftNativeOptions --- drift_flutter/lib/src/connect.dart | 17 +++++++++++------ drift_flutter/lib/src/native.dart | 11 ++++++++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/drift_flutter/lib/src/connect.dart b/drift_flutter/lib/src/connect.dart index 644137469..d79f20005 100644 --- a/drift_flutter/lib/src/connect.dart +++ b/drift_flutter/lib/src/connect.dart @@ -39,12 +39,12 @@ final class DriftWebOptions { final FutureOr Function()? initializeDatabase; /// Create web-specific drift options. - DriftWebOptions( - {required this.sqlite3Wasm, - required this.driftWorker, - this.onResult, - this.initializeDatabase, - }); + DriftWebOptions({ + required this.sqlite3Wasm, + required this.driftWorker, + this.onResult, + this.initializeDatabase, + }); } /// Options used to open drift databases on native platforms (outside of the @@ -67,6 +67,10 @@ final class DriftNativeOptions { /// may be used on multiple isolates. final bool shareAcrossIsolates; + /// Setting the [isolateDebugLog] is only helpful when debugging drift itself. + /// It will print messages exchanged between the Drift server and the client. + final bool isolateDebugLog; + /// An optional callback returning a custom database path to be used by drift. /// /// By default, drift uses the `getApplicationDocumentsDirectory()` function @@ -129,6 +133,7 @@ final class DriftNativeOptions { /// platforms. const DriftNativeOptions({ this.shareAcrossIsolates = false, + this.isolateDebugLog = false, this.databasePath, this.databaseDirectory, this.tempDirectoryPath, diff --git a/drift_flutter/lib/src/native.dart b/drift_flutter/lib/src/native.dart index 73c2a4503..a0917bf8c 100644 --- a/drift_flutter/lib/src/native.dart +++ b/drift_flutter/lib/src/native.dart @@ -7,8 +7,8 @@ import 'package:drift/drift.dart'; import 'package:drift/isolate.dart'; import 'package:drift/native.dart'; import 'package:meta/meta.dart'; -import 'package:path_provider/path_provider.dart'; import 'package:path/path.dart' as p; +import 'package:path_provider/path_provider.dart'; import 'package:sqlite3/sqlite3.dart'; import 'package:sqlite3_flutter_libs/sqlite3_flutter_libs.dart'; @@ -82,7 +82,10 @@ QueryExecutor driftDatabase({ case final port?) { final isolate = DriftIsolate.fromConnectPort(port); try { - return await isolate.connect(connectTimeout: connectTimeout); + return await isolate.connect( + connectTimeout: connectTimeout, + isolateDebugLog: native.isolateDebugLog, + ); } on TimeoutException { // Isolate has stopped shortly after the register call. It should // also remove the port mapping, so we can just try again in another @@ -124,7 +127,9 @@ QueryExecutor driftDatabase({ // due to a race condition (in which case it exits). final first = await firstMessage; if (first case SendPort port) { - return await DriftIsolate.fromConnectPort(port).connect(); + return await DriftIsolate.fromConnectPort(port).connect( + isolateDebugLog: native.isolateDebugLog, + ); } } }