Using live transactions can have some benefits :
- Having a result of the transaction for each statement
- Replicating batch process and benefit of the Cypher Transactional endpoint
- Using the same transaction between multiple http requests
How-to:
- Open the transaction, you don't have to care about transaction ids etc.., all is handled by the transaction object you receive back
$transaction = $client->createTransaction();
// Returns a \Neoxygen\NeoClient\Transaction\Transaction object
- Add statements to the transaction :
$query = 'CREATE (user:User {id: {user_id}, name: {user_name} }) RETURN user';
$params = ['user_id' => 3479, 'user_name' => 'Angus Young'];
$result = $transaction->pushQuery($query, $params);
// You receive a result object back, meaning you can reuse the properties of this object in further statements. Note that the
// transaction is not committed yet
- Commit the transaction :
try {
$transaction->commit();
$results = $transaction->getResults(); // results of all the statements of this transaction
} catch (\Neoxygen\NeoClient\Exception\Neo4jException $e) {
// do what you want
throw new $e;
}