remote function

  1. @Deprecated('Use the asynchronous `connectToRemoteAndInitialize` instead')
DatabaseConnection remote(
  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 remote must be the same value passed to DriftServer.serve.

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

NOTE: This synchronous method has a flaw, as its QueryExecutor.dialect is always going to be SqlDialect.sqlite. While this not a problem in most scenarios where that is the actual database, it makes it harder to use with other database clients. The connectToRemoteAndInitialize method does not have this issue.

Due to this problem, it is recommended to avoid remote altogether. If you know the dialect beforehand, you can wrap connectToRemoteAndInitialize in a DatabaseConnection.delayed to get a connection sychronously.

Implementation

@Deprecated('Use the asynchronous `connectToRemoteAndInitialize` instead')
DatabaseConnection remote(
  StreamChannel<Object?> channel, {
  bool debugLog = false,
  bool serialize = true,
  bool singleClientMode = false,
}) {
  final client = DriftClient(channel, debugLog, serialize, singleClientMode);
  return client.connection;
}