Clarify supported view columns

This commit is contained in:
Simon Binder 2022-05-23 21:38:23 +02:00
parent b8b372f7c7
commit a4dc3a3305
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
1 changed files with 10 additions and 3 deletions

View File

@ -294,9 +294,16 @@ abstract class CategoryTodoCount extends View {
Inside a Dart view, use
- abstract getters to declare tables that you'll read from (e.g. `TodosTable get todos`)
- `Expression` getters to add columns: (e.g. `itemCount => todos.id.count()`);
- the overridden `as` method to define the select statement backing the view
- abstract getters to declare tables that you'll read from (e.g. `TodosTable get todos`).
- `Expression` getters to add columns: (e.g. `itemCount => todos.id.count()`).
- the overridden `as` method to define the select statement backing the view.
The columns referenced in `select` may refer to two kinds of columns:
- Columns defined on the view itself (like `itemCount` in the example above).
- Columns defined on referenced tables (like `categories.description` in the example).
For these references, advanced drift features like [type converters]({{ '../Advanced Features/type_converters.md' | pageUrl }})
used in the column's definition from the table are also applied to the view's column.
Both kind of columns will be added to the data class for the view when selected.
Finally, a view needs to be added to a database or accessor by including it in the
`views` parameter: