diff --git a/Documentation/GoodPracticesForDesigningRecordTypes.md b/Documentation/GoodPracticesForDesigningRecordTypes.md index ced735354..5991b5521 100644 --- a/Documentation/GoodPracticesForDesigningRecordTypes.md +++ b/Documentation/GoodPracticesForDesigningRecordTypes.md @@ -683,6 +683,8 @@ Instead, have a look at [Database Observation]: > > :bulb: **Tip**: [FetchedRecordsController] performs automated tracking of database changes, and can animate the cells of a table or collection view. > +> :bulb: **Tip**: [GRDBCombine] performs automated tracking of database changes, in the [Combine](https://developer.apple.com/documentation/combine) way. +> > :bulb: **Tip**: [RxGRDB] performs automated tracking of database changes, in the [RxSwift](https://github.com/ReactiveX/RxSwift) way. > > :bulb: **Tip**: [TransactionObserver] provides low-level database observation, for your most advanced needs. @@ -713,6 +715,7 @@ Instead, have a look at [Database Observation]: [ValueObservation]: ../README.md#valueobservation [FetchedRecordsController]: ../README.md#fetchedrecordscontroller [RxGRDB]: http://github.com/RxSwiftCommunity/RxGRDB +[GRDBCombine]: http://github.com/groue/GRDBCombine [TransactionObserver]: ../README.md#transactionobserver-protocol [Trust SQLite More Than Yourself]: #trust-sqlite-more-than-yourself [Persistable Record Types are Responsible for Their Tables]: #persistable-record-types-are-responsible-for-their-tables diff --git a/Documentation/WhyAdoptGRDB.md b/Documentation/WhyAdoptGRDB.md index 01d48762a..e23b5213a 100644 --- a/Documentation/WhyAdoptGRDB.md +++ b/Documentation/WhyAdoptGRDB.md @@ -117,7 +117,7 @@ let players = try Player.fetchAll(db) **Fetched records behave just like an in-memory cache of the database content.** Your application is free to decide, on its own, how it should handle the lifetime of those cached values: by ignoring future database changes, by observing database changes and react accordingly, or in any way deemed relevant. -There are several ways to be notified of database changes. You can build on top of the fundamental but low-level [TransactionObserver] protocol. Usually, you'll use [ValueObservation], which notifies fresh values after each database change, or [FetchedRecordsController], which animates table and collection views. And don't forget [RxGRDB], a set of reactive extensions based on [RxSwift]: +There are several ways to be notified of database changes. You can build on top of the fundamental but low-level [TransactionObserver] protocol. Usually, you'll use [ValueObservation], which notifies fresh values after each database change, or [FetchedRecordsController], which animates table and collection views. And don't forget [GRDBCombine] and [RxGRDB], two sets of reactive extensions based on [Combine] and [RxSwift]: ```swift Player.all().rx @@ -238,9 +238,10 @@ extension Player { let player = try Player.filter(name: "Arthur O'Brien").fetchOne(db) ``` -Custom SQL requests as the one above are welcome in database observation tools like [ValueObservation] and [RxGRDB]: +Custom SQL requests as the one above are welcome in database observation tools like [ValueObservation], [GRDBCombine] and [RxGRDB]: ```swift +// RxSwift Player.filter(name: "Arthur O'Brien").rx .fetchOne(in: dbQueue) .subscribe(onNext: { (player: Player?) in @@ -301,6 +302,8 @@ Happy GRDB! :gift: [FetchableRecord]: ../README.md#records [RxGRDB]: https://github.com/RxSwiftCommunity/RxGRDB [RxSwift]: https://github.com/ReactiveX/RxSwift +[GRDBCombine]: http://github.com/groue/GRDBCombine +[Combine]: https://developer.apple.com/documentation/combine [SQLite.swift]: http://github.com/stephencelis/SQLite.swift [StORM]: https://www.perfect.org/docs/StORM.html [Swift-Kuery]: http://github.com/IBM-Swift/Swift-Kuery diff --git a/README.md b/README.md index c45d1770e..320138467 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ GRDB ships with: Companion libraries that enhance and extend GRDB: +- [GRDBCombine]: track database changes in a reactive way, with [Combine](https://developer.apple.com/documentation/combine). - [RxGRDB]: track database changes in a reactive way, with [RxSwift](https://github.com/ReactiveX/RxSwift). - [GRDBObjc](https://github.com/groue/GRDBObjc): FMDB-compatible bindings to GRDB. @@ -6041,6 +6042,7 @@ GRDB puts this SQLite feature to some good use, and lets you observe the databas - [ValueObservation and DatabaseRegionObservation]: Automated tracking of database requests. - [FetchedRecordsController]: Animate table views according to database changes. - [TransactionObserver Protocol](#transactionobserver-protocol): Low-level database observation. +- [GRDBCombine]: Automated tracking of database changes, with [Combine](https://developer.apple.com/documentation/combine). - [RxGRDB]: Automated tracking of database changes, with [RxSwift](https://github.com/ReactiveX/RxSwift). Database observation requires that a single [database queue](#database-queues) or [pool](#database-pools) is kept open for all the duration of the database usage. @@ -6545,7 +6547,7 @@ You can combine up to eight observations together. They can feed from as many da Combining observations provides the guarantee that notified values are [**consistent**](https://en.wikipedia.org/wiki/Consistency_(database_systems)). -> :point_up: **Note**: readers who are familiar with Reactive Programming will recognize the [CombineLatest](http://reactivex.io/documentation/operators/combinelatest.html) operator in the ValueObservation `combine` method. The reactive operator does not care about data consistency, though: if you use a Reactive layer such as [RxGRDB] or [Combine], make sure you compose observations with `ValueObservation.combine`, not with the CombineLatest operator. +> :point_up: **Note**: readers who are familiar with Reactive Programming will recognize the [CombineLatest](http://reactivex.io/documentation/operators/combinelatest.html) operator in the ValueObservation `combine` method. The reactive operator does not care about data consistency, though: if you use a Reactive layer such as [GRDBCombine] or [RxGRDB], make sure you compose observations with `ValueObservation.combine`, not with the CombineLatest operator. ### ValueObservation Error Handling @@ -6800,7 +6802,7 @@ It looks and behaves very much like [Core Data's NSFetchedResultsController](htt Given a fetch request, and a type that adopts the [FetchableRecord] protocol, such as a subclass of the [Record](#record-class) class, a FetchedRecordsController is able to track changes in the results of the fetch request, notify of those changes, and return the results of the request in a form that is suitable for a table view or a collection view, with one cell per fetched record. -> :point_up: **Note**: when you don't need to animate a table or a collection view, use [ValueObservation] or [RxGRDB] instead. +> :point_up: **Note**: when you don't need to animate a table or a collection view, use [ValueObservation], [GRDBCombine], or [RxGRDB] instead. > > :bulb: **Tip**: see the [Demo Application](DemoApps/GRDBDemoiOS/README.md) for a sample app that uses FetchedRecordsController. @@ -7256,7 +7258,7 @@ do { > :point_up: **Note**: the databaseDidChange(with:) and databaseWillCommit() callbacks must not touch the SQLite database. This limitation does not apply to databaseDidCommit and databaseDidRollback which can use their database argument. -[DatabaseRegionObservation], [ValueObservation], [FetchedRecordsController], and [RxGRDB] are based on the TransactionObserver protocol. +[DatabaseRegionObservation], [ValueObservation], [FetchedRecordsController], [GRDBCombine], and [RxGRDB] are all based on the TransactionObserver protocol. See also [TableChangeObserver.swift](https://gist.github.com/groue/2e21172719e634657dfd), which shows a transaction observer that notifies of modified database tables with NSNotificationCenter. @@ -8263,6 +8265,7 @@ These protocols provide a unified API that let you write generic code that targe - [DatabaseRegionObservation] - [ValueObservation] - [FetchedRecordsController] +- [GRDBCombine] - [RxGRDB] Only five types adopt those protocols: DatabaseQueue, DatabasePool, DatabaseSnapshot, AnyDatabaseReader, and AnyDatabaseWriter. Expanding this set is not supported: any future GRDB release may break your custom writers and readers, without notice. @@ -8856,6 +8859,7 @@ This chapter has been renamed [Beyond FetchableRecord]. [DatabaseRegionObservation]: #databaseregionobservation [FetchedRecordsController]: #fetchedrecordscontroller [RxGRDB]: http://github.com/RxSwiftCommunity/RxGRDB +[GRDBCombine]: http://github.com/groue/GRDBCombine [DatabaseRegionConvertible]: #the-databaseregionconvertible-protocol [ValueObservation and DatabaseRegionObservation]: #valueobservation-and-databaseregionobservation [DatabaseRegion]: #databaseregion