createBackgroundConnection static method Null safety
- File file,
- {bool logStatements = false,
- DatabaseSetup? setup}
Like createInBackground, except that it returns the whole DatabaseConnection instead of just the executor.
This creates a database writing data to the given file
. The database
runs in a background isolate and is stopped when closed.
Implementation
static DatabaseConnection createBackgroundConnection(File file,
{bool logStatements = false, DatabaseSetup? setup}) {
return DatabaseConnection.delayed(Future.sync(() async {
final receiveIsolate = ReceivePort();
await Isolate.spawn(
_NativeIsolateStartup.start,
_NativeIsolateStartup(
file.absolute.path, logStatements, setup, receiveIsolate.sendPort),
debugName: 'Drift isolate worker for ${file.path}',
);
final driftIsolate = await receiveIsolate.first as DriftIsolate;
receiveIsolate.close();
return driftIsolate.connect(singleClientMode: true);
}));
}