Skip to content

Latest commit

 

History

History
48 lines (35 loc) · 1.73 KB

sqlite.md

File metadata and controls

48 lines (35 loc) · 1.73 KB

SQLite Provider

Intelligent Migrations

Whenever a new field(s) is added or removed from a connected model, Brick can automatically generate a migration for SQLite. For even less friction, running the watcher while actively developing will create the migration on model save:

flutter pub run build_runner watch

?> While Brick guesses right most of the time, the migration should still be reviewed after it's created (for example, a DropTable might just be a RenameTable or maybe onDeleteCascade needs to be set for a InsertForeignKey).

Multiplatform Support

Brick SQLite can be used when developing for Windows, MacOS, and Linux platforms. The following is not required for iOS and Android development except in a test environment..

  1. Add sqflite_common packages to your pubspec. If you're stubbing SQLite responses for testing, the packages only need to be added under dev_dependencies:.

    sqflite_common: any
    sqflite_common_ffi: any
  2. Use the SQLite FFI database factory when initializing your provider:

    import 'package:sqflite_common/sqlite_api.dart';
    import 'package:sqflite_common_ffi/sqflite_ffi.dart';
    
    MyRepository(
      sqliteProvider: SqliteProvider(
        inMemoryDatabase,
        databaseFactory: databaseFactoryFfi,
      ),
    );
  3. Make sure FFI is initialized when starting your app or running unit tests:

    void main() {
      sqfliteFfiInit();
      runApp(MyApp())
    }

FAQ

Can I specify a different table name?

Table names, association column names, and primary key column names are managed by the package. They are currently unchangeable.