mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
Add the custom strategies
This commit is contained in:
1 parent
03a8e03a92
commit
5f23d97903
2 files changed
+10
No files matched your search
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user