Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom column type does not pass schema validation #20

Open
aaron-foreflight opened this issue Aug 18, 2023 · 1 comment
Open

Custom column type does not pass schema validation #20

aaron-foreflight opened this issue Aug 18, 2023 · 1 comment

Comments

@aaron-foreflight
Copy link

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?

@daniel-beard
Copy link

Having the same issue, I'm attempting to store a Decimal as a custom column type (either blob or text would work for my purposes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants