Use proper data class name in docs

This commit is contained in:
Simon Binder 2020-04-13 21:49:02 +02:00
parent aeb63e7faa
commit ddf916f53b
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
1 changed files with 7 additions and 7 deletions

View File

@ -27,7 +27,7 @@ class MyDatabase extends _$MyDatabase {
// watches all todo entries in a given category. The stream will automatically // watches all todo entries in a given category. The stream will automatically
// emit new items whenever the underlying data changes. // emit new items whenever the underlying data changes.
Stream<List<TodoEntry>> watchEntriesInCategory(Category c) { Stream<List<Todo>> watchEntriesInCategory(Category c) {
return (select(todos)..where((t) => t.category.equals(c.id))).watch(); return (select(todos)..where((t) => t.category.equals(c.id))).watch();
} }
} }
@ -51,7 +51,7 @@ the amount of rows to return and an optional offset.
You can use the `orderBy` method on the select statement. It expects a list of functions that extract the individual You can use the `orderBy` method on the select statement. It expects a list of functions that extract the individual
ordering terms from the table. ordering terms from the table.
```dart ```dart
Future<List<TodoEntry>> sortEntriesAlphabetically() { Future<List<Todo>> sortEntriesAlphabetically() {
return (select(todos)..orderBy([(t) => OrderingTerm(expression: t.title)])).get(); return (select(todos)..orderBy([(t) => OrderingTerm(expression: t.title)])).get();
} }
``` ```
@ -62,7 +62,7 @@ You can also reverse the order by setting the `mode` property of the `OrderingTe
If you know a query is never going to return more than one row, wrapping the result in a `List` If you know a query is never going to return more than one row, wrapping the result in a `List`
can be tedious. Moor lets you work around that with `getSingle` and `watchSingle`: can be tedious. Moor lets you work around that with `getSingle` and `watchSingle`:
```dart ```dart
Stream<TodoEntry> entryById(int id) { Stream<Todo> entryById(int id) {
return (select(todos)..where((t) => t.id.equals(id))).watchSingle(); return (select(todos)..where((t) => t.id.equals(id))).watchSingle();
} }
``` ```
@ -105,7 +105,7 @@ Future moveImportantTasksIntoCategory(Category target) {
); );
} }
Future update(TodoEntry entry) { Future update(Todo entry) {
// using replace will update all fields from the entry that are not marked as a primary key. // using replace will update all fields from the entry that are not marked as a primary key.
// it will also make sure that only the entry with the same primary key will be updated. // it will also make sure that only the entry with the same primary key will be updated.
// Here, this means that the row that has the same id as entry will be updated to reflect // Here, this means that the row that has the same id as entry will be updated to reflect
@ -124,7 +124,7 @@ the statement will affect all rows in the table!
{{% alert title="Entries, companions - why do we need all of this?" %}} {{% alert title="Entries, companions - why do we need all of this?" %}}
You might have noticed that we used a `TodosCompanion` for the first update instead of You might have noticed that we used a `TodosCompanion` for the first update instead of
just passing a `TodoEntry`. Moor generates the `TodoEntry` class (also called _data just passing a `Todo`. Moor generates the `Todo` class (also called _data
class_ for the table) to hold a __full__ row with all its data. For _partial_ data, class_ for the table) to hold a __full__ row with all its data. For _partial_ data,
prefer to use companions. In the example above, we only set the the `category` column, prefer to use companions. In the example above, we only set the the `category` column,
so we used a companion. so we used a companion.
@ -143,13 +143,13 @@ You can very easily insert any valid object into tables. As some values can be a
companion version. companion version.
```dart ```dart
// returns the generated id // returns the generated id
Future<int> addTodoEntry(TodosCompanion entry) { Future<int> addTodo(TodosCompanion entry) {
return into(todos).insert(entry); return into(todos).insert(entry);
} }
``` ```
All row classes generated will have a constructor that can be used to create objects: All row classes generated will have a constructor that can be used to create objects:
```dart ```dart
addTodoEntry( addTodo(
TodosCompanion( TodosCompanion(
title: Value('Important task'), title: Value('Important task'),
content: Value('Refactor persistence code'), content: Value('Refactor persistence code'),