aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-07-29 20:24:13 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-07-29 20:24:13 +0200
commit06c7d6c9e3837131d92e4d44741196ac2feff930 (patch)
treedaa3ee0f8a2b5cfeaa742a33343348ed7fb30fc1 /lib
parentefb54c43e5432875c15e504e7a0668a33d744a22 (diff)
downloadexample-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
o Adding updating of employees.HEADmaster
Diffstat (limited to 'lib')
-rw-r--r--lib/dao.js23
1 files changed, 23 insertions, 0 deletions
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 = {