Basically I have two table
User -> id, name , email , fname, lname etc... Device -> id, name, user_id, etc...... here first I will insert data into User table and I get result, from that result how to get the Id of the User table entry so that I can use is as user_id for the entry in device basically user_id is foreign key referring User table
My insert code goes like this
exports.user = function(req,res){ var user_email = req.param('email', null); var user_fname = req.param('fname', null); var user_lname = req.param('lname', null); var user_phone = req.param('phone', null); var user_description = req.param('description',null); var user_data = { table:TABLE_USER, data:{ 'email':user_email, 'fname':user_fname, 'lname':user_lname, 'phone':user_phone, 'description':user_description } } db.insert(user_data,function (result) { //How to get the ID of the last inserted row from result, // get Id and insert in device table res.writeHeader(200, {"Content-Type": "text/plain"}); res.write(result[0] + " "); res.end(); } ); }