I am using RavenDB 2.0 unstable. Is it possible to query RavenDB 2.0 with a lambda or similar technique (linq?) from F#?
Here is intent example code. I am attempting to get all the posts in last 72 hours. Its wrong, but it gets the idea across.
static member public GetTopPosts _ =
use store = (new DocumentStore(Url = Docs.serverUrl, DefaultDatabase = Docs.dbName )).Initialize()
use session = store.OpenSession()
let result = session.Query<Post>().Where(fun x -> x.Date > DateTime.Now - new TimeSpan(72,0,0))
...
How can something like this be accomplished?
Yes you can do this.
You can find an example of this in FAKE
In your case your query would look something like this
let getTopPostsAsOf date =
use session = docStore.OpenSession()
query {
for post in session.Query<Post>() do
where (post.Date > date)
select post
} |> Seq.toArray
this would then be called with
let result = getTopPostsAsOf (DateTime.Now - TimeSpan.FromHours(72))
A couple of things to note.
The DocumentStore should be created once and only once at the startup of the application.
Also typically only a small set of library calls can be used within the query expressions, hence why I pass in the already computed date. The reason for this is because these expression trees end up getting serialized and executed within raven db engine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With