{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
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 {
PutItem -> Text
piTable :: T.Text
, PutItem -> Item
piItem :: Item
, PutItem -> Conditions
piExpect :: Conditions
, PutItem -> UpdateReturn
piReturn :: UpdateReturn
, PutItem -> ReturnConsumption
piRetCons :: ReturnConsumption
, PutItem -> ReturnItemCollectionMetrics
piRetMet :: ReturnItemCollectionMetrics
} deriving (PutItem -> PutItem -> Bool
(PutItem -> PutItem -> Bool)
-> (PutItem -> PutItem -> Bool) -> Eq PutItem
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutItem -> PutItem -> Bool
$c/= :: PutItem -> PutItem -> Bool
== :: PutItem -> PutItem -> Bool
$c== :: PutItem -> PutItem -> Bool
Eq,Int -> PutItem -> ShowS
[PutItem] -> ShowS
PutItem -> String
(Int -> PutItem -> ShowS)
-> (PutItem -> String) -> ([PutItem] -> ShowS) -> Show PutItem
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutItem] -> ShowS
$cshowList :: [PutItem] -> ShowS
show :: PutItem -> String
$cshow :: PutItem -> String
showsPrec :: Int -> PutItem -> ShowS
$cshowsPrec :: Int -> PutItem -> ShowS
Show,ReadPrec [PutItem]
ReadPrec PutItem
Int -> ReadS PutItem
ReadS [PutItem]
(Int -> ReadS PutItem)
-> ReadS [PutItem]
-> ReadPrec PutItem
-> ReadPrec [PutItem]
-> Read PutItem
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutItem]
$creadListPrec :: ReadPrec [PutItem]
readPrec :: ReadPrec PutItem
$creadPrec :: ReadPrec PutItem
readList :: ReadS [PutItem]
$creadList :: ReadS [PutItem]
readsPrec :: Int -> ReadS PutItem
$creadsPrec :: Int -> ReadS PutItem
Read,Eq PutItem
Eq PutItem
-> (PutItem -> PutItem -> Ordering)
-> (PutItem -> PutItem -> Bool)
-> (PutItem -> PutItem -> Bool)
-> (PutItem -> PutItem -> Bool)
-> (PutItem -> PutItem -> Bool)
-> (PutItem -> PutItem -> PutItem)
-> (PutItem -> PutItem -> PutItem)
-> Ord PutItem
PutItem -> PutItem -> Bool
PutItem -> PutItem -> Ordering
PutItem -> PutItem -> PutItem
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: PutItem -> PutItem -> PutItem
$cmin :: PutItem -> PutItem -> PutItem
max :: PutItem -> PutItem -> PutItem
$cmax :: PutItem -> PutItem -> PutItem
>= :: PutItem -> PutItem -> Bool
$c>= :: PutItem -> PutItem -> Bool
> :: PutItem -> PutItem -> Bool
$c> :: PutItem -> PutItem -> Bool
<= :: PutItem -> PutItem -> Bool
$c<= :: PutItem -> PutItem -> Bool
< :: PutItem -> PutItem -> Bool
$c< :: PutItem -> PutItem -> Bool
compare :: PutItem -> PutItem -> Ordering
$ccompare :: PutItem -> PutItem -> Ordering
$cp1Ord :: Eq PutItem
Ord)
putItem :: T.Text
-> Item
-> PutItem
putItem :: Text -> Item -> PutItem
putItem Text
tn Item
it = Text
-> Item
-> Conditions
-> UpdateReturn
-> ReturnConsumption
-> ReturnItemCollectionMetrics
-> PutItem
PutItem Text
tn Item
it Conditions
forall a. Default a => a
def UpdateReturn
forall a. Default a => a
def ReturnConsumption
forall a. Default a => a
def ReturnItemCollectionMetrics
forall a. Default a => a
def
instance ToJSON PutItem where
toJSON :: PutItem -> Value
toJSON PutItem{Text
Item
UpdateReturn
ReturnItemCollectionMetrics
ReturnConsumption
Conditions
piRetMet :: ReturnItemCollectionMetrics
piRetCons :: ReturnConsumption
piReturn :: UpdateReturn
piExpect :: Conditions
piItem :: Item
piTable :: Text
piRetMet :: PutItem -> ReturnItemCollectionMetrics
piRetCons :: PutItem -> ReturnConsumption
piReturn :: PutItem -> UpdateReturn
piExpect :: PutItem -> Conditions
piItem :: PutItem -> Item
piTable :: PutItem -> Text
..} =
[Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$ Conditions -> [Pair]
expectsJson Conditions
piExpect [Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++
[ Key
"TableName" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
piTable
, Key
"Item" Key -> Item -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Item
piItem
, Key
"ReturnValues" Key -> UpdateReturn -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UpdateReturn
piReturn
, Key
"ReturnConsumedCapacity" Key -> ReturnConsumption -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= ReturnConsumption
piRetCons
, Key
"ReturnItemCollectionMetrics" Key -> ReturnItemCollectionMetrics -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= ReturnItemCollectionMetrics
piRetMet
]
data PutItemResponse = PutItemResponse {
PutItemResponse -> Maybe Item
pirAttrs :: Maybe Item
, PutItemResponse -> Maybe ConsumedCapacity
pirConsumed :: Maybe ConsumedCapacity
, PutItemResponse -> Maybe ItemCollectionMetrics
pirColMet :: Maybe ItemCollectionMetrics
} deriving (PutItemResponse -> PutItemResponse -> Bool
(PutItemResponse -> PutItemResponse -> Bool)
-> (PutItemResponse -> PutItemResponse -> Bool)
-> Eq PutItemResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutItemResponse -> PutItemResponse -> Bool
$c/= :: PutItemResponse -> PutItemResponse -> Bool
== :: PutItemResponse -> PutItemResponse -> Bool
$c== :: PutItemResponse -> PutItemResponse -> Bool
Eq,Int -> PutItemResponse -> ShowS
[PutItemResponse] -> ShowS
PutItemResponse -> String
(Int -> PutItemResponse -> ShowS)
-> (PutItemResponse -> String)
-> ([PutItemResponse] -> ShowS)
-> Show PutItemResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutItemResponse] -> ShowS
$cshowList :: [PutItemResponse] -> ShowS
show :: PutItemResponse -> String
$cshow :: PutItemResponse -> String
showsPrec :: Int -> PutItemResponse -> ShowS
$cshowsPrec :: Int -> PutItemResponse -> ShowS
Show,ReadPrec [PutItemResponse]
ReadPrec PutItemResponse
Int -> ReadS PutItemResponse
ReadS [PutItemResponse]
(Int -> ReadS PutItemResponse)
-> ReadS [PutItemResponse]
-> ReadPrec PutItemResponse
-> ReadPrec [PutItemResponse]
-> Read PutItemResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutItemResponse]
$creadListPrec :: ReadPrec [PutItemResponse]
readPrec :: ReadPrec PutItemResponse
$creadPrec :: ReadPrec PutItemResponse
readList :: ReadS [PutItemResponse]
$creadList :: ReadS [PutItemResponse]
readsPrec :: Int -> ReadS PutItemResponse
$creadsPrec :: Int -> ReadS PutItemResponse
Read,Eq PutItemResponse
Eq PutItemResponse
-> (PutItemResponse -> PutItemResponse -> Ordering)
-> (PutItemResponse -> PutItemResponse -> Bool)
-> (PutItemResponse -> PutItemResponse -> Bool)
-> (PutItemResponse -> PutItemResponse -> Bool)
-> (PutItemResponse -> PutItemResponse -> Bool)
-> (PutItemResponse -> PutItemResponse -> PutItemResponse)
-> (PutItemResponse -> PutItemResponse -> PutItemResponse)
-> Ord PutItemResponse
PutItemResponse -> PutItemResponse -> Bool
PutItemResponse -> PutItemResponse -> Ordering
PutItemResponse -> PutItemResponse -> PutItemResponse
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: PutItemResponse -> PutItemResponse -> PutItemResponse
$cmin :: PutItemResponse -> PutItemResponse -> PutItemResponse
max :: PutItemResponse -> PutItemResponse -> PutItemResponse
$cmax :: PutItemResponse -> PutItemResponse -> PutItemResponse
>= :: PutItemResponse -> PutItemResponse -> Bool
$c>= :: PutItemResponse -> PutItemResponse -> Bool
> :: PutItemResponse -> PutItemResponse -> Bool
$c> :: PutItemResponse -> PutItemResponse -> Bool
<= :: PutItemResponse -> PutItemResponse -> Bool
$c<= :: PutItemResponse -> PutItemResponse -> Bool
< :: PutItemResponse -> PutItemResponse -> Bool
$c< :: PutItemResponse -> PutItemResponse -> Bool
compare :: PutItemResponse -> PutItemResponse -> Ordering
$ccompare :: PutItemResponse -> PutItemResponse -> Ordering
$cp1Ord :: Eq PutItemResponse
Ord)
instance Transaction PutItem PutItemResponse
instance SignQuery PutItem where
type ServiceConfiguration PutItem = DdbConfiguration
signQuery :: PutItem
-> ServiceConfiguration PutItem queryType
-> SignatureData
-> SignedQuery
signQuery PutItem
gi = ByteString
-> PutItem
-> DdbConfiguration queryType
-> SignatureData
-> SignedQuery
forall a qt.
ToJSON a =>
ByteString
-> a -> DdbConfiguration qt -> SignatureData -> SignedQuery
ddbSignQuery ByteString
"PutItem" PutItem
gi
instance FromJSON PutItemResponse where
parseJSON :: Value -> Parser PutItemResponse
parseJSON (Object Object
v) = Maybe Item
-> Maybe ConsumedCapacity
-> Maybe ItemCollectionMetrics
-> PutItemResponse
PutItemResponse
(Maybe Item
-> Maybe ConsumedCapacity
-> Maybe ItemCollectionMetrics
-> PutItemResponse)
-> Parser (Maybe Item)
-> Parser
(Maybe ConsumedCapacity
-> Maybe ItemCollectionMetrics -> PutItemResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Item)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"Attributes"
Parser
(Maybe ConsumedCapacity
-> Maybe ItemCollectionMetrics -> PutItemResponse)
-> Parser (Maybe ConsumedCapacity)
-> Parser (Maybe ItemCollectionMetrics -> PutItemResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe ConsumedCapacity)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"ConsumedCapacity"
Parser (Maybe ItemCollectionMetrics -> PutItemResponse)
-> Parser (Maybe ItemCollectionMetrics) -> Parser PutItemResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe ItemCollectionMetrics)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"ItemCollectionMetrics"
parseJSON Value
_ = String -> Parser PutItemResponse
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"PutItemResponse must be an object."
instance ResponseConsumer r PutItemResponse where
type ResponseMetadata PutItemResponse = DdbResponse
responseConsumer :: Request
-> r
-> IORef (ResponseMetadata PutItemResponse)
-> HTTPResponseConsumer PutItemResponse
responseConsumer Request
_ r
_ IORef (ResponseMetadata PutItemResponse)
ref Response (ConduitM () ByteString (ResourceT IO) ())
resp = IORef DdbResponse -> HTTPResponseConsumer PutItemResponse
forall a. FromJSON a => IORef DdbResponse -> HTTPResponseConsumer a
ddbResponseConsumer IORef (ResponseMetadata PutItemResponse)
IORef DdbResponse
ref Response (ConduitM () ByteString (ResourceT IO) ())
resp
instance AsMemoryResponse PutItemResponse where
type MemoryResponse PutItemResponse = PutItemResponse
loadToMemory :: PutItemResponse -> ResourceT IO (MemoryResponse PutItemResponse)
loadToMemory = PutItemResponse -> ResourceT IO (MemoryResponse PutItemResponse)
forall (m :: * -> *) a. Monad m => a -> m a
return