The Perl Advent Calendar needs more articles for 2022. Submit your idea today!

NAME

Neo4j::Driver::Session - Context of work for database interactions

VERSION

version 0.31

SYNOPSIS

 use Neo4j::Driver;
 $session = Neo4j::Driver->new->basic_auth(...)->session;
 
 # explicit transaction
 $transaction = $session->begin_transaction;
 
 # autocommit transaction
 $result = $session->run('MATCH (m:Movie) RETURN m.name, m.year');

DESCRIPTION

Provides a context of work for database interactions.

A Session hosts a series of transactions carried out against a database. Within the database, all statements are carried out within a transaction. Within application code, however, it is not always necessary to explicitly begin a transaction. If a statement is run directly against a Session, the server will automatically BEGIN and COMMIT that statement within its own transaction. This type of transaction is known as an autocommit transaction.

Explicit transactions allow multiple statements to be committed as part of a single atomic operation and can be rolled back if necessary.

Only one open transaction per session at a time is supported. To work with multiple concurrent transactions, simply use more than one session. On http: and https: connections, you can alternatively enable concurrent transactions within the same session through a config option (currently experimental); see "Concurrent transactions in HTTP sessions" in Neo4j::Driver for details.

To create a new session, call "session" in Neo4j::Driver.

METHODS

Neo4j::Driver::Session implements the following methods.

begin_transaction

 $transaction = $session->begin_transaction;

Begin a new explicit Transaction.

run

 $result = $session->run('...');

Run and commit a statement using an autocommit transaction and return the Result.

This method is semantically exactly equivalent to the following code, but is faster because it doesn't require an extra server roundtrip to commit the transaction.

 $transaction = $session->begin_transaction;
 $result = $transaction->run('...');
 $transaction->commit;

server

 $address = $session->server->address;
 $version = $session->server->agent;

Obtain the ServerInfo, consisting of the host, port, protocol and Neo4j version.

EXPERIMENTAL FEATURES

Neo4j::Driver::Session implements the following experimental features. These are subject to unannounced modification or removal in future versions. Expect your code to break if you depend upon these features.

Concurrent transactions

 %config = ( uri => 'http://...', concurrent_tx => 1 );
 $session = Neo4j::Driver->new(\%config)->session;
 $tx1 = $session->begin_transaction;
 $tx2 = $session->begin_transaction;
 $tx3 = $session->run(...);

Since HTTP is a stateless protocol, the Neo4j HTTP API effectively allows multiple concurrently open transactions without special client-side considerations. This driver exposes this feature to the client and will continue to do so, but the interface is not yet finalised. See "Concurrent transactions in HTTP sessions" in Neo4j::Driver for further details.

The Bolt protocol does not support concurrent transactions (sometimes known as "nested transactions") within the same session.

SECURITY CONSIDERATIONS

Both Session as well as Transaction objects internally hold references to the authentication credentials used to contact the Neo4j server. Objects of these classes should therefore not be passed to untrusted modules. However, objects of the ServerInfo class and the Result class (if detached) do not contain a reference to these credentials and are safe in this regard.

SEE ALSO

AUTHOR

Arne Johannessen <ajnn@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2016-2022 by Arne Johannessen.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)