📝 Update the documentation

This commit is contained in:
ValentinVignal 2022-11-28 19:06:38 +08:00
parent d7ef374677
commit 3f0e40b8a7
No known key found for this signature in database
GPG Key ID: 040FFDADFB7EF05A
2 changed files with 36 additions and 1 deletions

View File

@ -62,7 +62,7 @@ class Tasks extends Table {
> It can be easy to accidentally invalidate your database by introducing another enum value. > It can be easy to accidentally invalidate your database by introducing another enum value.
For instance, let's say we inserted a `Task` into the database in the above example and set its For instance, let's say we inserted a `Task` into the database in the above example and set its
`Status` to `running` (index = 1). `Status` to `running` (index = 1).
Now we `Status` enum to include another entry: Now we modify `Status` enum to include another entry:
```dart ```dart
enum Status { enum Status {
none, none,
@ -78,6 +78,40 @@ class Tasks extends Table {
to fix this. to fix this.
{% endblock %} {% endblock %}
If you prefer to store the enum as a text, you can use `textEnum` instead.
```dart
enum Status {
none,
running,
stopped,
paused
}
class Tasks extends Table {
IntColumn get id => integer().autoIncrement()();
TextColumn get status => textEnum<Status>()();
}
```
{% block "blocks/alert" title="Caution with enums" color="warning" %}
> It can be easy to accidentally invalidate your database by renaming your enum values.
For instance, let's say we inserted a `Task` into the database in the above example and set its
`Status` to `running`.
Now we modify `Status` enum to rename `running` into `processing`:
```dart
enum Status {
none,
processing,
stopped,
paused
}
```
When selecting the task, it won't be able to find the enum value `running` anymore, and will throw an error.
For this reason, it's best to not modify the name of your enum values. Otherwise you'd need to bump your schema version and run a custom update statement to fix this.
{% endblock %}
Also note that you can't apply another type converter on a column declared with an enum converter. Also note that you can't apply another type converter on a column declared with an enum converter.
## Using converters in drift {#using-converters-in-moor} ## Using converters in drift {#using-converters-in-moor}

View File

@ -175,6 +175,7 @@ Drift supports a variety of column types out of the box. You can store custom cl
| `DateTime` | `dateTime()` | `INTEGER` (default) or `TEXT` depending on [options](#datetime-options) | | `DateTime` | `dateTime()` | `INTEGER` (default) or `TEXT` depending on [options](#datetime-options) |
| `Uint8List` | `blob()` | `BLOB` | | `Uint8List` | `blob()` | `BLOB` |
| `Enum` | `intEnum()` | `INTEGER` (more information available [here]({{ "../Advanced Features/type_converters.md#implicit-enum-converters" | pageUrl }})). | | `Enum` | `intEnum()` | `INTEGER` (more information available [here]({{ "../Advanced Features/type_converters.md#implicit-enum-converters" | pageUrl }})). |
| `Enum` | `textEnum()` | `TEXT` (more information available [here]({{ "../Advanced Features/type_converters.md#implicit-enum-converters" | pageUrl }})). |
Note that the mapping for `boolean`, `dateTime` and type converters only applies when storing records in Note that the mapping for `boolean`, `dateTime` and type converters only applies when storing records in
the database. the database.