{-# OPTIONS_GHC -fno-warn-orphans #-} module Data.UUID.Orphans.Sqlite () where import Data.UUID (UUID) import Data.UUID qualified as UUID import Database.SQLite.Simple.FromField qualified as Sqlite import Database.SQLite.Simple.ToField qualified as Sqlite instance Sqlite.FromField UUID where fromField :: FieldParser UUID fromField Field field = do Text text <- FieldParser Text forall a. FromField a => FieldParser a Sqlite.fromField Field field case Text -> Maybe UUID UUID.fromText Text text of Maybe UUID Nothing -> (String -> String -> String -> ResultError) -> Field -> String -> Ok UUID forall a err. (Typeable a, Exception err) => (String -> String -> String -> err) -> Field -> String -> Ok a Sqlite.returnError String -> String -> String -> ResultError Sqlite.ConversionFailed Field field String "invalid UUID" Just UUID uuid -> UUID -> Ok UUID forall a. a -> Ok a forall (f :: * -> *) a. Applicative f => a -> f a pure UUID uuid instance Sqlite.ToField UUID where toField :: UUID -> SQLData toField = Text -> SQLData forall a. ToField a => a -> SQLData Sqlite.toField (Text -> SQLData) -> (UUID -> Text) -> UUID -> SQLData forall b c a. (b -> c) -> (a -> b) -> a -> c . UUID -> Text UUID.toText