module Database.PostgreSQL.Stream.Types (
Identifier(..),
SQL(..),
Only(..),
Null(..),
Action(..),
Query(..),
QueryError(..),
ConversionError(..),
) where
import Data.Monoid
import Data.String
import Data.Typeable
import Data.ByteString as B
import Data.ByteString.Char8 as B8
import Control.Exception
newtype SQL = SQLExpr { unSQL :: ByteString }
deriving (Eq, Ord, Show, IsString, Monoid)
newtype Only a = Only { unOnly :: a }
deriving (Eq, Ord, Read, Show, Typeable, Functor)
newtype Identifier = Identifier { unIdentifier :: ByteString }
deriving (Eq, Ord, Show, IsString, Monoid)
data Null = Null
data Action
= Plain ByteString
| Escape ByteString
| EscapeIdentifier ByteString
deriving (Eq, Typeable, Show)
newtype Query = Query { fromQuery :: ByteString }
deriving (Eq, Ord, Typeable)
instance Show Query where
show = show . fromQuery
instance IsString Query where
fromString s = Query (B8.pack s)
instance Monoid Query where
mempty = Query B.empty
mappend (Query a) (Query b) = Query (B.append a b)
mconcat xs = Query (B.concat (fmap fromQuery xs))
data QueryError = QueryError
{ qeMessage :: String
, qeQuery :: Query
} deriving (Eq, Show, Typeable)
instance Exception QueryError
data ConversionError
= ConversionError { ceMessage :: String }
| UnexpectedNull { ceMessage :: String }
| Incompatible { ceMessage :: String }
deriving (Eq, Show, Typeable)
instance Exception ConversionError