I'm following the datastore docs, and trying to do an example save in a transaction, but the code just hangs.
I am guessing that the docs for transactions is incomplete. Please inform me of the actual way to do transactions, and update the docs a bit (add at least 1 transaction example?)
the following code never executes any of the callbacks. running this example outside a transaction works fine.
// Save data to your dataset.
var blogPostData = {
title: 'How to make the perfect homemade pasta',
author: 'Andrew Chilton',
isDraft: true
};
var blogPostKey = dataset.key('BlogPost');
dataset.runInTransaction((transaction, done) => {
transaction.save({
key: blogPostKey,
data: blogPostData
}, function (err) {
if (err) {
return transaction.rollback((err, apiResponse) => {
console.log("in xact rollback callback 1", { err, apiResponse });
});
}
console.log("preview save 1", arguments);
// `blogPostKey` has been updated with an ID so you can do more operations
// with it, such as an update.
blogPostData.isDraft = false;
transaction.save({
key: blogPostKey,
data: blogPostData
}, function (err) {
if (err) {
return transaction.rollback((err, apiResponse) => {
console.log("in xact rollback callback 2", { err, apiResponse });
});
}
// The blog post is now published!
console.log("preview save 2 DONE!", arguments);
done();
});
});
}, (err) => {
console.log("xact insert err", err);
});
I'm following the datastore docs, and trying to do an example save in a transaction, but the code just hangs.
I am guessing that the docs for transactions is incomplete. Please inform me of the actual way to do transactions, and update the docs a bit (add at least 1 transaction example?)
the following code never executes any of the callbacks. running this example outside a transaction works fine.