Mention readRowOrNull in docs and exception

This commit is contained in:
Simon Binder 2021-01-18 19:19:39 +01:00
parent a375caaa44
commit 4ffe29fe17
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 8 additions and 5 deletions

View File

@ -34,8 +34,9 @@ Stream<List<EntryWithCategory>> entriesWithCategory() {
```
## 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
`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.
@ -45,14 +46,15 @@ return query.watch().map((rows) {
return rows.map((row) {
return EntryWithCategory(
row.readTable(todos),
row.readTable(categories),
row.readTableOrNull(categories),
);
}).toList();
});
```
_Note_: `readTable` returns `null` when an entity is not present in the row. For instance, todo entries
might not be in any category.For a row without a category, `row.readTable(categories)` would return `null`.
_Note_: `readTable` will throw an `ArgumentError` when a table is not present in the row. For instance,
todo entries might not be in any category. To account for that, we use `row.readTableOrNull` to load
categories.
## Custom columns

View File

@ -143,7 +143,8 @@ class TypedResult {
if (!_parsedData.containsKey(table)) {
throw ArgumentError(
'Invalid table passed to readTable: ${table.tableName}. This row '
'does not contain values for that table.');
'does not contain values for that table. \n'
'In moor version 4, you have to use readTableNull for outer joins.');
}
return _parsedData[table] as D;