createInBackground static method

QueryExecutor createInBackground(
  1. File file,
  2. {bool logStatements = false,
  3. bool cachePreparedStatements = _cacheStatementsByDefault,
  4. DatabaseSetup? setup,
  5. bool enableMigrations = true,
  6. IsolateSetup? isolateSetup}

Creates a database storing its result in file.

This method will create the same database as the default constructor of the NativeDatabase class. It also behaves the same otherwise: The file is created if it doesn't exist, logStatements can be used to print statements and setup can be used to perform a one-time setup work when the database is created.

The big distinction of this method is that the database is implicitly created on a background isolate, freeing up your main thread accessing the database from I/O work needed to run statements. When the database returned by this method is closed, the background isolate will shut down as well.

Important limitations: If the setup parameter is given, it must be a static or top-level function. The reason is that it is executed on another isolate.


static QueryExecutor createInBackground(
  File file, {
  bool logStatements = false,
  bool cachePreparedStatements = _cacheStatementsByDefault,
  DatabaseSetup? setup,
  bool enableMigrations = true,
  IsolateSetup? isolateSetup,
}) {
  return createBackgroundConnection(
    logStatements: logStatements,
    setup: setup,
    isolateSetup: isolateSetup,
    enableMigrations: enableMigrations,
    cachePreparedStatements: cachePreparedStatements,