From 2a3681e6b65f004d87d22cd53f1966bbe9437125 Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Thu, 3 Mar 2016 14:13:36 +0200 Subject: [PATCH] add support for List/Array.IsEmpty and Option.IsSome/None --- src/FSharp.DynamoDB/Expression/ConditionalExpr.fs | 12 ++++++++++++ .../ConditionalExpressionTests.fs | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/FSharp.DynamoDB/Expression/ConditionalExpr.fs b/src/FSharp.DynamoDB/Expression/ConditionalExpr.fs index 45f7b53..ab5f1fa 100644 --- a/src/FSharp.DynamoDB/Expression/ConditionalExpr.fs +++ b/src/FSharp.DynamoDB/Expression/ConditionalExpr.fs @@ -305,6 +305,18 @@ let extractQueryExpr (recordInfo : RecordInfo) (expr : Expr) : ConditionalExpres | SpecificCall2 <@ NOT_EXISTS @> (None, _, _, [AttributeGet attr]) -> Attribute_Not_Exists attr.Id + | SpecificCall2 <@ Array.isEmpty @> (None, _, _, [AttributeGet attr]) -> + Attribute_Not_Exists attr.Id + + | SpecificCall2 <@ List.isEmpty @> (None, _, _, [AttributeGet attr]) -> + Attribute_Not_Exists attr.Id + + | SpecificCall2 <@ Option.isSome @> (None, _, _, [AttributeGet attr]) -> + Attribute_Exists attr.Id + + | SpecificCall2 <@ Option.isNone @> (None, _, _, [AttributeGet attr]) -> + Attribute_Not_Exists attr.Id + | _ -> invalidQuery() let queryExpr = extractQuery body diff --git a/tests/FSharp.DynamoDB.Tests/ConditionalExpressionTests.fs b/tests/FSharp.DynamoDB.Tests/ConditionalExpressionTests.fs index 0616b83..70fc7db 100644 --- a/tests/FSharp.DynamoDB.Tests/ConditionalExpressionTests.fs +++ b/tests/FSharp.DynamoDB.Tests/ConditionalExpressionTests.fs @@ -308,6 +308,16 @@ type ``Conditional Expression Tests`` () = table.PutItem(item, <@ fun r -> r.List.Length >= list.Length @>) |> ignore table.PutItem(item, <@ fun r -> List.length r.List >= list.Length @>) |> ignore + [] + let ``List-isEmpty precondition`` () = + let item = { mkItem() with List = [] } + let key = table.PutItem item + table.PutItem({item with List = [42L]}, <@ fun r -> List.isEmpty r.List @>) |> ignore + + fun () -> table.PutItem(item, <@ fun r -> List.isEmpty r.List @>) + |> shouldFailwith<_, ConditionalCheckFailedException> + + [] let ``Set-count precondition`` () = let item = mkItem()