I come from PHP and do not understand how a series of MySQL queries can be written in async NodeJS. For example, take this example from PHP coding:
$mysqli->query("INSERT INTO articles (title) VALUES ('title')");
$article_id = $mysqli->insert_id;
foreach ($tags as $tag) {
$result = mysqli->query("SELECT tag_id from tags WHERE tag='$tag'");
if($result->num_rows==1){
$row=$result->fetch_assoc();
$tag_id=$row['tag_id'];
} else {
$mysqli->query("INSERT INTO tags (tag) VALUES ('$tag')");
$tag_id=$mysqli->insert_id;
}
$mysqli->query("INSERT INTO tag_map (article_id, tag_id) VALUES ($article_id, $tag_id)");
}
How can we write this code in Node.JS?
I specifically mean, the if statement and getting insert_id for the next queries.