From 2b6e69404ef0429ddb960daa244ee993d8d2efea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 16 Sep 2018 12:09:47 +0200 Subject: [PATCH] FetchedRecordsController in usage section --- README.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f15ed53b4..3d893efda 100644 --- a/README.md +++ b/README.md @@ -219,20 +219,21 @@ See the [Query Interface](#the-query-interface) Be notified of database changes ```swift -// Track query interface requests -Place.filter(key: 1) - .rx - .fetchOne(in: dbQueue) - .subscribe(onNext: { place: Place? in - print("Place 1 has changed") - }) +let request = Place.order(Column("title")) -// Track SQL requests -SQLRequest("SELECT * FROM place WHERE favorite ORDER BY title") - .rx +// Track request changes with FetchedRecordsController +let controller = FetchedRecordsController(dbQueue, request: request) +controller.trackChanges { controller in + print("Places have changed.") + let places = controller.fetchedRecords // [Place] +} +try controller.performFetch() + +// Track request changes with RxSwift and RxGRDB +request.rx .fetchAll(in: dbQueue) .subscribe(onNext: { places: [Place] in - print("Favorite places have changed") + print("Places have changed.") }) ```