From 6d71f8b17c2768a26e9166b563e515b4d7c36031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 25 May 2019 18:01:35 +0200 Subject: [PATCH] Relationship between view controllers and database managers --- Documentation/GoodPracticesForDesigningRecordTypes.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Documentation/GoodPracticesForDesigningRecordTypes.md b/Documentation/GoodPracticesForDesigningRecordTypes.md index 85fdaeaa9..e3b1fc7ff 100644 --- a/Documentation/GoodPracticesForDesigningRecordTypes.md +++ b/Documentation/GoodPracticesForDesigningRecordTypes.md @@ -557,7 +557,7 @@ class LibraryManager { // Feeds the list of authors extension LibraryManager { - struct AuthorListItem: Decodable, FetchableRecord{ + struct AuthorListItem: Decodable, FetchableRecord { let author: Author let bookCount: Int } @@ -611,6 +611,14 @@ extension LibraryManager { } ``` +The `AuthorListItem`, `BookInfo`, `AuthorInfo` types returned by the manager are designed to feed your view controllers. + +When a new screen is added to your application, and you want to make sure it displays **consistent data** free from any data race, make sure you update the manager if needed. The rule is very simple: consumed data must come from a **single database access** (`dbQueue.read`, `write`, etc.) + +This may sound unusual. Aren't view controllers (or view models, or presenters, depending on your application architecture) supposed to freely pick and compose the pieces of data they need from a general-purpose database manager which stands passively in front of the database? + +Well, not quite with GRDB. It is an unmanaged ORM, so some amount of management must be imported in your application. There is no free lunch! + > :question: **Note**: Wrapping several fetches in a single `read` method may look like an inconvenience to you. After all, other ORMs don't require that much ceremony: > > ```ruby