在节点js中查询Mysql

时间:2019-05-28 11:16:52

标签: javascript mysql node.js

我就是不明白这一点!一些想法?

我不知道如何处理第57行(现有的const行){

谢谢您的帮助:)

我从中得到的错误是

Connected!
Database created
(node:8692) UnhandledPromiseRejectionWarning: TypeError: existing is not iterable
    at insertUpdate (C:\Users\sondr\Desktop\koder\Ip_søk_syslog\app.js:57:23)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:8692) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:8692) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Using syslog
Tabel syslog_data created
^C
C:\Users\sondr\Desktop\koder\Ip_søk_syslog>
async function insertUpdate() {
    // hent alle IPer listet i databasen
    const existing = await con.query(`SELECT ip, count FROM syslog_data`);
    // gå gjennom IP etter IP
    for (const key in tracker) {
        let exists = false;
        // gå gjennom eksisterende IPer fra databasen for hver gang (finnes bedre løsninger enn loop)
        for (const row of existing) {
            // sjekk om IP matcher IP som skal legges til/oppdateres, og legg til eller øk "count"
            if (row.ip !== key) continue;
            con.query(`UPDATE syslog_data SET count=${++row.count} WHERE ip="${row.ip}"`);
            exists = true;
            break;
        }
        // hopp til neste IP hvis den gjeldende eksisterer
        if (exists) continue;
        // legg til IP i databasen, og sett "count" verdien
        await con.query(`INSERT INTO syslog_data (ip, count) VALUES ("${key}", "${tracker[key]}")`);
    }
}

insertUpdate();


});
}
});

0 个答案:

没有答案