module EZCouch.Types where
import Prelude ()
import ClassyPrelude
import Data.Aeson
import GHC.Generics
import EZCouch.Entity
data Persisted a = Persisted { persistedId :: Text, persistedRev :: Text, persistedValue :: a }
deriving (Show, Typeable, Eq, Ord, Generic)
instance (ToJSON a) => ToJSON (Persisted a)
instance (FromJSON a) => FromJSON (Persisted a)
persistedIdRev :: Persisted a -> IdRev a
persistedIdRev (Persisted id rev _) = IdRev id rev
persistedIdentified :: Persisted a -> Identified a
persistedIdentified (Persisted id _ value) = (id, value)
persistedIdHashPart :: Entity a => Persisted a -> Text
persistedIdHashPart (Persisted id _ value) =
fromMaybe undefined $ stripPrefix (entityType value ++ "-") id
type Identified a = (Text, a)
identifiedId (id, _) = id
identifiedValue (_, value) = value
data IdRev a = IdRev Text Text
data EZCouchException
= ParsingException Text
| OperationException Text
| ResponseException Text
| ConnectionException Text
| ServerException Text
deriving (Show, Typeable)
instance Exception EZCouchException