Have Record implement Decodable by default #1146
oddanderson
started this conversation in
Ideas
Replies: 1 comment
-
It is not possible to have class Record: Decodable { }
// Compiler error: 'required' initializer 'init(from:)' must be provided by subclass of 'Record'
class MyRecord: Record {
var id: Int64
init(id: Int64) {
self.id = id
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In the guide for querying using Joins, the guide relies heavily on structs in favor of objects. When it comes to the filter/querying guide, this makes the examples really simple because struct implements decodable already, assuming you only have a limited set of property types.
However, if one of your object types in a struct is a Record, you need to implement Decodable's
init(from: decoder)
in both the struct AND the record object, such that I end up with:As I was doing so, it seemed like I was writing a fair amount of duplicate code relative to the other functions I need to implement for Record, specifically
enum Columns: String, ColumnExpression
,required init(row: Row)
, andoverride func encode(to container: inout PersistenceContainer)
Curious if it makes sense to use those definitions to enable Record to implement Decodable for free
Beta Was this translation helpful? Give feedback.
All reactions