Neo4jClient.FsQuotations


Basic usage

Dependencies

Reference this library (dependency on Neo4jClient) and create a Neo4j GraphClient().

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
#r "Neo4jClient.dll"
#r "Neo4jClient.FsQuotations.dll"

open System
open Neo4jClient
open Neo4jClient.FsQuotations

let client = new GraphClient(Uri("http://localhost:7474/db/data"), "neo4j", "Password123")
client.Connect()

Define your model

Declare nodes & relationships in your model (by inheriting from INeo4jNode or INeo4jRelationship interfaces).

Here we are defining users (UserNode), households (HouseholdNode) and the IsResidentOf relationship.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
[<CLIMutable>]
type UserNode = 
    { FacebookId: string }
    interface INeo4jNode

[<CLIMutable>]
type HouseholdNode = 
    { Name: string }
    interface INeo4jNode

type IsResidentOf() =
    interface INeo4jRelationship

Create user nodes

1: 
2: 
3: 
4: 
for id in [ "Okay"; "TT"; "Opwal" ] do
    let user = { FacebookId = id }
    <@ createNode user @>
    |> executeWriteQuery client.Cypher

Get all nodes with specific label

1: 
2: 
3: 
4: 
5: 
6: 
let allUsers =
    <@ let user = declareNode<UserNode>
       matchNode user
       returnResults user @>
    |> executeReadQuery client.Cypher
    |> Seq.toList

Results

[{FacebookId = "Okay";}; {FacebookId = "TT";}; {FacebookId = "Opwal";}]

Get specific user

1: 
2: 
3: 
4: 
5: 
6: 
let userTT =
    <@ let user = declareNode<UserNode>
       matchNode user
       where (user.FacebookId = "TT")
       returnResults user @>
    |> executeReadQuery client.Cypher

Results

seq [{FacebookId = "TT";}]

Create node and relate to it

Create a HouseholdNode, mention that UserNode Opwal has a IsResidentOf relationship with it.

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
do
    let newHousehold: HouseholdNode = { Name = "Paris 10" }
    <@
        let user = declareNode<UserNode>
        matchNode user
        where (user.FacebookId = "Opwal")
        createRightRelation user declareRelationship<IsResidentOf> newHousehold
    @>
    |> executeWriteQuery client.Cypher

List all households where UserNode Opwal resides:

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
let opwalHouseholds =
    <@
    let user = declareNode<UserNode>
    let household = declareNode<HouseholdNode>
    matchRightRelation user declareRelationship<IsResidentOf> household
    where (user.FacebookId = "Opwal")
    returnResults household
    @>
    |> executeReadQuery client.Cypher
    |> Seq.toList

Results

[{Name = "Paris 10";}]
namespace System
namespace Neo4jClient
namespace Neo4jClient.FsQuotations
val client : GraphClient

Full name: Tutorial.client
Multiple items
type GraphClient =
  new : rootUri:Uri * httpClient:IHttpClient -> GraphClient + 2 overloads
  member BatchEndpoint : Uri
  member BeginTransaction : unit -> ITransaction + 1 overload
  member CheckIndexExists : indexName:string * indexFor:IndexFor -> bool
  member Connect : ?configuration:NeoServerConfiguration -> unit
  member Create<'TNode> : node:'TNode * relationships:IEnumerable<IRelationshipAllowingParticipantNode<'TNode>> * indexEntries:IEnumerable<IndexEntry> -> NodeReference<'TNode>
  member CreateIndex : indexName:string * config:IndexConfiguration * indexFor:IndexFor -> unit
  member CreateRelationship<'TSourceNode, 'TRelationship> : sourceNodeReference:NodeReference<'TSourceNode> * relationship:'TRelationship -> RelationshipReference
  member Cypher : ICypherFluentQuery
  member CypherCapabilities : CypherCapabilities
  ...

Full name: Neo4jClient.GraphClient

--------------------
GraphClient(rootUri: Uri, httpClient: Execution.IHttpClient) : unit
GraphClient(rootUri: Uri, ?username: string, ?password: string) : unit
GraphClient(rootUri: Uri, expect100Continue: bool, useNagleAlgorithm: bool, ?username: string, ?password: string) : unit
Multiple items
type Uri =
  new : uriString:string -> Uri + 5 overloads
  member AbsolutePath : string
  member AbsoluteUri : string
  member Authority : string
  member DnsSafeHost : string
  member Equals : comparand:obj -> bool
  member Fragment : string
  member GetComponents : components:UriComponents * format:UriFormat -> string
  member GetHashCode : unit -> int
  member GetLeftPart : part:UriPartial -> string
  ...

Full name: System.Uri

--------------------
Uri(uriString: string) : unit
Uri(uriString: string, uriKind: UriKind) : unit
Uri(baseUri: Uri, relativeUri: string) : unit
Uri(baseUri: Uri, relativeUri: Uri) : unit
GraphClient.Connect(?configuration: NeoServerConfiguration) : unit
property GraphClient.Cypher: Cypher.ICypherFluentQuery
Cypher.ICypherFluentQuery.Match([<ParamArray>] matchText: string []) : Cypher.ICypherFluentQuery
Multiple items
type CLIMutableAttribute =
  inherit Attribute
  new : unit -> CLIMutableAttribute

Full name: Microsoft.FSharp.Core.CLIMutableAttribute

--------------------
new : unit -> CLIMutableAttribute
type UserNode =
  {FacebookId: string;}
  interface INeo4jNode

Full name: Tutorial.UserNode
UserNode.FacebookId: string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = String

Full name: Microsoft.FSharp.Core.string
type INeo4jNode

Full name: Neo4jClient.FsQuotations.INeo4jNode
type HouseholdNode =
  {Name: string;}
  interface INeo4jNode

Full name: Tutorial.HouseholdNode
HouseholdNode.Name: string
Multiple items
type IsResidentOf =
  interface INeo4jRelationship
  new : unit -> IsResidentOf

Full name: Tutorial.IsResidentOf

--------------------
new : unit -> IsResidentOf
type INeo4jRelationship

Full name: Neo4jClient.FsQuotations.INeo4jRelationship
val id : string
val user : UserNode
val createNode : #INeo4jNode -> unit

Full name: Neo4jClient.FsQuotations.CypherQueryGrammar.createNode
val executeWriteQuery : cypher:Cypher.ICypherFluentQuery -> query:Quotations.Expr<unit> -> unit

Full name: Neo4jClient.FsQuotations.QuotationInterpreter.executeWriteQuery
val allUsers : UserNode list

Full name: Tutorial.allUsers
val declareNode<'T (requires 'T :> INeo4jNode)> : #INeo4jNode

Full name: Neo4jClient.FsQuotations.CypherQueryGrammar.declareNode
val matchNode : #INeo4jNode -> unit

Full name: Neo4jClient.FsQuotations.CypherQueryGrammar.matchNode
val returnResults : 'T -> 'T

Full name: Neo4jClient.FsQuotations.CypherQueryGrammar.returnResults
val executeReadQuery : cypher:Cypher.ICypherFluentQuery -> query:Quotations.Expr<'T> -> seq<'T>

Full name: Neo4jClient.FsQuotations.QuotationInterpreter.executeReadQuery
module Seq

from Microsoft.FSharp.Collections
val toList : source:seq<'T> -> 'T list

Full name: Microsoft.FSharp.Collections.Seq.toList
val userTT : seq<UserNode>

Full name: Tutorial.userTT
val where : bool -> unit

Full name: Neo4jClient.FsQuotations.CypherQueryGrammar.where
val newHousehold : HouseholdNode
val createRightRelation : #INeo4jNode -> #INeo4jRelationship -> #INeo4jNode -> unit

Full name: Neo4jClient.FsQuotations.CypherQueryGrammar.createRightRelation
val declareRelationship<'T (requires 'T :> INeo4jRelationship)> : #INeo4jRelationship

Full name: Neo4jClient.FsQuotations.CypherQueryGrammar.declareRelationship
val opwalHouseholds : HouseholdNode list

Full name: Tutorial.opwalHouseholds
val household : HouseholdNode
val matchRightRelation : #INeo4jNode -> #INeo4jRelationship -> #INeo4jNode -> unit

Full name: Neo4jClient.FsQuotations.CypherQueryGrammar.matchRightRelation
Fork me on GitHub