当我在db.each
中查询我的SQLite数据库时,字符串不会使用加法运算符追加
var messages = "Global Message History: \n\n";
db.each(sql, [Article], (err, row) => {
if (err) {
throw err;
}
console.log(`[${row.message_timestamp}] <@${row.msg_id}> in #${row.channel_name} on Server "${row.server_name}": ${row.message_content}`); //Outputs all messages
messages += `[${row.message_timestamp}] <@${row.msg_id}> in #${row.channel_name} on Server "${row.server_name}": ${row.message_content}\n`; // Doesn't work
});
sendMsg(messages);
sendMsg();
只应对所有消息执行一次,但它似乎不起作用且输出仅为Global Message History: \n\n
答案 0 :(得分:0)
此方法异步后,您应在db.each
的sendMsg()
参数中调用complete
作为:
var messages = "Global Message History: \n\n";
db.each(sql, [Article], (err, row) => {
if (err) {
throw err;
}
console.log(`[${row.message_timestamp}] <@${row.msg_id}> in #${row.channel_name} on Server "${row.server_name}": ${row.message_content}`); //Outputs all messages
messages += `[${row.message_timestamp}] <@${row.msg_id}> in #${row.channel_name} on Server "${row.server_name}": ${row.message_content}\n`; // Doesn't work
}, function(){ sendMsg(messages) });
希望这有帮助。