Migrating From GRDB 3 to GRDB 4

This commit is contained in:
Gwendal Roué committed 2019-04-24 13:28:54 +02:00
1 parent bdbcf682c4
commit 8084e83760
2 files changed
+83 -2

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
Migrating From GRDB 3 to GRDB 4
===============================
GRDB 4 comes with new features, but also a few breaking changes. This guide aims at helping you upgrading your applications.
### New requirements
GRDB now requires Swift 4.2+ and Xcode 10+. Swift 4.0 and 4.1 are no longer supported. Xcode 9 is no longer supported.
iOS 8 is no longer supported. The minimum iOS target is now iOS 9.
### Raw SQL
Whenever your application uses raw SQL queries or snippets, you will now always have to use the `sql` argument label:
```swift
// GRDB 3
try db.execute("INSERT INTO player (name) VALUES (?)", arguments: ["Arthur"])
let playerCount = try Int.fetchOne(db, "SELECT COUNT(*) FROM player")
// GRDB 4
try db.execute(sql: "INSERT INTO player (name) VALUES (?)", arguments: ["Arthur"])
let playerCount = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM player")
```
This change was made necessary by the introduction of [SQL Interpolation]
### ValueObservation
[ValueObservation] had a lifting in GRDB 4.
To guarantee asynchronous notifications, and never ever block your main thread, use the `.async(onQueue:startImmediately:)` scheduling:
```swift
// On main queue
var observation = ValueObservation.trackingAll(Player.all())
observation.scheduling = .async(onQueue: .main, startImmediately: true)
let observer = try observation.start(in: dbQueue) { (players: [Player]) in
// On main queue
print("fresh players: \(players)")s
}
// <- here "fresh players" is not printed yet.
```
In GRDB 3, this scheduling used to be named `.queue(_: startImmediately:)`.
The second breaking change is `ValueObservation.extent`, which was removed in GRDB 4. Now all observations last until the observer returned by the `start` method is deallocated.
### SQLCipher
- GRDBCipher discontinued
- #497 replaced with #508
### PersistenceError.recordNotFound
PersistenceError.recordNotFound is thrown whenever a record update method does not find any database row to update. It was refactored in GRDB 4:
```swift
public enum PersistenceError: Error {
case recordNotFound(databaseTableName: String, key: [String: DatabaseValue])
}
do {
try player.updateChanges {
$0.score += 1000
}
} catch let error as PersistenceError.recordNotFound {
// Update failed because player does not exist in the database
print(error)
// prints "Key not found in table player: [id:42]"
}
```
[SQL Interpolation]: SQLInterpolation.md
[ValueObservation]: ../README.md#valueobservation
+2 -2
View File
@@ -5,7 +5,7 @@ GRDB 4 [![Swift](https://img.shields.io/badge/swift-4.2-orange.svg?style=flat)](
---
:construction: GRDB 4 is currently under development in the [GRDB-4.0](https://github.com/groue/GRDB.swift/tree/GRDB-4.0) branch. [Release notes](https://github.com/groue/GRDB.swift/blob/GRDB-4.0/CHANGELOG.md#grdb-40-branch).
:construction: GRDB 4 is currently under development in the [GRDB-4.0](https://github.com/groue/GRDB.swift/tree/GRDB-4.0) branch. [Backlog](https://github.com/groue/GRDB.swift/pull/479) • [Release notes](https://github.com/groue/GRDB.swift/blob/GRDB-4.0/CHANGELOG.md#grdb-40-branch) • [Migrating From GRDB 3 to GRDB 4](Documentation/GRDB3MigrationGuide.md)
GRDB 4 will not be following semantic versioning during the development process. There may be breaking changes until 4.0.0 is released. There is not ETA (estimated time of arrival) for version 4.0.0. Your [help and support](https://github.com/groue/GRDB.swift/blob/master/CONTRIBUTING.md) are welcome.
@@ -14,7 +14,7 @@ The latest stable release [GRDB 3.7.0](https://github.com/groue/GRDB.swift/tree/
---
<!--
**Latest release**: March 9, 2019 • version 3.7.0 • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 2 to GRDB 3](Documentation/GRDB2MigrationGuide.md)
**Latest release**: March 9, 2019 • version 3.7.0 • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 4 to GRDB 4](Documentation/GRDB3MigrationGuide.md)
-->
**Requirements**: iOS 9.0+ / macOS 10.9+ / watchOS 2.0+ &bull; Swift 4.2+ / Xcode 10.0+