From 64b874fba378fde159b5c4e071b97a6f085592d0 Mon Sep 17 00:00:00 2001 From: Nick Darvey Date: Tue, 26 Jul 2022 20:07:14 +1000 Subject: [PATCH] chore: Add ADD_INT64 operator --- .../Expression/UpdateExpr.fs | 5 +++++ src/FSharp.AWS.DynamoDB/Types.fs | 4 ++++ .../UpdateExpressionTests.fs | 21 +++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/FSharp.AWS.DynamoDB/Expression/UpdateExpr.fs b/src/FSharp.AWS.DynamoDB/Expression/UpdateExpr.fs index dbd9a92..3aef7c0 100644 --- a/src/FSharp.AWS.DynamoDB/Expression/UpdateExpr.fs +++ b/src/FSharp.AWS.DynamoDB/Expression/UpdateExpr.fs @@ -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 diff --git a/src/FSharp.AWS.DynamoDB/Types.fs b/src/FSharp.AWS.DynamoDB/Types.fs index a21cc3a..4343161 100644 --- a/src/FSharp.AWS.DynamoDB/Types.fs +++ b/src/FSharp.AWS.DynamoDB/Types.fs @@ -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." diff --git a/tests/FSharp.AWS.DynamoDB.Tests/UpdateExpressionTests.fs b/tests/FSharp.AWS.DynamoDB.Tests/UpdateExpressionTests.fs index f9d1343..bab299c 100644 --- a/tests/FSharp.AWS.DynamoDB.Tests/UpdateExpressionTests.fs +++ b/tests/FSharp.AWS.DynamoDB.Tests/UpdateExpressionTests.fs @@ -371,6 +371,27 @@ type ``Update Expression Tests``(fixture : TableFixture) = test <@ item'.IntSet.Contains 42L @> + let [] ``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 [] ``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 []``DELETE from set`` () = let item = { mkItem() with IntSet = set [1L ; 42L] } let key = table.PutItem item