drift/examples/app
Simon Binder f9a163532b Disable third-party warnings in cocoapods project 2024-04-21 18:36:10 +02:00
..
android Highlight Android workarounds more 2023-10-24 21:14:57 +02:00
drift_schemas Fix triggers in example app 2022-08-31 11:58:25 +02:00
ios Disable third-party warnings in cocoapods project 2024-04-21 18:36:10 +02:00
lib Re-run generator 2023-12-12 12:15:17 +01:00
linux Remove js dep override override in example app 2022-05-29 20:07:41 +02:00
macos Disable third-party warnings in cocoapods project 2024-04-21 18:36:10 +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 Re-run builder in example app 2023-08-09 21:03:36 +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 macOS target to example app 2023-09-07 15:20:10 +02:00
README.md Explain build_runner is necessary for web samples 2024-01-03 23:04:58 +01: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
devtools_options.yaml Integrate db viewer into devtools 2023-10-18 23:16:52 +02:00
pubspec.yaml Upgrade go_router in example app 2023-07-22 15:14:38 +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. To run or build this app on the web, first run build_runner build to compile the web worker used to access databases.

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

Migration

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/

To make migrations easier, this command updates the lib/database/schema_versions.dart file containing snapshots of older database schema:

dart run drift_dev schema steps drift_schemas/ lib/database/schema_versions.dart

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