Move examples into top-level folder

This commit is contained in:
Simon Binder 2022-04-01 22:11:21 +02:00
parent 26c3dbfb48
commit 204fbad682
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
65 changed files with 17 additions and 9 deletions

View File

@ -200,7 +200,7 @@ targets:
In all files that use generated drift code, you'll have to replace `part 'filename.g.dart'` with `part 'filename.drift.dart'`. In all files that use generated drift code, you'll have to replace `part 'filename.g.dart'` with `part 'filename.drift.dart'`.
If you use drift _and_ another builder in the same file, you'll need both `.g.dart` and `.drift.dart` as part-files. If you use drift _and_ another builder in the same file, you'll need both `.g.dart` and `.drift.dart` as part-files.
A full example is available as part of [the drift repo](https://github.com/simolus3/drift/tree/develop/extras/with_built_value). A full example is available as part of [the drift repo](https://github.com/simolus3/drift/tree/develop/examples/with_built_value).
If you run into any problems with this approach, feel free to open an issue on drift. If you run into any problems with this approach, feel free to open an issue on drift.

View File

@ -249,7 +249,7 @@ By using those test databases, drift can help you test migrations from and to an
{% block "blocks/alert" title="Complex topic ahead" %} {% block "blocks/alert" title="Complex topic ahead" %}
> Writing schema tests is an advanced topic that requires a fairly complex setup described here. > Writing schema tests is an advanced topic that requires a fairly complex setup described here.
If you get stuck along the way, don't hesitate to [open a discussion about it](https://github.com/simolus3/drift/discussions). If you get stuck along the way, don't hesitate to [open a discussion about it](https://github.com/simolus3/drift/discussions).
Also, there's a working example [in the drift repository](https://github.com/simolus3/drift/tree/latest-release/extras/migrations_example). Also, there's a working example [in the drift repository](https://github.com/simolus3/drift/tree/latest-release/examples/migrations_example).
{% endblock %} {% endblock %}
### Setup ### Setup

View File

@ -194,21 +194,21 @@ DatabaseConnection connectToWorker() {
} }
``` ```
You can pass that `DatabaseConnection` to your database by enabling the You can pass that `DatabaseConnection` to your database by enabling the
`generate_connect_constructor` build option. `generate_connect_constructor` build option.
For more information on the `DatabaseConnection` class, see the documentation on For more information on the `DatabaseConnection` class, see the documentation on
[isolates]({{ "../Advanced Features/isolates.md" | pageUrl }}). [isolates]({{ "../Advanced Features/isolates.md" | pageUrl }}).
A small, but working example is available under [extras/web_worker_example](https://github.com/simolus3/drift/tree/develop/extras/web_worker_example) A small, but working example is available under [examples/web_worker_example](https://github.com/simolus3/drift/tree/develop/examples/web_worker_example)
in the drift repository. in the drift repository.
### Flutter ### Flutter
Flutter users will have to use a different approach to compile service workers. Flutter users will have to use a different approach to compile service workers.
Flutter web doesn't compile `.dart` files in web folder and won't use `.js` files generated by Flutter web doesn't compile `.dart` files in web folder and won't use `.js` files generated by
`build_web_compilers` either. Instead, we'll use Dart's build system to manually compile the worker to a `build_web_compilers` either. Instead, we'll use Dart's build system to manually compile the worker to a
JavaScript file before using Flutter-specific tooling. JavaScript file before using Flutter-specific tooling.
Example is available under [extras/flutter_web_worker_example](https://github.com/simolus3/drift/tree/develop/extras/flutter_web_worker_example) Example is available under [examples/flutter_web_worker_example](https://github.com/simolus3/drift/tree/develop/examples/flutter_web_worker_example)
in the drift repository. in the drift repository.
First, add [build_web_compilers](https://pub.dev/packages/build_web_compilers) to the project: First, add [build_web_compilers](https://pub.dev/packages/build_web_compilers) to the project:

8
examples/README.md Normal file
View File

@ -0,0 +1,8 @@
## Examples using drift
This collection of examples demonstrates how to use some advanced drift features.
- `flutter_web_worker_example`: Asynchronously run a drift database through a web worker with Fluter.
- `migrations_example`: Example showing to how to generate test utilities to verify schema migration.
- `web_worker_-_example`: Asynchronously run a drift database through a web worker, without Flutter.
- `with_built_value`: Configure `build_runner` so that drift-generated classes can be used by `build_runner`.

View File

@ -12,19 +12,19 @@ dart pub upgrade
dart test || EXIT_CODE=$? dart test || EXIT_CODE=$?
popd popd
pushd extras/integration_tests/postgres pushd examples/integration_tests/postgres
echo "Running integration tests with Postgres" echo "Running integration tests with Postgres"
dart pub upgrade dart pub upgrade
dart test || EXIT_CODE=$? dart test || EXIT_CODE=$?
popd popd
pushd extras/with_built_value pushd examples/with_built_value
echo "Running build runner in with_built_value" echo "Running build runner in with_built_value"
dart pub upgrade dart pub upgrade
dart run build_runner build --delete-conflicting-outputs || EXIT_CODE=$? dart run build_runner build --delete-conflicting-outputs || EXIT_CODE=$?
popd popd
pushd extras/migrations_example pushd examples/migrations_example
echo "Testing migrations in migrations_example" echo "Testing migrations in migrations_example"
dart pub upgrade dart pub upgrade
dart test dart test