Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/colinbull/ravendb
Browse files Browse the repository at this point in the history
  • Loading branch information
ayende committed May 6, 2012
2 parents ad73f06 + 1bfaf17 commit d349e16
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Raven.Client.Lightweight.FSharp/Raven.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ open Newtonsoft.Json
[<AutoOpen>]
module Operators =

let private toOption<'a> (a : 'a) =
match box a with
| null -> None
| _ -> Some(a)

let query (f : (IRavenQueryable<'a> -> #IQueryable<'b>)) (a : IDocumentSession) =
f(a.Query<'a>()).AsEnumerable()

Expand Down Expand Up @@ -65,6 +70,9 @@ open Newtonsoft.Json
let attachmentBody = attachment.Data.Invoke().ReadData()
(attachment.Metadata.JsonDeserialization<'a>(), attachment.Etag, attachmentBody)

let tryLoad<'a> (id : seq<string>) (a : IDocumentSession) =
a.Load<'a>(id) |> Seq.map2 (fun id result -> (id, toOption result)) id

let load<'a> (id : seq<string>) (a : IDocumentSession) =
a.Load(id).Cast<'a>()

Expand Down
19 changes: 18 additions & 1 deletion Raven.Tests.FSharp/RavenTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,24 @@ type ``Given a Initailised Document store execute using computation expression``
return expected, actual
} |> run session
Assert.Equal(exp,act)


[<Fact>]
let ``Should be able to save and retrieve an entity with tryLoad``() =
use ds = test.NewDocumentStore()
use session = ds.OpenSession()
let cust, act =
raven {
let! customer = store (Customer.Create("test", new DateTime(2012, 1, 1)))
do! saveChanges
let! actual = (tryLoad<Customer> ["customers/test";"customers/doesntexist"])
return customer, actual
} |> run session
let exp =
[
("customers/test", Option.Some(cust));
("customers/doesntexist", None)
]
Assert.True((exp = (act |> Seq.toList)))

[<Fact>]
let ``Should be able to query for filtered all entites``() =
Expand Down

0 comments on commit d349e16

Please sign in to comment.