connectToRemoteAndInitialize function

Future<DatabaseConnection> connectToRemoteAndInitialize(
  1. StreamChannel<Object?> channel, {
  2. bool debugLog = false,
  3. bool serialize = true,
  4. bool singleClientMode = false,
})

Connects to a remote server over a two-way communication channel.

The other end of the channel must be attached to a drift server with DriftServer.serve for this setup to work.

If it is known that only a single client will connect to this database server, singleClientMode can be enabled. When enabled, shutdown is implicitly called when the database connection is closed. This may make it easier to dispose the remote isolate or server. Also, update notifications for table updates don't have to be sent which reduces load on the connection.

If serialize is true, drift will only send bool, int, double, Uint8List, String or List's thereof over the channel. Otherwise, the message may be any Dart object. The value of serialize for connectToRemoteAndInitialize must be the same value passed to DriftServer.serve.

The optional debugLog can be enabled to print incoming and outgoing messages.

Implementation

Future<DatabaseConnection> connectToRemoteAndInitialize(
  StreamChannel<Object?> channel, {
  bool debugLog = false,
  bool serialize = true,
  bool singleClientMode = false,
}) async {
  final client = DriftClient(channel, debugLog, serialize, singleClientMode);
  await client.serverInfo;
  return client.connection;
}