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.connect parses 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 a Session.t — there is no connection pool yet, so each connect produces one session that owns its own connection.
Conn.basic_auth builds the authentication token (default principal neo4j; only the basic scheme is supported so far).
Session.run sends the query and returns a lazily streamed Neo4jResult. Neo4jResult.values drains it into a list of records, each a list of Values.t; Neo4jResult.consume instead returns the Summary of the query.
The sw switch passed to Driver.connect hosts the session's connection attempt, so it must outlive the session (it does here, as the session is closed inside Eio.Switch.run).
Routing (neo4j://) is not implemented yet: a neo4j:// URI fails on first use with a Service_unavailable error. Only bolt://, bolt+s:// (TLS with certificate validation) and bolt+ssc:// (TLS, self-signed allowed) are supported.
Next steps
The usage page covers sessions, transactions, value types and error handling.