After some testing, the best place to put it seems to be the second option. What we have now looks like this:
var query = new self.dialect.Query(connection, self, options);
return retry(function() {
return query.run(sql, bindParameters).finally(function() {
if (options.transaction) return;
return self.connectionManager.releaseConnection(connection);
});
}, {
max: 15 // will turn into variable
});
I would like to further wrap that in some "only-retry-if" code so we only retry on BUSY error state. Do you think the best idea would be to add a callback to the retry() function that can do the retry-or-not checking?