From 06c7d6c9e3837131d92e4d44741196ac2feff930 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 29 Jul 2012 20:24:13 +0200 Subject: o Adding updating of employees. --- lib/dao.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib') diff --git a/lib/dao.js b/lib/dao.js index 8fd6efd..969bb8e 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -8,6 +8,7 @@ function EmployeeDao(con) { this.getEmployee = getEmployee; this.deleteEmployee = deleteEmployee; this.insertEmployee = insertEmployee; + this.updateEmployee = updateEmployee; } function getDepartments(pager, cb) { @@ -125,6 +126,28 @@ function deleteEmployee(emp_no, cb) { }); } +function updateEmployee(emp_no, object, cb) { + var query = []; + var values = []; + var i = 1; + _.each(object, function(value, key) { + query.push(key + '=$' + i++); + values.push(value); + }); + query = 'UPDATE employees SET ' + query.join(', ') + ' WHERE emp_no=$' + i; + values.push(emp_no); + + /* + console.log('object', object); + console.log('query', query); + console.log('values', values); + */ + this.con.query(query, values, function(err, rs) { + if(err) return cb(err); + cb(undefined, rs.rowCount); + }); +} + function insertEmployee(birth_date, first_name, last_name, gender, hire_date, cb) { var con = this.con; var insert_employee = { -- cgit v1.2.3