https://github.com/apple/swift-evolution/blob/main/proposals/0310-effectful-readonly-properties.md
2.3 KiB
Migrating From GRDB 5 to GRDB 6
This guide aims at helping you upgrading your applications from GRDB 5 to GRDB 6.
Preparing the Migration to GRDB 6
If you haven't made it yet, upgrade to the latest GRDB 5 release first, and fix any deprecation warning prior to the GRDB 6 upgrade.
You can then upgrade to GRDB 6. Due to the breaking changes, it is possible that your application code no longer compiles. Follow the fix-its that suggest simple syntactic changes. Other modifications that you need to apply are described below.
New requirements
GRDB requirements have been bumped:
- Swift 5.7+ (was Swift 5.3+)
- Xcode 14.0+ (was Xcode 12.0+)
- iOS 11.0+ (unchanged)
- macOS 10.13+ (was macOS 10.10+)
- tvOS 11.0+ (was tvOS 11.0+)
- watchOS 4.0+ (was watchOS 2.0+)
Primary Associated Types
Request protocols now come with a primary associated type, enabled by SE-0346. This is a great opportunity to simplify your extensions:
-extension DerivableRequest where RowDecoder == Book {
+extension DerivableRequest<Book> {
/// Order books by title, in a localized case-insensitive fashion
func orderByTitle() -> Self {
order(Column("title").collating(.localizedCaseInsensitiveCompare))
}
}
The Cursor protocol has also gained a primary associated type (the type of its elements).
Other Changes
-
The initializer of in-memory databases can now throw errors:
-let dbQueue = DatabaseQueue() +let dbQueue = try DatabaseQueue() -
The
selectID()method is removed. You can provide your own implementation, based on the newselectPrimaryKey(as:)method:extension QueryInterfaceRequest<Player> { func selectID() -> QueryInterfaceRequest<Int64> { selectPrimaryKey() } } -
Cursor.isEmptyis now a throwing property, instead of a method:-if try cursor.isEmpty() { ... } +if try cursor.isEmpty { ... }