使用nodejs的gcloud数据存储事务问题
gcloud Datastore transaction issue using nodejs
我正在使用 nodejs 联系 google 数据存储。这是我的代码:
dataset.runInTransaction(function(transaction, done,err) {
// From the `transaction` object, execute dataset methods as usual.
// Call `done` when you're ready to commit all of the changes.
transaction.save(entities, function(err) {
if(err){
console.log("ERROR TRNASCTION");
transaction.rollback(done);
return;
}else{
console.log("TRANSACTION SUCCESS!");
done();
}
});
});
如果保存不成功,我希望事务回滚,如果是,我希望它提交。我面临的问题是它们似乎都不是 运行ning,只是控制台上没有输出。没有任何东西被发送到我的数据库,所以我假设至少 'if(err)' 条件会 运行 但事实并非如此。我是 glcoud 的新手,所以我不确定我是否在这里做错了什么?我正在关注 https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.26.0/datastore/transaction?method=save.
的文档
在事务上下文中,save
方法实际上不需要回调。在您调用 done()
之前,您要保存的内容会排队。调用 done
将提交事务。
然后您可以在传递给 runInTransaction
的第二个函数中处理来自提交操作的错误。有关示例,请参阅 https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.26.0/datastore/dataset?method=runInTransaction。
--
仅提及这一点,因为它与回滚部分有关:https://github.com/GoogleCloudPlatform/gcloud-node/issues/633 -- 我们正在等待升级到 Datastore 的 API,然后再解决该问题。
我正在使用 nodejs 联系 google 数据存储。这是我的代码:
dataset.runInTransaction(function(transaction, done,err) {
// From the `transaction` object, execute dataset methods as usual.
// Call `done` when you're ready to commit all of the changes.
transaction.save(entities, function(err) {
if(err){
console.log("ERROR TRNASCTION");
transaction.rollback(done);
return;
}else{
console.log("TRANSACTION SUCCESS!");
done();
}
});
});
如果保存不成功,我希望事务回滚,如果是,我希望它提交。我面临的问题是它们似乎都不是 运行ning,只是控制台上没有输出。没有任何东西被发送到我的数据库,所以我假设至少 'if(err)' 条件会 运行 但事实并非如此。我是 glcoud 的新手,所以我不确定我是否在这里做错了什么?我正在关注 https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.26.0/datastore/transaction?method=save.
的文档在事务上下文中,save
方法实际上不需要回调。在您调用 done()
之前,您要保存的内容会排队。调用 done
将提交事务。
然后您可以在传递给 runInTransaction
的第二个函数中处理来自提交操作的错误。有关示例,请参阅 https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.26.0/datastore/dataset?method=runInTransaction。
--
仅提及这一点,因为它与回滚部分有关:https://github.com/GoogleCloudPlatform/gcloud-node/issues/633 -- 我们正在等待升级到 Datastore 的 API,然后再解决该问题。