Home Reference Source
import Session from 'neo4j-driver/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

Begin a new transaction in this session.

public

async close(): Promise

Close this session.

public

lastBookmark(): string[]

Return the bookmark received following the last completed Transaction.

public

readTransaction(transactionWork: function(tx: Transaction): Promise, transactionConfig: TransactionConfig): Promise

Execute given unit of work in a READ transaction.

public

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

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

public

writeTransaction(transactionWork: function(tx: Transaction): Promise, transactionConfig: TransactionConfig): Promise

Execute given unit of work in a WRITE transaction.

Public Methods

public beginTransaction(transactionConfig: TransactionConfig): Transaction 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:

Transaction

New Transaction.

public async close(): Promise source

Close this session.

Return:

Promise

public lastBookmark(): string[] source

Return the bookmark received following the last completed Transaction.

Return:

string[]

A reference to a previous transaction.

public readTransaction(transactionWork: function(tx: Transaction): 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.

Params:

NameTypeAttributeDescription
transactionWork function(tx: Transaction): 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 run(query: mixed, parameters: Object, transactionConfig: TransactionConfig): Result source

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

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.

Return:

Result

New Result.

public writeTransaction(transactionWork: function(tx: Transaction): 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.

Params:

NameTypeAttributeDescription
transactionWork function(tx: Transaction): 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.