diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dao.js | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -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 = { |