marcoarment / Blackbird

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom column type does not pass schema validation

aaron-foreflight opened this issue · comments

I attempted to create a custom column type (UUID) and implemented BlackbirdColumnWrappable and BlackbirdStorableAsText as follows:

extension UUID: BlackbirdColumnWrappable, BlackbirdStorableAsText {
    public static func fromValue(_ value: Blackbird.Value) -> UUID? {
        guard case let Blackbird.Value.text(stringValue) = value else {
            return nil
        }
        return UUID(uuidString: stringValue)
    }

    public func unifiedRepresentation() -> String {
        self.uuidString
    }
    
    public static func from(unifiedRepresentation: String) -> UUID {
        return UUID(uuidString: unifiedRepresentation)!
    }
}

I also added an init(from:) decoder to my model as show in the comments of BlackbirdSchema.swift.

However, my model does not pass the schema validation because instead of using the BlackbirdDefaultsDecoder, which supplies a valid default for UUID, it uses the BlackbirdSQLiteDecoder which bypasses the if statement in my init(from:) to test for the BlackbirdDefaultsDecoder and provide a valid default.

Should the decoder at the following line be BlackbirdDefaultsDecoder to ensure the testRow has the right default for the column?
https://github.com/marcoarment/Blackbird/blob/2f15d7fae9f3821b43b7a945af38273fcb955157/Sources/Blackbird/BlackbirdModel.swift#L826C1-L835C10

Or am I just on the wrong path and this is not a feature Blackbird is supporting?