con.query("SELECT * FROM person", function (err, rowsFromMysql) {
if (rowsFromMysql === undefined || rowsFromMysql.length == 0) {
console.log("table person is empty");
db.all("SELECT * FROM person", function (err, rowsFromSqlite) {
rowsFromSqlite.forEach(function (rowFromSqlite) {
con.query("INSERT INTO `person` (`id`, `st`, `sch`, `iin`, `kl`, `d_end`, `d_pln`, `tel`, `telegram_id`, `doc`, `lat`, `dat`) VALUES ('" + rowFromSqlite.id + "', '" + rowFromSqlite.st + "', '" + rowFromSqlite.sch + "', '" + rowFromSqlite.iin + "','" + rowFromSqlite.kl + "', '" + rowFromSqlite.d_end + "', '" + rowFromSqlite.d_pln + "', '" + rowFromSqlite.tel + "', '','" + rowFromSqlite.doc + "', '" + rowFromSqlite.lat.replace(/\'/g, "") + "', '" + rowFromSqlite.dat + "')");
})
})
} else {
console.log("table 'person' is not empty");
db.all("SELECT * from person", function (err, rowsFromSqlite) {
con.query("SELECT * FROM person ORDER BY id DESC LIMIT 1", function (err, rowsFromMysql) {
rowsFromSqlite.forEach(function (rowFromSqlite) {
if (rowFromSqlite.id > rowsFromMysql[0].id) {
con.query("INSERT INTO `person` (`id`, `st`, `sch`, `iin`, `kl`, `d_end`, `d_pln`, `tel`, `telegram_id`, `doc`, `lat`, `dat`) VALUES ('" + rowFromSqlite.id + "', '" + rowFromSqlite.st + "', '" + rowFromSqlite.sch + "', '" + rowFromSqlite.iin + "','" + rowFromSqlite.kl + "', '" + rowFromSqlite.d_end + "', '" + rowFromSqlite.d_pln + "', '" + rowFromSqlite.tel + "', '','" + rowFromSqlite.doc + "', '" + rowFromSqlite.lat.replace(/\'/g, "") + "', '" + rowFromSqlite.dat + "')");
console.log("Added one person!");
}
})
})
});
}
});