-
Notifications
You must be signed in to change notification settings - Fork 52
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
Transaction is not working #144
Comments
Hello, |
Hi @alickmail I just released Once you update the gstore version (make sure you update how you instantiate gstore, there is a breaking change), you will need to make a small change in your code: ...
function transferCoins(fromUser, toUser, amount) {
const transaction = gstore.transaction();
return transaction.run()
.then(async () => {
await User.update(fromUser.entityKey.id, {
coins: fromUser.coins - amount,
}, null, null, transaction);
await User.update(toUser.entityKey.id, {
coins: toUser.coins + amount,
}, null, null, transaction);
return transaction.commit();
}).catch((err) => {
transaction.rollback();
throw err;
});
}
// ----------------------------
// Or without "async" and "waiting" if you already have fetched the entity data previously
function transferCoins(fromUser, toUser, amount) {
const transaction = gstore.transaction();
return transaction.run()
.then(() => {
const fromUserUpdated = new User({
...fromUser.entityData,
coins: fromUser.coins - amount},
fromUser.entityKey.id
);
const toUserUpdated = new User({
...toUser.entityData,
coins: toUser.coins + amount},
toUser.entityKey.id
);
fromUserUpdated.save(transaction);
toUserUpdated.save(transaction);
return transaction.commit();
}).catch((err) => {
transaction.rollback();
throw err;
});
} |
You use case made me think that it'd be useful to add a sort of Be careful that you might run in a race condition if 2 requests fetch the Closing the issue. Feel free to reopen if you still have a problem. |
I am not able to use transaction for model update, the
transaction.commit().then()
is fired, but the data on google console did not updated.I have tried the Model.update function without using transaction, the data on google console is updated successfully
i am following the example from gitbook:
Link
Here is update model code:
Here is the model file
Please help, thanks!
The text was updated successfully, but these errors were encountered: