sqlite-simple icon indicating copy to clipboard operation
sqlite-simple copied to clipboard

Add `FromField` instance for `UUID`

Open vrom911 opened this issue 7 years ago • 3 comments
trafficstars

postgresql-simple contains such instance. It would be really helpful to have it here as well.

vrom911 avatar May 16 '18 09:05 vrom911

@vrom911 thanks for reporting. I'll take a look into it.

sigrlami avatar Jan 17 '19 16:01 sigrlami

Postgres supports UUIDs as a native type, so there is a canonical encoding. SQLite doesn't, so we'd have to decide whether to encode them via the text representation of more compactly as binary blobs. Neither way is going to be best for all use cases.

kmicklas avatar Nov 11 '20 21:11 kmicklas

I've been using this locally, and I can make it a "pivot" package with only instances, if there's interest:

instance FromField UUID where
    fromField f@(Field (SQLText txt) _) = case fromText txt of
        Just r  -> Ok r
        Nothing -> returnError ConversionFailed f "need a uuid"
    fromField f = returnError ConversionFailed f "need a uuid"

instance ToField UUID where
    toField = SQLText . toText

Or I can pluck the code from #89...

danwdart avatar Oct 10 '22 11:10 danwdart