Javascript sqlite3字符串没有追加

时间:2017-08-05 22:04:39

标签: javascript sqlite

当我在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

1 个答案:

答案 0 :(得分:0)

此方法异步后,您应在db.eachsendMsg()参数中调用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) });

希望这有帮助。