使用nodejs的gcloud数据存储事务问题 [英] gcloud Datastore transaction issue using nodejs
问题描述
我正在使用nodejs联系google数据存储。这是我的代码:
dataset.runInTransaction(function(transaction,done,err){
//从`transaction`对象,像往常一样执行dataset方法
//当你准备好提交所有的变更时调用`done`
transaction.save(entities,function(err ){
if(err){
console.log(ERROR TRNASCTION);
transaction.rollback(done);
return;
} else {
console.log(TRANSACTION SUCCESS!);
done();
}
});
});
如果保存失败,我希望事务回滚,如果是这样,我想要它承诺。我面临的问题是它们都没有运行,只是在控制台上没有输出。没有什么被发送到我的数据库,所以我会至少假设'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 。
$ b
-
只要提到这一点,因为它涉及回滚部分: https://github.com/GoogleCloudPlatform/gcloud-node/issues/633 - 在解决该问题之前,我们正在等待升级到Datastore的API。
I am using nodejs to contact the google datastore. This is my code:
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();
}
});
});
If the save was not successful, I would like the transaction to rollback and if it was I want it to commit. The problem I am facing is that neither of them seem to be running, just no output on the console. Nothing is being sent to my database so I would assume at least the 'if(err)' condition would run but it doesn't. I am new to glcoud so I am not sure if I am doing something wrong here? I am following the doc at https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.26.0/datastore/transaction?method=save.
In the context of a transaction, the save
method doesn't actually need a callback. The things you wish to save are queued up until you call done()
. Calling done
will commit the transaction.
You can then handle errors from the commit operation in a second function passed to runInTransaction
. See https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.26.0/datastore/dataset?method=runInTransaction for examples of that.
--
Just mentioning this since it relates to the rollback part: https://github.com/GoogleCloudPlatform/gcloud-node/issues/633 -- we're waiting on an upgrade to Datastore's API before tackling that issue.
这篇关于使用nodejs的gcloud数据存储事务问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!