module Orville.PostgreSQL.Raw.PgTextFormatValue
( PgTextFormatValue
, NULByteFoundError (NULByteFoundError)
, unsafeFromByteString
, fromByteString
, toByteString
, toBytesForLibPQ
)
where
import Control.Exception (Exception)
import qualified Data.ByteString as BS
data PgTextFormatValue
= NoAssumptionsMade BS.ByteString
| AssumedToHaveNoNULValues BS.ByteString
deriving (Int -> PgTextFormatValue -> ShowS
[PgTextFormatValue] -> ShowS
PgTextFormatValue -> String
(Int -> PgTextFormatValue -> ShowS)
-> (PgTextFormatValue -> String)
-> ([PgTextFormatValue] -> ShowS)
-> Show PgTextFormatValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PgTextFormatValue -> ShowS
showsPrec :: Int -> PgTextFormatValue -> ShowS
$cshow :: PgTextFormatValue -> String
show :: PgTextFormatValue -> String
$cshowList :: [PgTextFormatValue] -> ShowS
showList :: [PgTextFormatValue] -> ShowS
Show)
instance Eq PgTextFormatValue where
PgTextFormatValue
left == :: PgTextFormatValue -> PgTextFormatValue -> Bool
== PgTextFormatValue
right =
PgTextFormatValue -> Either NULByteFoundError ByteString
toBytesForLibPQ PgTextFormatValue
left Either NULByteFoundError ByteString
-> Either NULByteFoundError ByteString -> Bool
forall a. Eq a => a -> a -> Bool
== PgTextFormatValue -> Either NULByteFoundError ByteString
toBytesForLibPQ PgTextFormatValue
right
data NULByteFoundError
= NULByteFoundError
deriving (Int -> NULByteFoundError -> ShowS
[NULByteFoundError] -> ShowS
NULByteFoundError -> String
(Int -> NULByteFoundError -> ShowS)
-> (NULByteFoundError -> String)
-> ([NULByteFoundError] -> ShowS)
-> Show NULByteFoundError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NULByteFoundError -> ShowS
showsPrec :: Int -> NULByteFoundError -> ShowS
$cshow :: NULByteFoundError -> String
show :: NULByteFoundError -> String
$cshowList :: [NULByteFoundError] -> ShowS
showList :: [NULByteFoundError] -> ShowS
Show, NULByteFoundError -> NULByteFoundError -> Bool
(NULByteFoundError -> NULByteFoundError -> Bool)
-> (NULByteFoundError -> NULByteFoundError -> Bool)
-> Eq NULByteFoundError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NULByteFoundError -> NULByteFoundError -> Bool
== :: NULByteFoundError -> NULByteFoundError -> Bool
$c/= :: NULByteFoundError -> NULByteFoundError -> Bool
/= :: NULByteFoundError -> NULByteFoundError -> Bool
Eq)
instance Exception NULByteFoundError
unsafeFromByteString :: BS.ByteString -> PgTextFormatValue
unsafeFromByteString :: ByteString -> PgTextFormatValue
unsafeFromByteString =
ByteString -> PgTextFormatValue
AssumedToHaveNoNULValues
fromByteString :: BS.ByteString -> PgTextFormatValue
fromByteString :: ByteString -> PgTextFormatValue
fromByteString =
ByteString -> PgTextFormatValue
NoAssumptionsMade
toBytesForLibPQ :: PgTextFormatValue -> Either NULByteFoundError BS.ByteString
toBytesForLibPQ :: PgTextFormatValue -> Either NULByteFoundError ByteString
toBytesForLibPQ PgTextFormatValue
value =
case PgTextFormatValue
value of
AssumedToHaveNoNULValues ByteString
noNULBytes ->
ByteString -> Either NULByteFoundError ByteString
forall a b. b -> Either a b
Right ByteString
noNULBytes
NoAssumptionsMade ByteString
anyBytes ->
if Word8 -> ByteString -> Bool
BS.elem Word8
0 ByteString
anyBytes
then NULByteFoundError -> Either NULByteFoundError ByteString
forall a b. a -> Either a b
Left NULByteFoundError
NULByteFoundError
else ByteString -> Either NULByteFoundError ByteString
forall a b. b -> Either a b
Right ByteString
anyBytes
toByteString :: PgTextFormatValue -> BS.ByteString
toByteString :: PgTextFormatValue -> ByteString
toByteString PgTextFormatValue
value =
case PgTextFormatValue
value of
AssumedToHaveNoNULValues ByteString
bytes ->
ByteString
bytes
NoAssumptionsMade ByteString
bytes ->
ByteString
bytes