drift/examples/app
Simon Binder 81315c3d69
Migrate mentions of `flutter pub run`
2023-06-19 16:09:47 +02:00
..
android Add new cross-platform Flutter example 2022-04-02 18:01:10 +02:00
drift_schemas Fix triggers in example app 2022-08-31 11:58:25 +02:00
ios Update ios, macos projects 2022-07-02 08:31:17 +02:00
lib Get new wasm implementation working in Chrome 2023-05-31 22:48:29 +02:00
linux Remove js dep override override in example app 2022-05-29 20:07:41 +02:00
test Fix reading triggers in old schema files (#2191) 2022-12-10 22:57:45 +01:00
tool Get new wasm implementation working in Chrome 2023-05-31 22:48:29 +02:00
web Rename old web test package 2023-06-10 18:01:25 +02:00
windows Remove js dep override override in example app 2022-05-29 20:07:41 +02:00
.gitignore Get new wasm implementation working in Chrome 2023-05-31 22:48:29 +02:00
.metadata Add new cross-platform Flutter example 2022-04-02 18:01:10 +02:00
README.md Migrate mentions of `flutter pub run` 2023-06-19 16:09:47 +02:00
analysis_options.yaml Restructure drift test files 2022-04-03 12:53:58 +02:00
build.yaml Get new wasm implementation working in Chrome 2023-05-31 22:48:29 +02:00
pubspec.yaml Update to stable sqlite3 package 2023-06-17 22:19:31 +02:00

README.md

app

A cross-platform todo app using drift for local persistence.

Supported platforms

This app runs on

  • Android
  • iOS
  • macOS
  • Linux
  • Windows
  • Web

When running the app, either with flutter run or by running the outputs of flutter build, native sqlite3 dependencies should be set up automatically. When running the app in a regular Dart VM, for instance through flutter test, you need to ensure that sqlite3 is available yourself. See the documentation for more details on this.

Development

As this app uses drift, it depends on code-generation. Use dart run build_runner build to automatically build the generated code.

Testing

Drift databases don't depend on platform-channels or Flutter-specific features by default. This means that they can easily be used in unit tests. One such test is in test/database_test.dart

Testing migrations

After changing the structure of your database schema, for instance by adding new tables or altering columns, you need to write a migration to ensure that existing users of your app can convert their database to the latest version.

Drift contains builtin APIs for common migrations. Also, it includes builtin tools to verify that migrations are doing what they're supposed to do.

To write such tests, run the following command after making schema changes and incrementing your schema version. It will export the current schema of the database as a JSON file. You should check those generated files into source control.

dart run drift_dev schema dump lib/database/database.dart drift_schemas/

Then, run the following command to automatically generate test utilities which you can use to write unit tests for schema migrations:

dart run drift_dev schema generate drift_schemas/ test/generated_migrations/

An example for a schema test is in test/migration_test.dart.