mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-26 04:07:50 +00:00
Merge pull request #1703 from groue/dev/inflections-fixes
Fix pluralization of Bias, Focus, Gas, and Lens
This commit is contained in:
3 files changed
+69
-4
No files matched your search
@@ -10,6 +10,7 @@ Migrating From GRDB 6 to GRDB 7
|
||||
- [Column Coding Strategies](#column-coding-strategies)
|
||||
- [Cancellable Async Database Accesses](#cancellable-async-database-accesses)
|
||||
- [Default Transaction Kind](#default-transaction-kind)
|
||||
- [Associations to record types named Bias, Focus, Gas, and Lens](#associations-to-record-types-named-bias-focus-gas-and-lens)
|
||||
- [ValueObservation and the Main Actor](#valueobservation-and-the-main-actor)
|
||||
- [Access to SQLite C functions](#access-to-sqlite-c-functions)
|
||||
- [The Record Base Class is Discouraged](#the-record-base-class-is-discouraged)
|
||||
@@ -96,6 +97,53 @@ try await task.value
|
||||
|
||||
Other asynchronous database accesses, such as methods accepting a completion blocks (`asyncRead`, etc.), Combine publishers, RxSwift observables, do not handle cancellation and will proceed to completion by default.
|
||||
|
||||
## Associations to record types named Bias, Focus, Gas, and Lens
|
||||
|
||||
GRDB 7 has fixed its singularization and pluralization rules for database tables named "bias", "focus", "gas", and "lens".
|
||||
|
||||
If your application uses associations to those tables, you can now rely on proper pluralization and singularization.
|
||||
|
||||
With GRDB 7, you can remove custom association keys:
|
||||
|
||||
```swift
|
||||
struct Camera: TableRecord {
|
||||
// GRDB 6: fix incorrect GRDB pluralization
|
||||
static let lenses = hasMany(Lens.self).forKey("lenses")
|
||||
// GRDB 7
|
||||
static let lenses = hasMany(Lens.self)
|
||||
}
|
||||
```
|
||||
|
||||
If your application was not defining custom association keys in order to fix the wrong pluralization, then it may define types that will no longer work:
|
||||
|
||||
```swift
|
||||
// Works in GRDB 6, breaks in GRDB 7
|
||||
struct CameraWithLenses: Decodable, FetchableRecord {
|
||||
var camera: Camera
|
||||
var lens: [Lens] // <- incorrect pluralization
|
||||
}
|
||||
let results = Camera
|
||||
.including(all: Camera.lenses)
|
||||
.asRequest(of: CameraWithLenses.self)
|
||||
.fetchAll(db)
|
||||
```
|
||||
|
||||
There are two possible solutions. One is to fix those types, the other is to keep on using the wrong pluralization (it's your call):
|
||||
|
||||
```swift
|
||||
// GRDB 7, alternative 1
|
||||
struct CameraWithLenses: Decodable, FetchableRecord {
|
||||
var camera: Camera
|
||||
var lenses: [Lens] // <- fixed pluralization
|
||||
}
|
||||
|
||||
// GRDB 7, alternative 2
|
||||
struct Camera: TableRecord {
|
||||
// Use "lens" instead of "lenses" for GRDB 6 compatibility.
|
||||
static let lenses = hasMany(Lens.self).forKey("lens")
|
||||
}
|
||||
```
|
||||
|
||||
## Default Transaction Kind
|
||||
|
||||
Some applications specify a default transaction kind, which was previously recommended in the [Sharing a Database] guide:
|
||||
|
||||
@@ -63,7 +63,7 @@ extension Inflections {
|
||||
inflections.plural("^(ax|test)is$", "$1es")
|
||||
inflections.plural("(octop|vir)us$", "$1i")
|
||||
inflections.plural("(octop|vir)i$", "$1i")
|
||||
inflections.plural("(alias|status)$", "$1es")
|
||||
inflections.plural("(alias|bias|canvas|focus|gas|lens|status)$", "$1es")
|
||||
inflections.plural("(bu)s$", "$1ses")
|
||||
inflections.plural("(buffal|tomat|her)o$", "$1oes")
|
||||
inflections.plural("([ti])um$", "$1a")
|
||||
@@ -102,13 +102,12 @@ extension Inflections {
|
||||
inflections.singular("(cris|test)(is|es)$", "$1is")
|
||||
inflections.singular("^(a)x[ie]s$", "$1xis")
|
||||
inflections.singular("(octop|vir)(us|i)$", "$1us")
|
||||
inflections.singular("(alias|status)(es)?$", "$1")
|
||||
inflections.singular("(alias|bias|canvas|focus|gas|lens|status)(es)?$", "$1")
|
||||
inflections.singular("^(ox)en$", "$1")
|
||||
inflections.singular("(vert|ind)ices$", "$1ex")
|
||||
inflections.singular("(matr)ices$", "$1ix")
|
||||
inflections.singular("(quiz)zes$", "$1")
|
||||
inflections.singular("(database)s$", "$1")
|
||||
inflections.singular("(canvas)(es)?$", "$1")
|
||||
|
||||
inflections.uncountableWords([
|
||||
"advice",
|
||||
|
||||
@@ -124,7 +124,25 @@
|
||||
"hero" : "heroes",
|
||||
"foot" : "feet",
|
||||
"matrix" : "matrices",
|
||||
"watch" : "watches"
|
||||
"watch" : "watches",
|
||||
"lens" : "lenses",
|
||||
"focus" : "focuses",
|
||||
"class" : "classes",
|
||||
"glass" : "glasses",
|
||||
"brush" : "brushes",
|
||||
"match" : "matches",
|
||||
"address" : "addresses",
|
||||
"bias" : "biases",
|
||||
"compass" : "compasses",
|
||||
"crisis" : "crises",
|
||||
"dress" : "dresses",
|
||||
"gas" : "gases",
|
||||
"guess" : "guesses",
|
||||
"kiss" : "kisses",
|
||||
"loss" : "losses",
|
||||
"pass" : "passes",
|
||||
"success" : "successes",
|
||||
"witness" : "witnesses"
|
||||
},
|
||||
|
||||
"Irregularities": {
|
||||
|
||||
Reference in new issue
Block a user