sqlite-simple
sqlite-simple copied to clipboard
Add `FromField` instance for `UUID`
trafficstars
postgresql-simple contains such instance. It would be really helpful to have it here as well.
@vrom911 thanks for reporting. I'll take a look into it.
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.
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...