Created
April 16, 2012 19:05
-
-
Save samholmes/2400815 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var db = require('./exports-the-db-connection.js'); | |
var http = require('http'); | |
http.createServer(function(req, res){ | |
if (req.url == '/A') | |
DoA(); | |
else if (req.url == '/B') | |
DoB(); | |
else | |
res.send("Fuck you!"); | |
}).listen(80); | |
function DoA() | |
{ | |
db.query("BEGIN TRANSACTION", function(err, result){ | |
db.query("SELECT * FROM someTable", function(err, result){ | |
var importantInformation = results[0].someImportantColumn; | |
if (importantInformation == 'somethingImportant') | |
{ | |
db.query("INSERT someOtherTable (...) VALUES (...)", function(err, results){ | |
if (err) | |
{ | |
db.query("ROLLBACK", function(){ | |
res.send("Aww..."); | |
}); | |
} | |
else | |
{ | |
db.query("COMMIT", function(){ | |
res.end("Yay!"); | |
}) | |
} | |
}); | |
} | |
else | |
{ | |
res.end(); | |
} | |
}); | |
}); | |
} | |
function DoB(req, res) | |
{ | |
db.query("BEGIN TRANSACTION", function(err){ | |
db.query("UPDATE someTable SET someImportantColumn = 'somethingImporant'", function(){ | |
if (err) | |
{ | |
db.query("ROLLBACK", function(){ | |
res.end('Something bad happened!'); | |
}); | |
} | |
else | |
{ | |
db.query("COMMIT", function(){ | |
res.end("Done did good!"); | |
}) | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment