问题描述:

I'm using node-mysql to create a transaction

  • How can I skip an enclosed/nested query within a transaction and fall through to the next nested query?


Why I'm asking this:

  • Queries within transactions are nested, necessitating that all enclosed queries be run sequentially.
  • Some of the enclosed queries don't need to / can't run since for some queries I don't have any data to use.

E.g in semi-pseudocode:

var query = "some-query";

Query1(query, function() {

var query2 = "another-query";

Query2(query, function() {

// if query2 doesn't need to run how do i fall through to

// this point so I can commitTransaction() ?

commitTransaction();

});

});


I could probably go with something like this:

var query = "some-query";

Query1(query, function() {

if(query2NeedsToRun) {

var query2 = "another-query";

Query2(query, function() {

commitTransaction();

});

} else {

commitTransaction();

}

});

but this style is repetitive and will start looking hideous sooner than later so I'm wondering if there's a more elegant way to go about it.

相关阅读:
Top