Created
July 22, 2014 22:57
-
-
Save qcom/32e45e8e18820529ede4 to your computer and use it in GitHub Desktop.
wrangling that flow control tho
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
db.postClassified = function(data, callback) { | |
var tx = new Transaction(client); | |
async.waterfall([ | |
function(cb) { tx.begin(cb); }, | |
function(result, cb) { | |
if (!data.image_name) return cb(null, null); | |
tx.query("INSERT INTO images (file_name) VALUES ($1) RETURNING id", [data.image_name], cb); | |
}, | |
function(result, cb) { | |
tx.query("INSERT INTO classifieds (email, phone_number, name, posting_title, price, address, image, posting_body, condition) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", | |
[data.email, data.phone_number, data.name, data.posting_title, data.price, data.address, result ? result.rows[0].id : null, data.posting_body, data.condition], cb); | |
}, | |
function(result, cb) { tx.commit(callback); } | |
], callback); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment