module Aws.DynamoDb.Commands.GetItem where
import Control.Applicative
import Data.Aeson
import Data.Default
import qualified Data.Text as T
import Aws.Core
import Aws.DynamoDb.Core
data GetItem = GetItem {
giTableName :: T.Text
, giKey :: PrimaryKey
, giAttrs :: Maybe [T.Text]
, giConsistent :: Bool
, giRetCons :: ReturnConsumption
} deriving (Eq,Show,Read,Ord)
getItem
:: T.Text
-> PrimaryKey
-> GetItem
getItem tn k = GetItem tn k Nothing False def
data GetItemResponse = GetItemResponse {
girItem :: Maybe Item
, girConsumed :: Maybe ConsumedCapacity
} deriving (Eq,Show,Read,Ord)
instance Transaction GetItem GetItemResponse
instance ToJSON GetItem where
toJSON GetItem{..} = object $
maybe [] (return . ("AttributesToGet" .=)) giAttrs ++
[ "TableName" .= giTableName
, "Key" .= giKey
, "ConsistentRead" .= giConsistent
, "ReturnConsumedCapacity" .= giRetCons
]
instance SignQuery GetItem where
type ServiceConfiguration GetItem = DdbConfiguration
signQuery gi = ddbSignQuery "GetItem" gi
instance FromJSON GetItemResponse where
parseJSON (Object v) = GetItemResponse
<$> v .:? "Item"
<*> v .:? "ConsumedCapacity"
parseJSON _ = fail "GetItemResponse must be an object."
instance ResponseConsumer r GetItemResponse where
type ResponseMetadata GetItemResponse = DdbResponse
responseConsumer _ ref resp = ddbResponseConsumer ref resp
instance AsMemoryResponse GetItemResponse where
type MemoryResponse GetItemResponse = GetItemResponse
loadToMemory = return