Add the custom strategies

This commit is contained in:
Gwendal Roué committed 2021-08-28 15:50:34 +02:00
1 parent 03a8e03a92
commit 5f23d97903
2 files changed
+10

No files matched your search

+5
View File
@@ -420,12 +420,17 @@ public enum DatabaseKeyEncodingStrategy {
/// A key encoding strategy that converts camel-case keys to snake-case keys.
case convertToSnakeCase
/// A key encoding strategy defined by the closure you supply.
case custom((CodingKey) -> String)
func column(forKey key: CodingKey) -> String {
switch self {
case .useDefaultKeys:
return key.stringValue
case .convertToSnakeCase:
return Self.convertToSnakeCase(key.stringValue)
case let .custom(column):
return column(key)
}
}
+5
View File
@@ -654,12 +654,17 @@ public enum DatabaseKeyDecodingStrategy {
/// A key decoding strategy that converts snake-case keys to camel-case keys.
case convertFromSnakeCase
/// A key decoding strategy defined by the closure you supply.
case custom((CodingKey) -> String)
func column(forKey key: CodingKey) -> String {
switch self {
case .useDefaultKeys:
return key.stringValue
case .convertFromSnakeCase:
return Self.convertFromSnakeCase(key.stringValue)
case let .custom(column):
return column(key)
}
}