Home Reference Source
import Session from 'neo4j-driver-core/lib/session.js'
public class | source

Session

A Session instance is used for handling the connection and sending queries through the connection. In a single session, multiple queries will be executed serially. In order to execute parallel queries, multiple sessions are required.

Method Summary

Public Methods
public
public

Begin a new transaction in this session.

public

close(): Promise

Close this session.

public

executeRead(transactionWork: function(tx: ManagedTransaction): Promise, transactionConfig: TransactionConfig): Promise

Execute given unit of work in a READ transaction.

public

executeWrite(transactionWork: function(tx: ManagedTransaction): Promise, transactionConfig: TransactionConfig): Promise

Execute given unit of work in a WRITE transaction.

public

lastBookmarks(): string[]

Return the bookmarks received following the last completed Transaction.

public

run(query: mixed, parameters: Object, transactionConfig: TransactionConfig, parameterRules: Rules): Result

Run Cypher query Could be called with a query object i.e.: {text: "MATCH ...", parameters: {param: 1}} or with the query and parameters as separate arguments.

Public Methods

public [Symbol.asyncDispose]() source

public beginTransaction(transactionConfig: TransactionConfig): TransactionPromise source

Begin a new transaction in this session. A session can have at most one transaction running at a time, if you want to run multiple concurrent transactions, you should use multiple concurrent sessions.

While a transaction is open the session cannot be used to run queries outside the transaction.

Params:

NameTypeAttributeDescription
transactionConfig TransactionConfig
  • optional

Configuration for the new auto-commit transaction.

Return:

TransactionPromise

New Transaction.

public close(): Promise source

Close this session.

Return:

Promise

public executeRead(transactionWork: function(tx: ManagedTransaction): Promise, transactionConfig: TransactionConfig): Promise source

Execute given unit of work in a READ transaction.

Transaction will automatically be committed unless the given function throws or returns a rejected promise. Some failures of the given function or the commit itself will be retried with exponential backoff with initial delay of 1 second and maximum retry time of 30 seconds. Maximum retry time is configurable via driver config's maxTransactionRetryTime property in milliseconds.

NOTE: Because it is an explicit transaction from the server point of view, Cypher queries using "CALL {} IN TRANSACTIONS" or the older "USING PERIODIC COMMIT" construct will not work (call Session#run for these).

Params:

NameTypeAttributeDescription
transactionWork function(tx: ManagedTransaction): Promise

Callback that executes operations against a given Transaction.

transactionConfig TransactionConfig
  • optional

Configuration for all transactions started to execute the unit of work.

Return:

Promise

Resolved promise as returned by the given function or rejected promise when given function or commit fails.

public executeWrite(transactionWork: function(tx: ManagedTransaction): Promise, transactionConfig: TransactionConfig): Promise source

Execute given unit of work in a WRITE transaction.

Transaction will automatically be committed unless the given function throws or returns a rejected promise. Some failures of the given function or the commit itself will be retried with exponential backoff with initial delay of 1 second and maximum retry time of 30 seconds. Maximum retry time is configurable via driver config's maxTransactionRetryTime property in milliseconds.

NOTE: Because it is an explicit transaction from the server point of view, Cypher queries using "CALL {} IN TRANSACTIONS" or the older "USING PERIODIC COMMIT" construct will not work (call Session#run for these).

Params:

NameTypeAttributeDescription
transactionWork function(tx: ManagedTransaction): Promise

Callback that executes operations against a given Transaction.

transactionConfig TransactionConfig
  • optional

Configuration for all transactions started to execute the unit of work.

Return:

Promise

Resolved promise as returned by the given function or rejected promise when given function or commit fails.

public lastBookmarks(): string[] source

Return the bookmarks received following the last completed Transaction.

Return:

string[]

A reference to a previous transaction.

public run(query: mixed, parameters: Object, transactionConfig: TransactionConfig, parameterRules: Rules): Result source

Run Cypher query Could be called with a query object i.e.: {text: "MATCH ...", parameters: {param: 1}} or with the query and parameters as separate arguments.

This is an auto-commit query, meaning the server will commit the results without further input.

The transaction is guaranteed to be committed anywhere between the start of it (i.e., calling Session#run) and fully consuming the returned Result. The Result can be consumed as a promise or lazily using Result#subscribe.

If the code moves on (i.e., by calling Session#close or by starting another session) before the Result is fully consumed, it will be consumed in the background. However, in this case any error that occurs will be swallowed silently. Therefore, it is reccomended to always fully consume Results from Session.run.

Params:

NameTypeAttributeDescription
query mixed

Cypher query to execute

parameters Object

Map with parameters to use in query

transactionConfig TransactionConfig
  • optional

Configuration for the new auto-commit transaction.

parameterRules Rules
  • optional

Rules to typecheck and/or map the parameter object. Must not be provided as a separate argument if an Object is passed as first argument

Return:

Result

New Result.