You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bolt V3 allows additional metadata to be attached to BEGIN and RUN
messages. This makes it possible to expose a couple new features in
the API.
Auto-commit transactions executed via `Session#run()` now support
bookmarks. In previous protocol versions, there was no good place in
the RUN message to attach bookmarks. Auto-commit transactions will
now use bookmarks given in `Driver#session(bookmarkOrBookmarks)`
function and participate in causal chaining within a session.
Transactions functions, auto-commit, and explicit transactions now
accept a configuration object with transaction timeout and metadata.
Example of a configuration object:
```
{
timeout: 3000, // 3 seconds
metadata: {key1: 42, key2: '42'}
}
```
where timeout is specified in milliseconds and metadata is an object
containing valid Cypher types.
Transactions that execute longer than the configured timeout will be
terminated by the database. This functionality allows limiting
query/transaction execution time. Specified timeout overrides the
default timeout configured in the database using
`dbms.transaction.timeout` setting. Examples:
Specified transaction metadata will be attached to the executing
transaction and visible in the output of `dbms.listQueries` and
`dbms.listTransactions` procedures. It will also get logged to the
`query.log`. This functionality makes it easier to tag transactions
and is equivalent to `dbms.setTXMetaData` procedure.
Examples:
```
var driver = neo4j.driver(...);
var session = driver.session();
var txConfig = {
timeout: 5000, // 5 seconds
metadata: {
type: 'My Query',
application: 'My App neo4j#1',
sequence_number: 42
}
};
// transaction configuration for auto-commit transaction
session.run('RETURN $x', {x: 42}, txConfig)
.then(...)
.catch(...)
// transaction configuration for explicit transaction
var tx = session.beginTransaction(txConfig);
tx.run(...);
// transaction configuration for read transaction function
session.readTransaction(tx => tx.run('RETURN $x', {x: 42}), txConfig)
.then(...)
.catch(...)
// transaction configuration for write transaction function
session.writeTransaction(tx => tx.run('RETURN $x', {x: 42}), txConfig)
.then(...)
.catch(...)
```
0 commit comments