diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-07-29 20:24:13 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-07-29 20:24:13 +0200 |
commit | 06c7d6c9e3837131d92e4d44741196ac2feff930 (patch) | |
tree | daa3ee0f8a2b5cfeaa742a33343348ed7fb30fc1 /lib | |
parent | efb54c43e5432875c15e504e7a0668a33d744a22 (diff) | |
download | example-collection-json-db-master.tar.gz example-collection-json-db-master.tar.bz2 example-collection-json-db-master.tar.xz example-collection-json-db-master.zip |
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 = { |