Skip to content

Commit 2a3681e

Browse files
add support for List/Array.IsEmpty and Option.IsSome/None
1 parent 9e30e85 commit 2a3681e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/FSharp.DynamoDB/Expression/ConditionalExpr.fs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,18 @@ let extractQueryExpr (recordInfo : RecordInfo) (expr : Expr) : ConditionalExpres
305305
| SpecificCall2 <@ NOT_EXISTS @> (None, _, _, [AttributeGet attr]) ->
306306
Attribute_Not_Exists attr.Id
307307

308+
| SpecificCall2 <@ Array.isEmpty @> (None, _, _, [AttributeGet attr]) ->
309+
Attribute_Not_Exists attr.Id
310+
311+
| SpecificCall2 <@ List.isEmpty @> (None, _, _, [AttributeGet attr]) ->
312+
Attribute_Not_Exists attr.Id
313+
314+
| SpecificCall2 <@ Option.isSome @> (None, _, _, [AttributeGet attr]) ->
315+
Attribute_Exists attr.Id
316+
317+
| SpecificCall2 <@ Option.isNone @> (None, _, _, [AttributeGet attr]) ->
318+
Attribute_Not_Exists attr.Id
319+
308320
| _ -> invalidQuery()
309321

310322
let queryExpr = extractQuery body

tests/FSharp.DynamoDB.Tests/ConditionalExpressionTests.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,16 @@ type ``Conditional Expression Tests`` () =
308308
table.PutItem(item, <@ fun r -> r.List.Length >= list.Length @>) |> ignore
309309
table.PutItem(item, <@ fun r -> List.length r.List >= list.Length @>) |> ignore
310310

311+
[<Fact>]
312+
let ``List-isEmpty precondition`` () =
313+
let item = { mkItem() with List = [] }
314+
let key = table.PutItem item
315+
table.PutItem({item with List = [42L]}, <@ fun r -> List.isEmpty r.List @>) |> ignore
316+
317+
fun () -> table.PutItem(item, <@ fun r -> List.isEmpty r.List @>)
318+
|> shouldFailwith<_, ConditionalCheckFailedException>
319+
320+
311321
[<Fact>]
312322
let ``Set-count precondition`` () =
313323
let item = mkItem()

0 commit comments

Comments
 (0)