Created
June 9, 2014 21:34
-
-
Save JonCanning/c95340adaa3bf4d8c215 to your computer and use it in GitHub Desktop.
RavenDB IDocumentStore Extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module IDocumentStoreExtensions | |
| open Raven.Client | |
| open System.Linq | |
| type IDocumentStore with | |
| member this.getAll<'a>() = | |
| let rec load results = | |
| use session = this.OpenSession() | |
| let queryable, statistics = session.Query<'a>().Statistics() | |
| let newResults = results @ (queryable.Take(1024).Skip(results.Count()) |> Seq.toList) | |
| match newResults.Count() with | |
| | i when i = statistics.TotalResults -> newResults | |
| | _ -> load newResults | |
| load List.empty | |
| member this.forEach<'a> f = | |
| let rec load count = | |
| use session = this.OpenSession() | |
| let queryable, statistics = session.Query<'a>().Statistics() | |
| let results = queryable.Take(1024).Skip(count) |> Seq.toList | |
| results |> Seq.iter f | |
| match count + results.Count() with | |
| | i when i = statistics.TotalResults -> () | |
| | i -> load i | |
| load 0 | |
| member this.forEachInIndex<'a> index f = | |
| let rec load count = | |
| use session = this.OpenSession() | |
| let queryable, statistics = session.Query<'a>(index).Statistics() | |
| let results = queryable.Take(1024).Skip(count) |> Seq.toList | |
| results |> Seq.iter f | |
| match count + results.Count() with | |
| | i when i = statistics.TotalResults -> () | |
| | i -> load i | |
| load 0 | |
| member this.storeAndSave o = | |
| use session = this.OpenSession() | |
| session.Store o | |
| session.SaveChanges() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment