Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cpruijsen committed Aug 13, 2016
2 parents 4f40716 + 8fa1f67 commit 2dd3a3c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/db/stork/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ class Model {
});
}

// TODO
updateOrCreate(obj) {

return this.db.find(obj)
.then((foundObj) => {
if (!foundObj) {
return this.create(obj);
} else {
return update(foundObj, obj);
}
});
}

create(obj) {
return this.db.insert(obj).into(this.table).returning(...Object.keys(obj));
return this.db.insert(obj).into(this.table).returning(...Object.keys(obj), 'id');
}

save(obj) {
Expand All @@ -48,7 +54,7 @@ class Model {
return this.db(this.table)
.update(updateObj, [...updateObj])
.where(criteriaObj)
.returning(...Object.keys(updateObj));
.returning(...Object.keys(updateObj), 'id');
}

remove(obj) {
Expand Down

0 comments on commit 2dd3a3c

Please sign in to comment.