Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Database/DynamoDB.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ module Database.DynamoDB (
, innerJoin
-- * Data entry
, putItem
, putItem'
, putItemBatch
, insertItem
-- * Data modification
Expand Down Expand Up @@ -120,7 +121,11 @@ dGetItem p pkey = D.getItem (tableName p) & D.giKey .~ dKeyToAttr p pkey

-- | Write item into the database; overwrite any previously existing item with the same primary key.
putItem :: (MonadAWS m, DynamoTable a r) => a -> m ()
putItem item = void $ send (dPutItem item)
putItem = void . putItem'

-- | Write item into the database and receive the response; overwrite any previously existing item with the same primary key.
putItem' :: (MonadAWS m, DynamoTable a r) => a -> m D.PutItemResponse
putItem' item = send (dPutItem item)

-- | Write item into the database only if it doesn't already exist.
insertItem :: forall a r m. (MonadAWS m, DynamoTable a r) => a -> m ()
Expand Down
10 changes: 8 additions & 2 deletions test/BaseSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module BaseSpec where

import Control.Exception.Safe (SomeException, catchAny, finally,
try)
import Control.Lens ((.~))
import Control.Lens ((.~), (^.))
import Control.Monad.IO.Class (liftIO)
import Data.Conduit (runConduit, (=$=))
import qualified Data.Conduit.List as CL
Expand All @@ -22,7 +22,8 @@ import Data.Proxy
import Data.Semigroup ((<>))
import qualified Data.Text as T
import Network.AWS
import Network.AWS.DynamoDB (dynamoDB)
import Network.AWS.DynamoDB (dynamoDB,
pirsResponseStatus)
import System.Environment (setEnv)
import System.IO (stdout)
import Test.Hspec
Expand Down Expand Up @@ -79,12 +80,17 @@ spec = do
withDb "putItem/getItem works" $ do
let testitem1 = Test "1" 2 "text" False 3.14 2 Nothing
testitem2 = Test "2" 3 "text" False 4.15 3 (Just "text")
testitem3 = Test "3" 4 "text" False 5.16 4 (Just "text")
putItem testitem1
putItem testitem2
res <- putItem' testitem3
liftIO $ res ^. pirsResponseStatus `shouldBe` 200
it1 <- getItem Strongly tTest ("1", 2)
it2 <- getItem Strongly tTest ("2", 3)
it3 <- getItem Strongly tTest ("3", 4)
liftIO $ Just testitem1 `shouldBe` it1
liftIO $ Just testitem2 `shouldBe` it2
liftIO $ Just testitem3 `shouldBe` it3
withDb "getItemBatch/putItemBatch work" $ do
let template i = Test (T.pack $ show i) i "text" False 3.14 i Nothing
newItems = map template [1..300]
Expand Down