Created
August 5, 2018 14:53
-
-
Save tankala/540cdc24ab258cc2e0a4671e8de71962 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 mysql = require('mysql'); | |
var con = mysql.createConnection({ | |
host: "localhost", | |
user: "root", | |
password: "root", | |
database: "Employee" | |
}); | |
con.connect(function (err) { | |
if (err) throw err; | |
console.log('Connected'); | |
}); | |
var getEmpObj = function (empName, callback) { | |
let seletQuery = "SELECT * FROM Employee where employeeName = '" + empName + "'"; | |
con.query(seletQuery, function (err, result, fields) { | |
if (err) throw err; | |
callback(result); | |
}); | |
} | |
var updateEmpAddress = function (empName, empNewAddress, callback) { | |
getEmpObj(empName, function(result) { | |
let empId = result[0].employeeId; | |
let updateAddressQuery = "UPDATE Employee SET employeeAddress = '" + empNewAddress + "' WHERE employeeId = " + empId; | |
con.query(updateAddressQuery, function (err, result) { | |
if (err) throw err; | |
console.log(result.affectedRows + " record(s) updated"); | |
callback(); | |
}); | |
}); | |
} | |
var printEmployeeDetails = function(empName) { | |
getEmpObj(empName, function(result) { | |
console.log(JSON.stringify(result[0])); | |
con.end(); | |
}); | |
} | |
updateEmpAddress("Aditya", "Delhi", printEmployeeDetails("Aditya")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment