mirror of https://github.com/AMT-Cheif/drift.git
Document #2537 better
This commit is contained in:
parent
e433cff932
commit
94c4c1a8e0
|
@ -15,37 +15,11 @@ how to get started. You can watch it [here](https://youtu.be/zpWsedYMczM).
|
||||||
A complete cross-platform Flutter app using drift is also available [here](https://github.com/simolus3/drift/tree/develop/examples/app).
|
A complete cross-platform Flutter app using drift is also available [here](https://github.com/simolus3/drift/tree/develop/examples/app).
|
||||||
|
|
||||||
## Adding the dependency
|
## Adding the dependency
|
||||||
First, lets add drift to your project's `pubspec.yaml`.
|
|
||||||
At the moment, the current version of `drift` is [![Drift version](https://img.shields.io/pub/v/drift.svg)](https://pub.dev/packages/drift)
|
|
||||||
and the latest version of `drift_dev` is [![Generator version](https://img.shields.io/pub/v/drift_dev.svg)](https://pub.dev/packages/drift_dev).
|
|
||||||
|
|
||||||
{% assign versions = 'package:drift_docs/versions.json' | readString | json_decode %}
|
{% include "partials/dependencies" %}
|
||||||
|
|
||||||
{% assign snippets = 'package:drift_docs/snippets/tables/filename.dart.excerpt.json' | readString | json_decode %}
|
{% assign snippets = 'package:drift_docs/snippets/tables/filename.dart.excerpt.json' | readString | json_decode %}
|
||||||
|
|
||||||
```yaml
|
|
||||||
dependencies:
|
|
||||||
drift: ^{{ versions.drift }}
|
|
||||||
sqlite3_flutter_libs: ^0.5.0
|
|
||||||
path_provider: ^2.0.0
|
|
||||||
path: ^{{ versions.path }}
|
|
||||||
|
|
||||||
dev_dependencies:
|
|
||||||
drift_dev: ^{{ versions.drift_dev }}
|
|
||||||
build_runner: ^{{ versions.build_runner }}
|
|
||||||
```
|
|
||||||
|
|
||||||
If you're wondering why so many packages are necessary, here's a quick overview over what each package does:
|
|
||||||
|
|
||||||
- `drift`: This is the core package defining most apis
|
|
||||||
- `sqlite3_flutter_libs`: Ships the latest `sqlite3` version with your Android or iOS app. This is not required when you're _not_ using Flutter,
|
|
||||||
but then you need to take care of including `sqlite3` yourself.
|
|
||||||
For an overview on other platforms, see [platforms]({{ '../platforms.md' | pageUrl }}).
|
|
||||||
- `path_provider` and `path`: Used to find a suitable location to store the database. Maintained by the Flutter and Dart team
|
|
||||||
- `drift_dev`: This development-only dependency generates query code based on your tables. It will not be included in your final app.
|
|
||||||
- `build_runner`: Common tool for code-generation, maintained by the Dart team
|
|
||||||
|
|
||||||
{% include "partials/changed_to_ffi" %}
|
|
||||||
|
|
||||||
### Declaring tables
|
### Declaring tables
|
||||||
|
|
||||||
Using drift, you can model the structure of your tables with simple dart code.
|
Using drift, you can model the structure of your tables with simple dart code.
|
||||||
|
|
|
@ -12,35 +12,8 @@ declaring both tables and queries in Dart. This version will focus on how to use
|
||||||
A complete cross-platform Flutter app using drift is also available [here](https://github.com/simolus3/drift/tree/develop/examples/app).
|
A complete cross-platform Flutter app using drift is also available [here](https://github.com/simolus3/drift/tree/develop/examples/app).
|
||||||
|
|
||||||
## Adding the dependency
|
## Adding the dependency
|
||||||
First, lets add drift to your project's `pubspec.yaml`.
|
|
||||||
At the moment, the current version of `drift` is [![Drift version](https://img.shields.io/pub/v/drift.svg)](https://pub.dev/packages/drift)
|
|
||||||
and the latest version of `drift_dev` is [![Generator version](https://img.shields.io/pub/v/drift_dev.svg)](https://pub.dev/packages/drift_dev).
|
|
||||||
|
|
||||||
{% assign versions = 'package:drift_docs/versions.json' | readString | json_decode %}
|
{% include "partials/dependencies" %}
|
||||||
|
|
||||||
```yaml
|
|
||||||
dependencies:
|
|
||||||
drift: ^{{ versions.drift }}
|
|
||||||
sqlite3_flutter_libs: ^0.5.0
|
|
||||||
path_provider: ^2.0.0
|
|
||||||
path: ^{{ versions.path }}
|
|
||||||
|
|
||||||
dev_dependencies:
|
|
||||||
drift_dev: ^{{ versions.drift_dev }}
|
|
||||||
build_runner: ^{{ versions.build_runner }}
|
|
||||||
```
|
|
||||||
|
|
||||||
If you're wondering why so many packages are necessary, here's a quick overview over what each package does:
|
|
||||||
|
|
||||||
- `drift`: This is the core package defining most apis
|
|
||||||
- `sqlite3_flutter_libs`: Ships the latest `sqlite3` version with your Android or iOS app. This is not required when you're _not_ using Flutter,
|
|
||||||
but then you need to take care of including `sqlite3` yourself.
|
|
||||||
For an overview on other platforms, see [platforms]({{ '../platforms.md' | pageUrl }}).
|
|
||||||
- `path_provider` and `path`: Used to find a suitable location to store the database. Maintained by the Flutter and Dart team
|
|
||||||
- `drift_dev`: This development-only dependency generates query code based on your tables. It will not be included in your final app.
|
|
||||||
- `build_runner`: Common tool for code-generation, maintained by the Dart team
|
|
||||||
|
|
||||||
{% include "partials/changed_to_ffi" %}
|
|
||||||
|
|
||||||
## Declaring tables and queries
|
## Declaring tables and queries
|
||||||
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
<div class="alert alert-primary" role="alert">
|
|
||||||
<h4 class="alert-heading">Changes to the recommended implementation</h4>
|
|
||||||
<p>
|
|
||||||
Previous versions of this article recommended to use <code>moor_flutter</code> or
|
|
||||||
the <code>moor_ffi</code> package.
|
|
||||||
For new users, we recommend to use <code>package:drift/native.dart</code> to open the database -
|
|
||||||
more on that below!
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
If you have an existing setup that works, there's no need to change anything.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
Some versions of the Flutter tool create a broken `settings.gradle` on Android, which can cause problems with `drift/native.dart`.
|
|
||||||
If you get a "Failed to load dynamic library" exception, see [this comment](https://github.com/flutter/flutter/issues/55827#issuecomment-623779910).
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
{% block "blocks/markdown" %}
|
||||||
|
|
||||||
|
First, lets add drift to your project's `pubspec.yaml`.
|
||||||
|
At the moment, the current version of `drift` is [![Drift version](https://img.shields.io/pub/v/drift.svg)](https://pub.dev/packages/drift)
|
||||||
|
and the latest version of `drift_dev` is [![Generator version](https://img.shields.io/pub/v/drift_dev.svg)](https://pub.dev/packages/drift_dev).
|
||||||
|
|
||||||
|
{% assign versions = 'package:drift_docs/versions.json' | readString | json_decode %}
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
dependencies:
|
||||||
|
drift: ^{{ versions.drift }}
|
||||||
|
sqlite3_flutter_libs: ^0.5.0
|
||||||
|
path_provider: ^2.0.0
|
||||||
|
path: ^{{ versions.path }}
|
||||||
|
|
||||||
|
dev_dependencies:
|
||||||
|
drift_dev: ^{{ versions.drift_dev }}
|
||||||
|
build_runner: ^{{ versions.build_runner }}
|
||||||
|
```
|
||||||
|
|
||||||
|
If you're wondering why so many packages are necessary, here's a quick overview over what each package does:
|
||||||
|
|
||||||
|
- `drift`: This is the core package defining the APIs you use to access drift databases.
|
||||||
|
- `sqlite3_flutter_libs`: Ships the latest `sqlite3` version with your Android or iOS app. This is not required when you're _not_ using Flutter,
|
||||||
|
but then you need to take care of including `sqlite3` yourself.
|
||||||
|
For an overview on other platforms, see [platforms]({{ '../platforms.md' | pageUrl }}).
|
||||||
|
Note that the `sqlite3_flutter_libs` package will include the native sqlite3 library for the following
|
||||||
|
architectures: `armv8`, `armv7`, `x86` and `x86_64`.
|
||||||
|
Most Flutter apps don't run on 32-bit x86 devices without further setup, so you should
|
||||||
|
[add a snippet](https://github.com/simolus3/sqlite3.dart/tree/main/sqlite3_flutter_libs#included-platforms)
|
||||||
|
to your `build.gradle` if you don't need `x86` builds.
|
||||||
|
Otherwise, the Play Store might allow users on `x86` devices to install your app even though it is not
|
||||||
|
supported.
|
||||||
|
In Flutter's current native build system, drift unfortunately can't do that for you.
|
||||||
|
- `path_provider` and `path`: Used to find a suitable location to store the database. Maintained by the Flutter and Dart team.
|
||||||
|
- `drift_dev`: This development-only dependency generates query code based on your tables. It will not be included in your final app.
|
||||||
|
- `build_runner`: Common tool for code-generation, maintained by the Dart team.
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -1,14 +1,14 @@
|
||||||
# Short description for each builder
|
# Short description for each builder
|
||||||
|
|
||||||
# - preparing_builder: Infers the type of inline Dart expressions in moor files.
|
# - preparing_builder: Infers the type of inline Dart expressions in drift files.
|
||||||
# We create a `input.temp.dart` file containing the expressions so that they
|
# We create a `input.temp.dart` file containing the expressions so that they
|
||||||
# can be resolved.
|
# can be resolved.
|
||||||
# - moor_generator: The regular SharedPartBuilder for @UseMoor and @UseDao
|
# - drift_dev: The regular SharedPartBuilder for @DriftDatabase and @DriftAccessor
|
||||||
# annotations
|
# annotations
|
||||||
# - moor_generator_not_shared: Like moor_generator, but as a PartBuilder instead of
|
# - not_shared: Like drift_dev, but as a PartBuilder instead of
|
||||||
# a SharedPartBuilder. This builder is disabled by default, but users may choose
|
# a SharedPartBuilder. This builder is disabled by default, but users may choose
|
||||||
# to use it so that generated classes can be used by other builders.
|
# to use it so that generated classes can be used by other builders.
|
||||||
# - moor_cleanup: Deletes the `.temp.dart` files generated by the `preparing_builder`.
|
# - cleanup: Deletes the `.temp.dart` files generated by the `preparing_builder`.
|
||||||
|
|
||||||
builders:
|
builders:
|
||||||
preparing_builder:
|
preparing_builder:
|
||||||
|
|
Loading…
Reference in New Issue