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

Session

A Session instance is used for handling the connection and sending statements through the connection.

Constructor Summary

Public Constructor
public

constructor(mode: string, connectionProvider: ConnectionProvider, bookmark: Bookmark, config: Object)

Method Summary

Public Methods
public

Begin a new transaction in this session.

public

close(callback: function())

Close this session.

public

lastBookmark(): string | null

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(statement: mixed, parameters: Object, transactionConfig: TransactionConfig): Result

Run Cypher statement Could be called with a statement object i.e.: {text: "MATCH ...", parameters: {param: 1}} or with the statement 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 Constructors

public constructor(mode: string, connectionProvider: ConnectionProvider, bookmark: Bookmark, config: Object) source

Params:

NameTypeAttributeDescription
mode string

the default access mode for this session.

connectionProvider ConnectionProvider

the connection provider to acquire connections from.

bookmark Bookmark

the initial bookmark for this session.

config Object
  • optional
  • default: {}

this driver configuration.

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 statements outside the transaction.

Params:

NameTypeAttributeDescription
transactionConfig TransactionConfig
  • optional

configuration for the new auto-commit transaction.

Return:

Transaction

New Transaction

public close(callback: function()) source

Close this session.

Params:

NameTypeAttributeDescription
callback function()

Function to be called after the session has been closed

public lastBookmark(): string | null source

Return the bookmark received following the last completed Transaction.

Return:

string | null

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(statement: mixed, parameters: Object, transactionConfig: TransactionConfig): Result source

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

Params:

NameTypeAttributeDescription
statement mixed

Cypher statement to execute

parameters Object

Map with parameters to use in statement

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.