Skip to content

Commit

Permalink
add support for List/Array.IsEmpty and Option.IsSome/None
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriktsarpalis committed Mar 3, 2016
1 parent 9e30e85 commit 2a3681e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/FSharp.DynamoDB/Expression/ConditionalExpr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/FSharp.DynamoDB.Tests/ConditionalExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

[<Fact>]
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>


[<Fact>]
let ``Set-count precondition`` () =
let item = mkItem()
Expand Down

0 comments on commit 2a3681e

Please sign in to comment.