Skip to content
Draft
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
5 changes: 5 additions & 0 deletions src/FSharp.AWS.DynamoDB/Expression/UpdateExpr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ let extractOpExprUpdaters (recordInfo : RecordTableInfo) (expr : Expr) : Interme
attrs.Add attr
updateOps.Add (Add (attr.Id, op))

| SpecificCall2 <@ ADD_INT64 @> (None, _, _, [AttributeGet attr; value]) ->
let op = getOperand attr.Pickler value
attrs.Add attr
updateOps.Add (Add (attr.Id, op))

| SpecificCall2 <@ DELETE @> (None, _, _, [AttributeGet attr; value]) ->
let op = getOperand attr.Pickler value
attrs.Add attr
Expand Down
4 changes: 4 additions & 0 deletions src/FSharp.AWS.DynamoDB/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ module UpdateOperators =
let ADD (path : Set<'T>) (values : seq<'T>) : UpdateOp =
invalidOp "ADD operation reserved for quoted update expressions."

/// Adds given value to attribute path
let ADD_INT64 (path : int64) (value : int64) : UpdateOp =
invalidOp "ADD_INT64 operation reserved for quoted update expressions."

/// Deletes given set of values to set attribute path
let DELETE (path : Set<'T>) (values : seq<'T>) : UpdateOp =
invalidOp "DELETE operation reserved for quoted update expressions."
21 changes: 21 additions & 0 deletions tests/FSharp.AWS.DynamoDB.Tests/UpdateExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,27 @@ type ``Update Expression Tests``(fixture : TableFixture) =

test <@ item'.IntSet.Contains 42L @>

let [<Fact>] ``ADD to int`` () =
let item = mkItem()
let key = table.PutItem item
let item' = table.UpdateItem(key, <@ fun r -> ADD_INT64 r.Value 1L @>)

test <@ item.Value + 1L = item'.Value @>


let [<Fact>] ``ADD to int without creating item first`` () =
let item = mkItem()
let item' = table.UpdateItem(TableKey.Combined(item.HashKey, item.RangeKey), <@ fun (r : R) ->
ADD_INT64 r.Value 42L &&&
// Set attributes to satisfy default values
// System.NotSupportedException : Default value...
// at FSharp.AWS.DynamoDB.Pickler.Pickler`1.get_DefaultValueUntyped()
SET r.Union (UA 0L) &&&
SET r.Serialized item.Serialized &&&
SET r.Serialized2 item.Serialized2 @>)

test <@ 0L + 42L = item'.Value @>

let [<Fact>]``DELETE from set`` () =
let item = { mkItem() with IntSet = set [1L ; 42L] }
let key = table.PutItem item
Expand Down