I am trying to to create transaction in waterline but I am getting this error from OrientDB:
com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException: Cannot find a command executor for the command request: sql.BEGIN
Here is my code:
try {
itemsModel.query("BEGIN", function(err) { if (err) {throw new Error(err);}
itemsModel.update({id:items_ids,status:ACTIVE},{status:INACTIVE})
.exec(function(err, INA_items){ if (err) {throw new Error(err);}
if (INA_items.length != items_ids.length ) {throw new Error({err:RECORD_NOT_FOUND});}
itemsModel.query("COMMIT", function(err) { if (err) {throw new Error({err:MSG.RECORD_NOT_FOUND,title:"ITEMS"});} });
});
});
}
catch(e){
itemsModel.query("ROLLBACK", function(err) {
if (err) {return res.serverError(err);}
return res.serverError(e);
});
}
I also checked BEGIN
command directly in orientdb, but same error.
The question as it stands is mixing several different concepts, I'll try to address one by one:
Waterline's API itself does not support transactions (check issue #755);
It looks like you are using
sails-orientdb
adapter and from it you are executing a raw SQL query;The SQL query you are executing in the second line of your example is just
BEGIN
and that's where OrientDB itself is throwing an error. A transaction SQL query must be something like:Example taken from OrientDB docs.
Alternatively you can use transactions in a more javascript style by making use of the Oriento DB object. Assuming you are using
sails-orientdb
you can get the Oriento DB object like this:Example taken from Oriento tests. Another good example can be found at Oriento's example folder.