Document where type converters aren' applied

This commit is contained in:
Simon Binder 2023-12-27 18:34:27 +01:00
parent 615a1d7ad8
commit 910b284e08
1 changed files with 15 additions and 0 deletions

View File

@ -177,3 +177,18 @@ your type converter.
As an alternative to using JSON type converters, you can use a custom [`ValueSerializer`](https://drift.simonbinder.eu/api/drift/valueserializer-class)
and pass it to the serialization methods.
## Type converters and SQL
In database rows, columns to which a type converter has been applied are storing the result of
`toSql()`. Drift will apply the type converter automatically when reading or writing rows, but they
are not applied automatically when creating your own [expressions]({{'Dart API/expressions.md' | pageUrl }}).
For example, filtering for values with [`column.equals`](https://drift.simonbinder.eu/api/drift/expression/equals)
will compare not apply the type converter, you'd be comparing the underlying database values.
On columns with type converters, [`equalsValue`](https://drift.simonbinder.eu/api/drift/generatedcolumnwithtypeconverter/equalsvalue)
can be used instead - unlike `equals`, `equasValue` will apply the converter before emtting a comparison in SQL.
If you need to apply the converter for other comparisons as well, you can do that manually with `column.converter.toSql`.
For variables used in queries that are part of a [drift file]({{'SQL API/drift_files.md'| pageUrl}}), type converters will be
applied by default if the `apply_converters_on_variables` [builder option]({{'Generation options/index.md'|pageUrl}}) is enabled (which it is by default).