package neodriver
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page
Convenience module aggregating the public Neo4j driver API
Install
dune-project
Dependency
Authors
Maintainers
Sources
0.1.2.tar.gz
md5=ddea08803bc57d4928a9f13de54461ae
sha512=d5dc0b69af7972944332b243a28ccc2b15adb62ee9129023cf5a3ea57faf13b048e79579fe03b73d0a17c8c84e32ab92f27de6e2579c59ce4bb5bf8b5131100c
doc/quickstart.html
Quickstart
This page walks you through connecting to Neo4j from OCaml and running your first query with the neodriver packages.
Prerequisites
- OCaml >= 5.2 and dune >= 3.13 (via opam or a system package manager).
- A running Neo4j instance, reachable at
bolt://localhost:7687(the Bolt port), with a user that can run queries.
Adding the driver to your project
Install the packages from opam:
opam install neodriver neodriver_eio
When developing against a local checkout of the driver, pin the packages instead:
cd ocaml-neo4j-driver opam pin add neodriver_packstream . opam pin add neodriver_core . opam pin add neodriver_eio . opam pin add neodriver . opam install neodriver neodriver_eio eio_main
eio_main provides the Eio_main.run entry point used by the example below.
Declare the dependency in your executable's dune file:
(executable (name hello) (libraries neodriver neodriver_eio eio_main))
A minimal program
Save the following as hello.ml:
open Neodriver
let () =
Eio_main.run (fun env ->
let net = Eio.Stdenv.net env in
let clock = Eio.Stdenv.mono_clock env in
Eio.Switch.run (fun sw ->
let session =
match
Driver.connect ~uri:"bolt://localhost:7687"
~auth:(Conn.basic_auth ~credentials:"your_password" ())
net clock sw
with
| Ok session -> session
| Error error -> failwith (Errors.to_string error)
in
(match Session.run session ~query:"RETURN 1 AS n" ~parameters:[] with
| Ok result -> (
match Neo4jResult.values result with
| Ok [ [ Values.Int n ] ] -> Printf.printf "n = %Ld\n%!" n
| _ -> ())
| Error error -> failwith (Errors.to_string error));
Session.close session))Run it:
dune exec ./hello.exe
You should see n = 1.
What is going on
Driver.connectparses the URI and returns a lazily connectingSession: no server contact happens until the first query, so the error returned is the same whether the URI is invalid, the server is unreachable or the credentials are wrong. It returns aSession.t— there is no connection pool yet, so eachconnectproduces one session that owns its own connection.Conn.basic_authbuilds the authentication token (default principalneo4j; only thebasicscheme is supported so far).Session.runsends the query and returns a lazily streamedNeo4jResult.Neo4jResult.valuesdrains it into a list of records, each a list ofValues.t;Neo4jResult.consumeinstead returns theSummaryof the query.- The
swswitch passed toDriver.connecthosts the session's connection attempt, so it must outlive the session (it does here, as the session is closed insideEio.Switch.run). - Routing (
neo4j://) is not implemented yet: aneo4j://URI fails on first use with aService_unavailableerror. Onlybolt://,bolt+s://(TLS with certificate validation) andbolt+ssc://(TLS, self-signed allowed) are supported.
Next steps
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page