drift/examples/app
Simon Binder b9a605ed25
Allow async mappings from SQL to row classes
When existing, custom row classes are used, drift now supports using a
(potentially asynchronous) static method to load them instead of just
a named constructor like before.
Tables are also changed to support the `map` method being async for
cases where that is needed. The same applies to custom queries which
may have to be async now.
2022-08-12 22:55:02 +02:00
..
android Add new cross-platform Flutter example 2022-04-02 18:01:10 +02:00
drift_schemas Add new cross-platform Flutter example 2022-04-02 18:01:10 +02:00
ios Update ios, macos projects 2022-07-02 08:31:17 +02:00
lib Allow async mappings from SQL to row classes 2022-08-12 22:55:02 +02:00
linux Remove js dep override override in example app 2022-05-29 20:07:41 +02:00
test Re-generate migration tests in app example 2022-07-29 18:54:41 +02:00
tool Example app: Add explanatory comment to copy builder 2022-06-03 23:18:23 +02:00
web Link new cross-platform example in docs 2022-04-08 21:16:46 +02:00
windows Remove js dep override override in example app 2022-05-29 20:07:41 +02:00
.gitignore Add new cross-platform Flutter example 2022-04-02 18:01:10 +02:00
.metadata Add new cross-platform Flutter example 2022-04-02 18:01:10 +02:00
README.md Add new cross-platform Flutter example 2022-04-02 18:01:10 +02:00
analysis_options.yaml Restructure drift test files 2022-04-03 12:53:58 +02:00
build.yaml Always enable the new SQL generation mode 2022-07-03 21:53:17 +02:00
pubspec.yaml Remove js dep override override in example app 2022-05-29 20:07:41 +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 flutter pub 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.

flutter pub 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:

flutter pub run drift_dev schema generate drift_schemas/ test/generated_migrations/

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