在我的代碼結束時,我有兩個同時運行的操作,一個查詢生成一個Atler表。第二次插入。Node.js執行順序查詢
問題是有時插入發生在alter table之前。
如何在所有鍵的for循環中執行代碼的第一部分,然後繼續插入?
if (count >1) {
for(var i = 0; i < keys.length -1; i++) {
client.execute (queryadd, { prepare: true }, function (err) {
console.log("do");
});
}
}
client.execute(queryinsert, { prepare: true }, function (err) {
console.log(err);
client.shutdown();
});
如果我使用await,我得到意外的客戶端標識符...? –
看看https://ponyfoo.com/articles/understanding-javascript-async-await或https://www.twilio.com/blog/2015/10/asyncawait-the-hero-javascript-deserved.html –
如果你不想使用es6/7,那麼只需使用這個庫https://caolan.github.io/async/ –