mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
Update documentation
This commit is contained in:
1 parent
e2790c863f
commit
bfe037c61d
2 files changed
+34
-46
No files matched your search
@@ -177,9 +177,41 @@ Those changes have been applied identically to [GRDBCombine] and [RxGRDB], so th
|
||||
|
||||
3. Some value observations used to automatically remove duplicate values. This is no longer automatic. If your application relies on distinct consecutive values, use the [removeDuplicates] operator.
|
||||
|
||||
4. ValueObservation used to have a `compactMap` method. This method has been removed without any replacement.
|
||||
**ValueObservation features have been removed**.
|
||||
|
||||
5. ValueObservation used to let application define custom "reducers" using the ValueReducer protocol. These apis are no longer available. See the [#731](https://github.com/groue/GRDB.swift/pull/731) conversation for a solution towards a replacement.
|
||||
1. ValueObservation used to have a `compactMap` method. This method has been removed without any replacement.
|
||||
|
||||
If your application uses GRDBCombine or RxGRDB, then use the `compactMap` method from Combine or RxSwift instead.
|
||||
|
||||
2. ValueObservation used to have a `combine` method. This method has been removed without any replacement.
|
||||
|
||||
In your application, replace combined observations with a single observation:
|
||||
|
||||
```swift
|
||||
// BEFORE: GRDB 4
|
||||
let playerCountObservation = ValueObservation.tracking(Player.fetchCount)
|
||||
let bestPlayersObservation = ValueObservation.tracking(Player
|
||||
.limit(10)
|
||||
.order(Column("score").desc)
|
||||
.fetchAll)
|
||||
let observation = ValueObservation
|
||||
.combine(playerCountObservation, bestPlayersObservation)
|
||||
.map(HallOfFame.init)
|
||||
|
||||
// NEW: GRDB 5
|
||||
let observation = ValueObservation.tracking { db -> HallOfFame in
|
||||
let playerCount = try Player.fetchCount(db)
|
||||
let bestPlayers = try Player
|
||||
.limit(10)
|
||||
.order(Column("score").desc)
|
||||
.fetchAll(db)
|
||||
return HallOfFame(playerCount: playerCount, bestPlayers: bestPlayers)
|
||||
}
|
||||
```
|
||||
|
||||
As is previous versions of GRDB, do not use the `combineLatest` operators of Combine or RxSwift in order to combine several ValueObservation. You would lose all guarantees of [data consistency](https://en.wikipedia.org/wiki/Consistency_(database_systems)).
|
||||
|
||||
3. ValueObservation used to let application define custom "reducers" using the ValueReducer protocol. These apis are no longer available. See the [#731](https://github.com/groue/GRDB.swift/pull/731) conversation for a solution towards a replacement.
|
||||
|
||||
|
||||
## Other Changes
|
||||
|
||||
@@ -5711,7 +5711,6 @@ let cancellable = observation.start(
|
||||
|
||||
- [ValueObservation.map](#valueobservationmap)
|
||||
- [ValueObservation.removeDuplicates](#valueobservationremoveduplicates)
|
||||
- [ValueObservation.combine](#valueobservationcombine)
|
||||
- [ValueObservation.requiresWriteAccess](#valueobservationrequireswriteaccess)
|
||||
|
||||
|
||||
@@ -5772,49 +5771,6 @@ let observation = ValueObservation
|
||||
```
|
||||
|
||||
|
||||
#### ValueObservation.combine
|
||||
|
||||
The `ValueObservation.combine` static method builds a single observation from several (up to eight):
|
||||
|
||||
```swift
|
||||
// An observation of Int
|
||||
let playerCountObservation = ValueObservation.tracking { db in
|
||||
try Player.fetchCount(db)
|
||||
}
|
||||
// An observation of [Player]
|
||||
let bestPlayersObservation = ValueObservation.tracking { db in
|
||||
try Player
|
||||
.limit(10)
|
||||
.order(Column("score").desc)
|
||||
.fetchAll(db)
|
||||
}
|
||||
|
||||
// The combined observation of (Int, [Player])
|
||||
let observation = ValueObservation.combine(
|
||||
playerCountObservation,
|
||||
bestPlayersObservation)
|
||||
```
|
||||
|
||||
Combining observations together provides the guarantee that notified values are [**consistent**](https://en.wikipedia.org/wiki/Consistency_(database_systems)).
|
||||
|
||||
`combine` also exists as an instance method:
|
||||
|
||||
```swift
|
||||
struct HallOfFame {
|
||||
var totalPlayerCount: Int
|
||||
var bestPlayers: [Player]
|
||||
}
|
||||
|
||||
// An observation of HallOfFame
|
||||
let observation = playerCountObservation.combine(bestPlayersObservation) {
|
||||
HallOfFame(totalPlayerCount: $0, bestPlayers: $1)
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
> :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. This is partially exact, because the reactive operator is unable to guarantee data consistency. If you use a Reactive layer such as [GRDBCombine] or [RxGRDB], make sure you compose observations with `ValueObservation.combine`, and never with the CombineLatest operator.
|
||||
|
||||
|
||||
#### ValueObservation.requiresWriteAccess
|
||||
|
||||
The `requiresWriteAccess` property is false by default. When true, a ValueObservation has a write access to the database, and its fetches are automatically wrapped in a [savepoint](#transactions-and-savepoints):
|
||||
|
||||
Reference in new issue
Block a user