Skip to content

Commit

Permalink
return update query single element
Browse files Browse the repository at this point in the history
  • Loading branch information
afontainec committed Sep 27, 2019
1 parent a054a80 commit 30f0169
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions models/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,12 @@ class Table {
// UDATE
// ################################################

update(input, newValues, options) {
async update(input, newValues, options) {
const whereQuery = typeof input === 'object' ? input : { id: input };
return this.updateWhere(whereQuery, newValues, options);
const query = this.updateWhere(whereQuery, newValues, options);
if (Table.returnAsQuery(options)) return query;
const result = await Table.fetchQuery(query);
return result[0];
}

updateQuery(whereQuery, values, options) {
Expand Down
7 changes: 7 additions & 0 deletions test/integrationTests/tablegateway/update/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ describe('TABLE GATEWAY: update', () => { // eslint-disable-line
assert.notEqual(entry.updated_at.toString(), updated.updated_at.toString());
});

it('update entry', async () => { // eslint-disable-line
const entry = await Coffee.findById(1);
entry.name = 'updated';
const updated = await Coffee.update(1, Utils.cloneJSON(entry));
assert.equal(updated.name, 'updated');
});


it('update entry, without givin the id', async () => { // eslint-disable-line
const entry = {};
Expand Down

0 comments on commit 30f0169

Please sign in to comment.