{-# OPTIONS_GHC -fno-warn-orphans #-} module Network.URI.Orphans.Sqlite () where import Database.SQLite.Simple.FromField qualified as Sqlite import Database.SQLite.Simple.ToField qualified as Sqlite import Network.URI (URI) import Network.URI qualified as URI instance Sqlite.FromField URI where fromField :: FieldParser URI fromField Field field = do String string <- FieldParser String forall a. FromField a => FieldParser a Sqlite.fromField Field field case String -> Maybe URI URI.parseURI String string of Maybe URI Nothing -> (String -> String -> String -> ResultError) -> Field -> String -> Ok URI 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 URI" Just URI uri -> URI -> Ok URI forall a. a -> Ok a forall (f :: * -> *) a. Applicative f => a -> f a pure URI uri instance Sqlite.ToField URI where toField :: URI -> SQLData toField URI uri = String -> SQLData forall a. ToField a => a -> SQLData Sqlite.toField ((String -> String) -> URI -> String -> String URI.uriToString String -> String forall a. a -> a id URI uri String "")