connect method

Future<DatabaseConnection> connect({
  1. bool isolateDebugLog = false,
  2. bool singleClientMode = false,
  3. Duration? connectTimeout,
})

Connects to this DriftIsolate from another isolate.

All operations on the returned DatabaseConnection will be executed on a background isolate.

When singleClientMode is enabled (it defaults to false), drift assumes that the isolate will only be connected to once. In this mode, drift will shutdown the remote isolate once the returned DatabaseConnection is closed. Also, stream queries are more efficient when this mode is enables since we don't have to synchronize table updates to other clients (since there are none).

Setting the isolateDebugLog is only helpful when debugging drift itself. It will print messages exchanged between the two isolates.

Implementation

Future<DatabaseConnection> connect({
  bool isolateDebugLog = false,
  bool singleClientMode = false,
  Duration? connectTimeout,
}) async {
  final (channel, serialize) = await _open(connectTimeout);
  final connection = await connectToRemoteAndInitialize(
    channel,
    debugLog: isolateDebugLog,
    serialize: serialize,
    singleClientMode: singleClientMode,
  );

  return DatabaseConnection(connection.executor,
      streamQueries: connection.streamQueries, connectionData: this);
}