Case
SQLRowDecoder.KeyDecodingStrategy.custom(_:)
CodingKeys used by the decoded model type.@preconcurrency case custom(@Sendable ([any CodingKey]) -> any CodingKey)
Parameters
closureA closure which performs a forward conversion of a
CodingKeyto the equivalent database column name.
Discussion
The full path to the current decoding position is provided for context (in case you need to locate this key within the payload). The returned key is used in place of the last component in the coding path before decoding.
If the result of the conversion is a duplicate key, then only one value will be present in the container for the type to decode from.
Note
The coding “path” will in reality always contain exactly one coding key. Users may consider this an API guarantee and safely write code which relies on this assumption.
Warning
The naming conventions used by SQLRowDecoder.KeyDecodingStrategy are misleading. In particular, although the SQLRowDecoder.KeyDecodingStrategy.convertFromSnakeCase strategy implies conversion to camel-cased keys from snake-cased originals, in reality any given CodingKey is subjected to the inverse transformation (as described by SQLQueryEncoder.KeyEncodingStrategy.convertToSnakeCase). Likewise, the closure provided to the SQLRowDecoder.KeyDecodingStrategy.custom(_:) strategy is expected to perform a forward translation, translating a Swift-side CodingKey into the database-side column name found in a given query result row. Users are encouraged to consider the use of SomeCodingKey for returning results.
It is also worth noting that this behavior is inconsistent with how a KeyDecodingStrategy specified on Foundation’s JSONDecoder works.