View Source eneo4j (eneo4j v1.0.0)

This module provides functions to begin, run, commit and rollback transactions, and statement builder. It is a main API for this library.

Link to this section Summary

Functions

The same as begin_and_commit_transaction(Statements, 60000).

Use this function to begin and commit a transaction in a single HTTP request.

The same as begin_transaction(Statements, 60000).

Use this function to begin transaction

This function works the same as eneo4j:build_statement(Query, Params, false)

This function allows to build a statement and include query stats.
The same as commit_transaction(Statements, CommitLink, 60000).

Use this function commit a transaction.

Use this function to extract information about neo4j version, distribution, etc.

The same as keep_alive_transaction(RunLink, 60000).

Use this function to keep transaction alive. It will timeout after 60 seconds (by default).

The same as rollback_transaction(RollbackLink, 60000).

Use this function rollback a transaction.

The same as run_queries_inside_transaction(Statements, RunLink, 60000).

Use this function to begin transaction.

Link to this section Types

Link to this type

discovery_api_response/0

View Source

Specs

discovery_api_response() :: #{binary() := binary()}.

Specs

query_result() :: {ok, response()} | {error, any()}.
Link to this type

query_result_with_commit/0

View Source

Specs

query_result_with_commit() :: {ok, response_with_commit()} | {error, any()}.

Specs

response() :: #{binary() := any() | [any(), ...]}.
Link to this type

response_with_commit/0

View Source

Specs

response_with_commit() :: #{binary() := any()} | #{binary() := list()}.

Specs

statement() :: eneo4j_worker:statement().

Specs

statements() :: eneo4j_worker:statements().

Link to this section Functions

Link to this function

begin_and_commit_transaction(Statements)

View Source

Specs

begin_and_commit_transaction(statements()) -> query_result().
The same as begin_and_commit_transaction(Statements, 60000).
Link to this function

begin_and_commit_transaction(Statements, Timeout)

View Source

Specs

begin_and_commit_transaction(statements(), timeout()) -> query_result().

Use this function to begin and commit a transaction in a single HTTP request.

   Query = <<"CREATE (n:Person { name: $name, title: $title });">>,
  
   % Provide params if needed:
   ParamsAndy = #{
    <<"name">> => <<"Andy">>,
    <<"title">> => <<"Developer">>
    },
  
   % Build a statement:
   Statement = eneo4j:build_statement(Query, ParamsAndy),
   Execute the query
   {ok, Result} = eneo4j:begin_and_commit_transaction([Statement], 30000).
Link to this function

begin_transaction(Statements)

View Source

Specs

begin_transaction(statements()) -> query_result_with_commit().
The same as begin_transaction(Statements, 60000).
Link to this function

begin_transaction(Statements, Timeout)

View Source

Specs

begin_transaction(statements(), timeout()) -> query_result_with_commit().

Use this function to begin transaction

   QueryGetPersonsNames = <<"MATCH (n:Person) RETURN n.name">>,
   Statement = eneo4j:build_statement(QueryGetPersonsNames, #{}),
   {ok, Result} = eneo4j:begin_transaction([Statement]),
Link to this function

build_statement(Query, Params)

View Source

Specs

build_statement(binary(), #{binary() => any()}) -> statement().

This function works the same as eneo4j:build_statement(Query, Params, false)

   Query = <<"MATCH (n) WHERE n.name = $name RETURN n">>,
   Params = #{<<"name">> => <<"Andy">>},
   Statement = eneo4j:build_statement(Query, Params),
Link to this function

build_statement(Query, Params, IncludeStats)

View Source

Specs

build_statement(binary(), #{binary() => any()}, boolean()) -> statement().
This function allows to build a statement and include query stats.
Link to this function

commit_transaction(Statements, CommitLink)

View Source

Specs

The same as commit_transaction(Statements, CommitLink, 60000).
Link to this function

commit_transaction(Statements, CommitLink, Timeout)

View Source

Specs

Use this function commit a transaction.

    {ok, Response} = eneo4j:begin_transaction([Statement]),
    {ok, CommitLink} = eneo4j_response:get_commit_transaction_link(Response),
  
    % You may add statements when committing a transaction
  
    Statements = [],
    {ok, Result} = eneo4j:commit_transaction(Statements, CommitLink),

Specs

discovery_api() -> discovery_api_response().

Use this function to extract information about neo4j version, distribution, etc.

It may be used to check the connection and if the database wa configured correctly.
Link to this function

keep_alive_transaction(RunLink)

View Source

Specs

The same as keep_alive_transaction(RunLink, 60000).
Link to this function

keep_alive_transaction(RunLink, Timeout)

View Source

Specs

keep_alive_transaction(eneo4j_response:run_queries_link(), timeout()) ->
                          query_result_with_commit().

Use this function to keep transaction alive. It will timeout after 60 seconds (by default).

   {ok, BeginResponse} = eneo4j:begin_transaction([]),
  
   Query = <<"MATCH (n:Person) RETURN n.name">>,
   Statement = eneo4j:build_statement(Query, #{}),
  
   timer:sleep(timer:seconds(40)),
  
   {ok, RunLink} = eneo4j_response:get_run_queries_link(BeginResponse),
   {ok, RunResponse} = eneo4j:keep_alive_transaction(RunLink),
  
   % Normally transaction would timeout here,
   % but thanks to eneo4j:keep_alive_transaction/1 call it will remain opened.
  
   timer:sleep(timer:seconds(40)),
  
   % Run queries inside transaction many times:
  
   {ok, RunLink2} = eneo4j_response:get_run_queries_link(RunResponse),
   {ok, Result} = eneo4j:run_queries_inside_transaction([Statement], RunLink2),
Link to this function

rollback_transaction(RollbackLink)

View Source

Specs

The same as rollback_transaction(RollbackLink, 60000).
Link to this function

rollback_transaction(RollbackLink, Timeout)

View Source

Specs

rollback_transaction(eneo4j_response:rollback_transaction_link(), timeout()) ->
                        query_result_with_commit().

Use this function rollback a transaction.

    {ok, Response} = eneo4j:begin_transaction([Statement]),
    {ok, RollbackLink} = eneo4j_response:get_rollback_transaction_link(Response),
  
    % You may add statements when committing a transaction
  
    Statements = [],
    {ok, Result} = eneo4j:rollback_transaction(Statements, RollbackLink),
Link to this function

run_queries_inside_transaction(Statements, RunLink)

View Source

Specs

run_queries_inside_transaction(statements(), eneo4j_response:run_queries_link()) ->
                                  query_result_with_commit().
The same as run_queries_inside_transaction(Statements, RunLink, 60000).
Link to this function

run_queries_inside_transaction(Statements, RunLink, Timeout)

View Source

Specs

run_queries_inside_transaction(statements(), eneo4j_response:run_queries_link(), timeout()) ->
                                  query_result_with_commit().

Use this function to begin transaction.

   {ok, BeginResponse} = eneo4j:begin_transaction([]),
  
   Query = <<"MATCH (n:Person) RETURN n.name">>,
   Statement = eneo4j:build_statement(Query, #{}),
  
   {ok, RunLink} = eneo4j_response:get_run_queries_link(BeginResponse),
   {ok, RunResponse} = eneo4j:run_queries_inside_transaction([Statement], RunLink),
  
   % Run queries inside transaction many times:
   {ok, RunLink2} = eneo4j_response:get_run_queries_link(RunResponse),
   {ok, Result} = eneo4j:run_queries_inside_transaction([Statement], RunLink2),