Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated f# api with some select, take and skip combinators

  • Loading branch information...
commit 02d20bd528ff565695cab2af7e3616734c6b11c8 1 parent 7d12f31
@colinbull colinbull authored
View
14 Raven.Client.Lightweight.FSharp/Raven.fs
@@ -6,6 +6,7 @@ open System.Linq.Expressions
open System.ComponentModel.Composition
open Raven.Client
+open Raven.Client.Indexes
open Raven.Client.Linq
open Raven.Client.Document
open Raven.Abstractions.Extensions
@@ -21,6 +22,19 @@ open Newtonsoft.Json
let luceneQuery<'a, 'b> (f : (IDocumentQuery<'a> -> IDocumentQuery<'b>)) (a : IDocumentSession) =
f(a.Advanced.LuceneQuery<'a>()).AsEnumerable()
+
+ let select (p : Expr<'a -> 'b>) (a : IRavenQueryable<'a>) =
+ let expr = Linq.toLinqExpression (fun b a -> Expression.Lambda<Func<'a,'b>>(a, b |> Array.ofSeq)) p
+ a.Select(expr)
+
+ let skip n (a : IRavenQueryable<'a>) =
+ a.Skip(n)
+
+ let take n (a : IRavenQueryable<'a>) =
+ a.Take(n)
+
+ let queryIndex<'a, 'b, 'index when 'index : (new : unit -> 'index) and 'index :> AbstractIndexCreationTask> (f : (IRavenQueryable<'a> -> IQueryable<'b>)) (a : IDocumentSession) =
+ f(a.Query<'a, 'index>()).AsEnumerable()
let where (p : Expr<'a -> bool>) (a : IRavenQueryable<'a>) =
let expr = Linq.toLinqExpression (fun b a -> Expression.Lambda<Func<'a,bool>>(a, b |> Array.ofSeq)) p
View
47 Raven.Tests.FSharp/RavenTests.fs
@@ -134,6 +134,51 @@ type ``Given a Initailised Document store execute using computation expression``
}
[<Fact>]
+ let ``Should be able to skip results with skip``() =
+ use ds = test.NewDocumentStore()
+ use session = ds.OpenSession()
+ let actual =
+ raven {
+ do! storeMany (createCustomers 15) >> ignore
+ let! actual = query (where <@ fun x -> x.Dob < new DateTime(2012,1,7) @> >> skip 3)
+ return actual
+ } |> run session |> Seq.toList
+
+ let expected = createCustomers ((new DateTime(2012,1,7)).Subtract(new DateTime(2012,1,1)).Days) |> Seq.skip 3 |> Seq.toList
+
+ Assert.True((expected = actual))
+
+ [<Fact>]
+ let ``Should be able to take n results with take``() =
+ use ds = test.NewDocumentStore()
+ use session = ds.OpenSession()
+ let actual =
+ raven {
+ do! storeMany (createCustomers 15) >> ignore
+ let! actual = query (where <@ fun x -> x.Dob < new DateTime(2012,1,7) @> >> take 3)
+ return actual
+ } |> run session |> Seq.toList
+
+ let expected = createCustomers ((new DateTime(2012,1,4)).Subtract(new DateTime(2012,1,1)).Days) |> Seq.toList
+
+ Assert.True((expected = actual))
+
+ [<Fact>]
+ let ``Should be able to project a property with select``() =
+ use ds = test.NewDocumentStore()
+ use session = ds.OpenSession()
+ let actual =
+ raven {
+ do! storeMany (createCustomers 7) >> ignore
+ let! actual = query (select <@ fun x -> x.Id @>)
+ return actual
+ } |> run session |> Seq.toList
+
+ let expected = createCustomers 7 |> Seq.map (fun x -> x.Id) |> Seq.toList
+
+ Assert.True((expected = actual))
+
+ [<Fact>]
let ``Should implicitly call save changes if runs to completion``() =
use ds = test.NewDocumentStore()
use session = ds.OpenSession()
@@ -142,7 +187,7 @@ type ``Given a Initailised Document store execute using computation expression``
//Humm... Is this the only way I could get it too compile, Assert.Equals cant resolve the correct overload
Assert.True((expected = actual))
-
+
[<Fact>]
let ``Should be able to save and retrieve an entity``() =
use ds = test.NewDocumentStore()
View
24 RavenDB.sln
@@ -51,6 +51,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{CFD25A
CommonAssemblyInfo.cs = CommonAssemblyInfo.cs
EndProjectSection
EndProject
+Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Raven.Client.Lightweight.FSharp", "Raven.Client.Lightweight.FSharp\Raven.Client.Lightweight.FSharp.fsproj", "{6996133D-EE21-4CC8-B29B-F6222EE476BB}"
+EndProject
+Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Raven.Tests.FSharp", "Raven.Tests.FSharp\Raven.Tests.FSharp.fsproj", "{295D9C7D-5F05-4B12-BB1E-8FB7A21E9071}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -241,6 +245,26 @@ Global
{8A1DB308-D56B-49BC-A421-A2AB32617215}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{8A1DB308-D56B-49BC-A421-A2AB32617215}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{8A1DB308-D56B-49BC-A421-A2AB32617215}.Release|x86.ActiveCfg = Release|Any CPU
+ {6996133D-EE21-4CC8-B29B-F6222EE476BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6996133D-EE21-4CC8-B29B-F6222EE476BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6996133D-EE21-4CC8-B29B-F6222EE476BB}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {6996133D-EE21-4CC8-B29B-F6222EE476BB}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {6996133D-EE21-4CC8-B29B-F6222EE476BB}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {6996133D-EE21-4CC8-B29B-F6222EE476BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6996133D-EE21-4CC8-B29B-F6222EE476BB}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6996133D-EE21-4CC8-B29B-F6222EE476BB}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {6996133D-EE21-4CC8-B29B-F6222EE476BB}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {6996133D-EE21-4CC8-B29B-F6222EE476BB}.Release|x86.ActiveCfg = Release|Any CPU
+ {295D9C7D-5F05-4B12-BB1E-8FB7A21E9071}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {295D9C7D-5F05-4B12-BB1E-8FB7A21E9071}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {295D9C7D-5F05-4B12-BB1E-8FB7A21E9071}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {295D9C7D-5F05-4B12-BB1E-8FB7A21E9071}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {295D9C7D-5F05-4B12-BB1E-8FB7A21E9071}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {295D9C7D-5F05-4B12-BB1E-8FB7A21E9071}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {295D9C7D-5F05-4B12-BB1E-8FB7A21E9071}.Release|Any CPU.Build.0 = Release|Any CPU
+ {295D9C7D-5F05-4B12-BB1E-8FB7A21E9071}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {295D9C7D-5F05-4B12-BB1E-8FB7A21E9071}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {295D9C7D-5F05-4B12-BB1E-8FB7A21E9071}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Please sign in to comment.
Something went wrong with that request. Please try again.