Skip to content

Instantly share code, notes, and snippets.

@qcom
Created July 22, 2014 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qcom/32e45e8e18820529ede4 to your computer and use it in GitHub Desktop.
Save qcom/32e45e8e18820529ede4 to your computer and use it in GitHub Desktop.
wrangling that flow control tho
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