Skip to content

Instantly share code, notes, and snippets.

@JonCanning
Created June 9, 2014 21:34
Show Gist options
  • Select an option

  • Save JonCanning/c95340adaa3bf4d8c215 to your computer and use it in GitHub Desktop.

Select an option

Save JonCanning/c95340adaa3bf4d8c215 to your computer and use it in GitHub Desktop.
RavenDB IDocumentStore Extensions
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