花了几个小时尝试在这里找到多种解决方案后,我决定在此处发布有关错误的问题(将其放在async.waterfall:function1中的第一个函数上):
C:\wamp64\www\projet\app\node_modules\mysql\lib\protocol\Parser.js:80
throw err; // Rethrow non-MySQL errors
^
TypeError: callback is not a function
at Query._callback (C:\wamp64\www\projet\app\model\mymodel.js:10:3)
at Query.Sequence.end (C:\wamp64\www\projet\app\node_modules\mysql\lib\protocol\sequences\Sequence.js:88:24)
at Query._handleFinalResultPacket (C:\wamp64\www\projet\app\node_modules\mysql\lib\protocol\sequences\Query.js:139:8)
at Query.EofPacket (C:\wamp64\www\projet\app\node_modules\mysql\lib\protocol\sequences\Query.js:123:8)
at Protocol._parsePacket (C:\wamp64\www\projet\app\node_modules\mysql\lib\protocol\Protocol.js:279:23)
at Parser.write (C:\wamp64\www\projet\app\node_modules\mysql\lib\protocol\Parser.js:76:12)
at Protocol.write (C:\wamp64\www\projet\app\node_modules\mysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\wamp64\www\projet\app\node_modules\mysql\lib\Connection.js:103:28)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
我关注了几篇文章,但不确定语法或在此控制器和模型中构建代码的方式。我想我想念什么,但我不知道什么:(
这是myController.js
const async = require('async');
const MyModel = require('../model/mymodel');
module.exports.respond = function(socket) {
socket.on('connectionUser', function(param1, param2, param3= 'false') {
try {
async.waterfall([
async.constant(param1, param2, param3),
MyModel.function1,
MyModel.function2,
], function3);
} catch (err) {
// ERRORS handler
}
function funtion3 (err, userInfos, res[0]) {}
在mymodel.js中
const db = require('../config);
module.exports.function1 = function(callback){
let reqSql = 'SELECT ...';
db.query(reqSql, function(err, res){
if (err) return callback(err);
return callback(null, res[0]);
});
};
module.exports.function2 = function(userInfos, callback){
let reqSql = 'SELECT ....'
db.query(reqSql, function(err, res){
if (err) return callback(err);
return callback(null, userInfos, res[0]);
});
};
答案 0 :(得分:0)
确切地显示错误消息。回调不是function1,function2,中嵌套函数中的函数
您需要从嵌套函数返回回调
尝试
const db = require('../config);
module.exports.function1 = function(callback){
let reqSql = 'SELECT ...';
db.query(reqSql, function(err, res){
if (err) return callback(err);
return callback(null, res[0]);
});
};
module.exports.function2 = function(userInfos, callback){
let reqSql = 'SELECT ....'
db.query(reqSql, function(err, res){
if (err) return callback(err);
return callback(null, userInfos, res[0]);
});
};