diff --git a/docs/pages/docs/Advanced Features/type_converters.md b/docs/pages/docs/Advanced Features/type_converters.md index ba71d93f..7a120ef0 100644 --- a/docs/pages/docs/Advanced Features/type_converters.md +++ b/docs/pages/docs/Advanced Features/type_converters.md @@ -62,7 +62,7 @@ class Tasks extends Table { > 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 `Status` to `running` (index = 1). - Now we `Status` enum to include another entry: + Now we modify `Status` enum to include another entry: ```dart enum Status { none, @@ -78,6 +78,40 @@ class Tasks extends Table { to fix this. {% 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()(); +} +``` + +{% 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. ## Using converters in drift {#using-converters-in-moor} diff --git a/docs/pages/docs/Getting started/advanced_dart_tables.md b/docs/pages/docs/Getting started/advanced_dart_tables.md index d61f42ea..89d6e0a7 100644 --- a/docs/pages/docs/Getting started/advanced_dart_tables.md +++ b/docs/pages/docs/Getting started/advanced_dart_tables.md @@ -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) | | `Uint8List` | `blob()` | `BLOB` | | `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 the database.