databaseFactoryFfi top-level property

DatabaseFactory get databaseFactoryFfi

The sqflite database factory using ffi (package:sqlite3).

Works on Windows, Linux and macOS (Flutter and Dart VM), also on Android and iOS. SQLite is bundled with the application by package:sqlite3 build hooks (run with dart run, dart test, flutter run...). Database calls run in a background isolate.

Call sqfliteFfiInit first. Use the factory directly:

sqfliteFfiInit();
var db = await databaseFactoryFfi.openDatabase(
  inMemoryDatabasePath,
  options: OpenDatabaseOptions(
    version: 1,
    onCreate: (db, version) =>
        db.execute('CREATE TABLE Test (id INTEGER PRIMARY KEY, name TEXT)'),
  ),
);

or set it as the global factory used by openDatabase() (existing sqflite code, unit tests), once, before opening any database:

sqfliteFfiInit();
databaseFactory = databaseFactoryFfi;

getDatabasesPath() returns .dart_tool/sqflite_common_ffi/databases in the current directory: use absolute paths in an application.

Not supported on the web, use databaseFactoryFfiWeb from the sqflite_common_ffi_web package.

Implementation

DatabaseFactory get databaseFactoryFfi => databaseFactoryFfiImpl;