簡體   English   中英

Node.js-為什么此代碼不起作用?

[英]Node.js - Why isn't this code working?

當在搜索數據庫時找不到該用戶的任何內容時,我已經嘗試過下面的代碼來執行操作。 這是使用twitch-irc庫及其twitch-irc-db模塊(Node.js)。

db.where('users', {name: user.username}).then(function(result) {
    if (!result) {
        console.log('No result lad');
    }
    var cid = result.items[0].cid;
    console.log(result.items[0].cid);
    if (!cid) {
        db.insert('users', {name: user.username, keys: 0}).then(function() {
            console.log(user.username + ' is new to the stream, generating them a blank database entry.');
        });
    }
});

由於某些原因,上面的console.log()行均不起作用。 如您所見,我嘗試了if(!result)和if(!cid)的方法,但上述兩種方法均無效。

您的查詢是否可能由於某種原因而失敗並且您沒有跟蹤錯誤?

嘗試添加.fail

db.where('users', {name: user.username}).then(function(result) {
    if (!result) {
        console.log('No result lad');
    }
    var cid = result.items[0].cid;
    console.log(result.items[0].cid);
    if (!cid) {
        db.insert('users', {name: user.username, keys: 0}).then(function() {
            console.log(user.username + ' is new to the stream, generating them a blank database entry.');
        });
    }
}).fail(function(err) {console.log(err)});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM