Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace returnVals by returnChanges #13

Merged
merged 2 commits into from
May 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions todo-angular-express-promise/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function create(req, res, next) {
var todo = req.body;
todo.createdAt = r.now(); // Set the field `createdAt` to the current time

r.table('todos').insert(todo, {returnVals: true}).run(req._rdbConn).then(function(result) {
r.table('todos').insert(todo, {returnChanges: true}).run(req._rdbConn).then(function(result) {
if (result.inserted !== 1) {
handleError(res, next)(new Error("Document was not inserted."));
}
Expand All @@ -60,7 +60,7 @@ function create(req, res, next) {
function update(req, res, next) {
var todo = req.body;
if ((todo != null) && (todo.id != null)) {
r.table('todos').get(todo.id).update(todo, {returnVals: true}).run(req._rdbConn).then(function(result) {
r.table('todos').get(todo.id).update(todo, {returnChanges: true}).run(req._rdbConn).then(function(result) {
res.send(JSON.stringify(result.new_val));
}).error(handleError(res))
.finally(next);
Expand Down
4 changes: 2 additions & 2 deletions todo-angular-koa/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function* create(next) {
try{
var todo = yield parse(this);
todo.createdAt = r.now(); // Set the field `createdAt` to the current time
var result = yield r.table('todos').insert(todo, {returnVals: true}).run(this._rdbConn);
var result = yield r.table('todos').insert(todo, {returnChanges: true}).run(this._rdbConn);

todo = result.new_val; // todo now contains the previous todo + a field `id` and `createdAt`
this.body = JSON.stringify(todo);
Expand All @@ -84,7 +84,7 @@ function* update(next) {
throw new Error("The todo must have a field `id`.");
}

var result = yield r.table('todos').get(todo.id).update(todo, {returnVals: true}).run(this._rdbConn);
var result = yield r.table('todos').get(todo.id).update(todo, {returnChanges: true}).run(this._rdbConn);
this.body = JSON.stringify(result.new_val);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line needs updating I believe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which part of it?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. I believe it should be result.changes[0].new_val -- but i'm not sure of the impact of only looking at [0]

and sometimes, there is no new_val property if there was no change (ie: they made the call but it was with identical data as what already was in the db.

I also noticed I didn't need to JSON.stringify. I think koa will do that for us.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right! Didn't think about it enough. I opened #14 so we don't forget changing that.

}
catch(e) {
Expand Down