Q.nfcall:TypeCast在发生未指定的错误时失败

问题描述

我正在学习节点,并且很难为数据库交互编写后端代码。基于promise的实现看上去比使用回调更干净,因此我进行了一些挖掘并找到了Q。

在这里,甚至在哪里我都做错了我。 .then中的错误函数似乎正在捕获TypeCast错误,但是我不知道该怎么做会导致该错误

运行以下脚本

MysqL = require('MysqL');
var q = require('q')

var dbx = MysqL.createConnection({
    //this is verified correct...
});

function getuser3(UserdisplayName) {
    return q.nfcall(dbx.query,"SELECT * FROM Users WHERE Name = ? ",[UserdisplayName])
    // This should wrap the query function with a promise,apply the arguments "SELECT...",// [UserdisplayName],and set up the last-argument-node-style callback so it fulfills the promise
    // with either a value or an error. If I understand correctly.
}

val = getuser3("Player2")
    .then(
            function (value) {
                console.log(value)
                return value //this should be sent to val in the outside scope,right?
            },function (error) {
                console.log(error)
            }
    )
    .done()

console.log(val)

返回以下错误

c:\Users\cb\Documents\guts\learning node\backend\node_modules\q\q.js:155
                throw e;
                ^

TypeError: Cannot read property 'typeCast' of undefined
    at query (c:\Users\cb\Documents\guts\learning node\backend\node_modules\MysqL\lib\Connection.js:185:34)
    at Promise.apply (c:\Users\cb\Documents\guts\learning node\backend\node_modules\q\q.js:1185:26)
    at Promise.promise.promisedispatch (c:\Users\cb\Documents\guts\learning node\backend\node_modules\q\q.js:808:41)
    at c:\Users\cb\Documents\guts\learning node\backend\node_modules\q\q.js:1411:14
    at runSingle (c:\Users\cb\Documents\guts\learning node\backend\node_modules\q\q.js:137:13)
    at flush (c:\Users\cb\Documents\guts\learning node\backend\node_modules\q\q.js:125:13)
    at processticksAndRejections (internal/process/task_queues.js:79:11)
Process exited with code 1

我已经尝试了几种语法变体,尽我所能阅读文档,但是我真的不知道下一步该怎么做。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)