module Aws.DynamoDb.Commands.PutItem where
import Control.Applicative
import Data.Aeson
import Data.Default
import qualified Data.Text as T
import Prelude
import Aws.Core
import Aws.DynamoDb.Core
data PutItem = PutItem {
piTable :: T.Text
, piItem :: Item
, piExpect :: Conditions
, piReturn :: UpdateReturn
, piRetCons :: ReturnConsumption
, piRetMet :: ReturnItemCollectionMetrics
} deriving (Eq,Show,Read,Ord)
putItem :: T.Text
-> Item
-> PutItem
putItem tn it = PutItem tn it def def def def
instance ToJSON PutItem where
toJSON PutItem{..} =
object $ expectsJson piExpect ++
[ "TableName" .= piTable
, "Item" .= piItem
, "ReturnValues" .= piReturn
, "ReturnConsumedCapacity" .= piRetCons
, "ReturnItemCollectionMetrics" .= piRetMet
]
data PutItemResponse = PutItemResponse {
pirAttrs :: Maybe Item
, pirConsumed :: Maybe ConsumedCapacity
, pirColMet :: Maybe ItemCollectionMetrics
} deriving (Eq,Show,Read,Ord)
instance Transaction PutItem PutItemResponse
instance SignQuery PutItem where
type ServiceConfiguration PutItem = DdbConfiguration
signQuery gi = ddbSignQuery "PutItem" gi
instance FromJSON PutItemResponse where
parseJSON (Object v) = PutItemResponse
<$> v .:? "Attributes"
<*> v .:? "ConsumedCapacity"
<*> v .:? "ItemCollectionMetrics"
parseJSON _ = fail "PutItemResponse must be an object."
instance ResponseConsumer r PutItemResponse where
type ResponseMetadata PutItemResponse = DdbResponse
responseConsumer _ _ ref resp = ddbResponseConsumer ref resp
instance AsMemoryResponse PutItemResponse where
type MemoryResponse PutItemResponse = PutItemResponse
loadToMemory = return