Clarify join result types in docs

This commit is contained in:
Simon Binder 2024-04-21 14:51:03 +02:00
parent 9bcaeddb3b
commit aba434e7e0
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 5 additions and 6 deletions

View File

@ -9,6 +9,8 @@ import '../_shared/todo_tables.drift.dart';
class EntryWithCategory {
EntryWithCategory(this.entry, this.category);
// The classes are generated by drift for each of the tables involved in the
// join.
final TodoItem entry;
final Category? category;
}
@ -69,8 +71,6 @@ extension SelectExamples on CanUseCommonTables {
leftOuterJoin(categories, categories.id.equalsExp(todoItems.category)),
]);
// see next section on how to parse the result
// #enddocregion joinIntro
// #docregion results
return query.watch().map((rows) {
return rows.map((row) {
@ -81,7 +81,6 @@ extension SelectExamples on CanUseCommonTables {
}).toList();
});
// #enddocregion results
// #docregion joinIntro
}
// #enddocregion joinIntro

View File

@ -114,14 +114,14 @@ Of course, you can also join multiple tables:
{% include "blocks/snippet" snippets = snippets name = 'otherTodosInSameCategory' %}
## Parsing results
### Parsing results
Calling `get()` or `watch` on a select statement with join returns a `Future` or `Stream` of
`List<TypedResult>`, respectively. Each `TypedResult` represents a row from which data can be
read. It contains a `rawData` getter to obtain the raw columns. But more importantly, the
`readTable` method can be used to read a data class from a table.
In the example query above, we can read the todo entry and the category from each row like this:
In the example query above, we've read the todo entry and the category from each row like this:
{% include "blocks/snippet" snippets = snippets name = 'results' %}

View File

@ -140,7 +140,7 @@ abstract class _TransactionExecutor extends _BaseExecutor
if (_closed) {
throw StateError(
"A tranaction was used after being closed. Please check that you're "
"A transaction was used after being closed. Please check that you're "
'awaiting all database operations inside a `transaction` block.');
}
}