MySQL数据库返回null结果

时间:2017-12-08 10:25:50

标签: mysql amazon-rds google-cloud-functions

在MySQL中使用'SELECT'命令从节点js。有时,查询返回非null值,有时会返回带有相同查询的null

这是我的代码:

exports.Top10 = functions.https.onRequest(function (req, res) {
    connection.query("SELECT * FROM Ads ORDER BY (Stars / Raters) LIMIT 10", function (err, result) {
        if (err) {
            console.log("Top10 Err: ", err);
        }
        res.end(JSON.stringify(result));
    });
});
  

Top10 Err:{错误:致命错误后无法将查询排入队列。

at Protocol._validateEnqueue (/user_code/node_modules/mysql/lib/protocol/Protocol.js:201:16)
at Protocol._enqueue (/user_code/node_modules/mysql/lib/protocol/Protocol.js:139:13)
at Connection.query (/user_code/node_modules/mysql/lib/Connection.js:208:25)
at /user_code/index.js:510:28
at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:26:41)
at /var/tmp/worker/worker.js:671:7
at /var/tmp/worker/worker.js:655:9
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickDomainCallback (internal/process/next_tick.js:128:9) code:
     

'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR',致命:错误}

我正在使用Firebase云功能作为节点服务器& Amazon RDS MySQL数据库

如果您对此问题有任何疑问,请发表评论

1 个答案:

答案 0 :(得分:2)

当用于订购然后应用于desc / asc时,将使用此代码

exports.Top10 = functions.https.onRequest(function (req, res) {
    connection.query("SELECT * FROM Ads ORDER BY (Stars / Raters) DESC LIMIT 10", function (err, result) {
        if (err) {
            console.log("Top10 Err: ", err);
        }
        res.end(JSON.Parse(result));
    });
});