OrientDB: Failure inside batch script doesn't rollback

34 Views Asked by At
begin;
let t = create Vertex Ticket set ticketType = "premium"
create edge For from $t to #42:1;
create edge At from $t to #37:0;
create edge Created from #46:1 to $t;
commit;

In the above batch script while creating edge 'Created' (statement no:5) the record #46:1 is not found (deleted) so an exception is thrown. How do I rollback the transaction in this case?

P.S: I'm using orientjs library

1

There are 1 best solutions below

0
Naveen Anto On

Initialize the transaction on session, then do the batch update (without begin and commit) and either commit or rollback.

try {
  session.begin()
  await session.batch(...)
  session.commit(..)
} catch (e) {
  session.tx().rollback();
}