Skip to content

Commit 5c57c9d

Browse files
author
Oliver Rumbelow
authored
Merge pull request #34 from holidayextras/v1.2.4
Use READ_COMMITTED transaction isolation
2 parents d6e036f + f0104e4 commit 5c57c9d

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"extends": "eslint:recommended",
23
"globals": {
34
},
45
"env": {

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
- 2016-07-04 - v1.2.4
2+
- 2016-07-04 - Use stricter MySQL transaction isolation READ_COMMITTED
13
- 2016-07-01 - v1.2.3
24
- 2016-07-01 - Deletion errors fail transactions
35
- 2016-06-29 - v1.2.2

lib/sqlHandler.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ SqlStore._getSearchBlock = function(filter) {
306306
SqlStore.prototype._dealWithTransaction = function(done, callback) {
307307
var self = this;
308308
var transactionOptions = {
309-
isolationLevel: Sequelize.Transaction.ISOLATION_LEVELS.READ_UNCOMMITTED,
309+
isolationLevel: Sequelize.Transaction.ISOLATION_LEVELS.READ_COMMITTED,
310310
autocommit: false
311311
};
312312
self.sequelize.transaction(transactionOptions).asCallback(function(err1, transaction) {
@@ -495,29 +495,31 @@ SqlStore.prototype.create = function(request, newResource, finishedCallback) {
495495
/**
496496
Delete a resource, given a resource type and and id.
497497
*/
498-
SqlStore.prototype.delete = function(request, callback) {
498+
SqlStore.prototype.delete = function(request, finishedCallback) {
499499
var self = this;
500500

501-
self.baseModel.findAll({
502-
where: { id: request.params.id },
503-
include: self.relationArray
504-
}).asCallback(function(findErr, results) {
505-
if (findErr) return self._errorHandler(findErr, callback);
501+
self._dealWithTransaction(finishedCallback, function(t, finishTransaction) {
502+
self.baseModel.findAll({
503+
where: { id: request.params.id },
504+
include: self.relationArray
505+
}).asCallback(function(findErr, results) {
506+
if (findErr) return finishTransaction(findErr);
506507

507-
var theResource = results[0];
508+
var theResource = results[0];
508509

509-
// If the resource doesn't exist, error
510-
if (!theResource) {
511-
return callback({
512-
status: "404",
513-
code: "ENOTFOUND",
514-
title: "Requested resource does not exist",
515-
detail: "There is no " + request.params.type + " with id " + request.params.id
516-
});
517-
}
510+
// If the resource doesn't exist, error
511+
if (!theResource) {
512+
return finishTransaction({
513+
status: "404",
514+
code: "ENOTFOUND",
515+
title: "Requested resource does not exist",
516+
detail: "There is no " + request.params.type + " with id " + request.params.id
517+
});
518+
}
518519

519-
theResource.destroy().asCallback(function(deleteErr) {
520-
return callback(deleteErr);
520+
theResource.destroy(t).asCallback(function(deleteErr) {
521+
return finishTransaction(deleteErr);
522+
});
521523
});
522524
});
523525
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsonapi-store-relationaldb",
3-
"version": "1.2.3",
3+
"version": "1.2.4",
44
"description": "Relational data store for jsonapi-server.",
55
"keywords": [
66
"json:api",

0 commit comments

Comments
 (0)