module Database.PostgreSQL.PQTypes.XML (
    XML(..)
  ) where

import Data.Text
import qualified Data.ByteString.Char8 as BSC

import Database.PostgreSQL.PQTypes.Format
import Database.PostgreSQL.PQTypes.FromSQL
import Database.PostgreSQL.PQTypes.Internal.C.Types
import Database.PostgreSQL.PQTypes.ToSQL

-- | Representation of SQL XML types as 'Text'.  Users of hpqtypes may
-- want to add conversion instances for their favorite XML type around 'XML'.
newtype XML = XML { XML -> Text
unXML :: Text }
  deriving (XML -> XML -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: XML -> XML -> Bool
$c/= :: XML -> XML -> Bool
== :: XML -> XML -> Bool
$c== :: XML -> XML -> Bool
Eq, Eq XML
XML -> XML -> Bool
XML -> XML -> Ordering
XML -> XML -> XML
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: XML -> XML -> XML
$cmin :: XML -> XML -> XML
max :: XML -> XML -> XML
$cmax :: XML -> XML -> XML
>= :: XML -> XML -> Bool
$c>= :: XML -> XML -> Bool
> :: XML -> XML -> Bool
$c> :: XML -> XML -> Bool
<= :: XML -> XML -> Bool
$c<= :: XML -> XML -> Bool
< :: XML -> XML -> Bool
$c< :: XML -> XML -> Bool
compare :: XML -> XML -> Ordering
$ccompare :: XML -> XML -> Ordering
Ord, ReadPrec [XML]
ReadPrec XML
Int -> ReadS XML
ReadS [XML]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [XML]
$creadListPrec :: ReadPrec [XML]
readPrec :: ReadPrec XML
$creadPrec :: ReadPrec XML
readList :: ReadS [XML]
$creadList :: ReadS [XML]
readsPrec :: Int -> ReadS XML
$creadsPrec :: Int -> ReadS XML
Read, Int -> XML -> ShowS
[XML] -> ShowS
XML -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [XML] -> ShowS
$cshowList :: [XML] -> ShowS
show :: XML -> String
$cshow :: XML -> String
showsPrec :: Int -> XML -> ShowS
$cshowsPrec :: Int -> XML -> ShowS
Show)

instance PQFormat XML where
  pqFormat :: ByteString
pqFormat = String -> ByteString
BSC.pack String
"%xml"

instance FromSQL XML where
  type PQBase XML = PGbytea
  fromSQL :: Maybe (PQBase XML) -> IO XML
fromSQL = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> XML
XML forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. FromSQL t => Maybe (PQBase t) -> IO t
fromSQL

instance ToSQL XML where
  type PQDest XML = PGbytea
  toSQL :: forall r.
XML -> ParamAllocator -> (Ptr (PQDest XML) -> IO r) -> IO r
toSQL = forall t r.
ToSQL t =>
t -> ParamAllocator -> (Ptr (PQDest t) -> IO r) -> IO r
toSQL forall b c a. (b -> c) -> (a -> b) -> a -> c
. XML -> Text
unXML