检查变量是否存在,然后更新

mutmk8jj  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(299)

我想在我的mysql数据库中搜索我的表,在一列中寻找一个变量,如果它确实找到了它,我希望它每分钟更新一次。如果它不在那里,我希望它创建它,然后它会被更新。我还没有做的创建部分或更新的一部分,如果有人能帮我做这将是伟大的。这是我的密码:

var request = require("request")
var sql = require("mssql")

var mysql = require('mysql');
var connection = mysql.createConnection({
  host     : 'xxx.xx.xx.xx',
  user     : 'root',
  password : 'xxx',
  database : 'points'
});

var Found = false;
var url = "https://tmi.twitch.tv/group/user/kong_plays/chatters"
var viewerAmount = 0;
var viewers = [];
var val = 0;

connection.connect((err) => {
  if (err) {
    console.log("Error connecting to database")
  }
  console.log('Connected to database!');
});

request({
    url: url,
    json: true
}, function (error, response, body) {
    if (!error && response.statusCode === 200) {
        viewers = body.chatters.viewers;
        console.log(viewers);
        viewerAmount = viewers.length;

    }
})

console.log(viewerAmount)
    function getPoints(){
              while(viewerAmount >= 0) {

              }
        }
        setInterval(function(){
            getPoints()}, 3000)

connection.query('SELECT * FROM points', (err,rows) => {

if(err) throw err;
rows.forEach( (row) => {
  viewerCount = viewerAmount
  console.log(viewerCount)
  while(viewerCount >= 0){
    console("1")
    viewerCount = viewerCount - 1;
    if (viewers[viewerCount] === row.twitchName) {
      console.log("Found "+viewers[viewerCount]+" in the database already. Ignoring");
      Found = true;
    }else if(viewerCount > 0){
      viewerCount = viewerCount - 1;        
    }else if (viewerCount === 0){
      console.log("Not found!")
    }
  }
});

});

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题