Skip to content

Commit a09b8af

Browse files
committed
DynamoDb: Avoid overlapping ToJSON instance
Aeson 1.0 will provide a `ToJSON [a]` instance, which the previous `ToJSON [AttributeUpdate]` instance will overlap with. This internally wraps `[AttributeUpdate]` in a newtype.
1 parent 1bc7328 commit a09b8af

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Aws/DynamoDb/Commands/UpdateItem.hs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@
1919
--
2020
----------------------------------------------------------------------------
2121

22-
module Aws.DynamoDb.Commands.UpdateItem where
22+
module Aws.DynamoDb.Commands.UpdateItem
23+
( UpdateItem(..)
24+
, updateItem
25+
, AttributeUpdate(..)
26+
, au
27+
, UpdateAction(..)
28+
, UpdateItem(..)
29+
, UpdateItemResponse(..)
30+
) where
2331

2432
-------------------------------------------------------------------------------
2533
import Control.Applicative
@@ -55,7 +63,10 @@ updateItem
5563
updateItem tn key ups = UpdateItem tn key ups def def def def
5664

5765

58-
type AttributeUpdates = [AttributeUpdate]
66+
-- | A helper to avoid overlapping instances for 'ToJSON'.
67+
newtype AttributeUpdates = AttributeUpdates {
68+
getAttributeUpdates :: [AttributeUpdate]
69+
}
5970

6071

6172
data AttributeUpdate = AttributeUpdate {
@@ -77,7 +88,7 @@ au a = AttributeUpdate a def
7788

7889

7990
instance ToJSON AttributeUpdates where
80-
toJSON = object . map mk
91+
toJSON = object . map mk . getAttributeUpdates
8192
where
8293
mk AttributeUpdate { auAction = UDelete, auAttr = auAttr } =
8394
(attrName auAttr) .= object
@@ -114,7 +125,7 @@ instance ToJSON UpdateItem where
114125
object $ expectsJson uiExpect ++
115126
[ "TableName" .= uiTable
116127
, "Key" .= uiKey
117-
, "AttributeUpdates" .= uiUpdates
128+
, "AttributeUpdates" .= AttributeUpdates uiUpdates
118129
, "ReturnValues" .= uiReturn
119130
, "ReturnConsumedCapacity" .= uiRetCons
120131
, "ReturnItemCollectionMetrics" .= uiRetMet

0 commit comments

Comments
 (0)