MySQL XDevAPI如何返回成功状态 [英] MySQL XDevAPI How to return a successful status

查看:391
本文介绍了MySQL XDevAPI如何返回成功状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用与MySQL通讯的XDEVAPI开发我的RestAPI.这段代码可用于添加新记录,

Developing my RestAPI using XDEVAPI talking to MySQL. This piece of code works for adding a new record,

myRecord.add = (newmyRecord, res) =>
{
    mysql.getSession(mydb)      // .getSession() is a Promise, returns a session
        .then
        (
            sess =>
            {
                sess.getSchema("myschema").getTable("mytable").insert(...).execute(row=>{console.log('inserted')}); 
                
                res.send(200);   // resulting "UnhandledPromiseRejectionWarning: TypeError: res.send is not a function"
                //return 200;    // Postman still shows "Sending" and Fiddler does not show status 200
            }
            
        );
}

所以我的问题是如何发送成功的200来完成POST?

So my question is how to send back a successful 200 to complete the POST?

推荐答案

execute()方法还返回一个Promise,对于

The execute() method also returns back a Promise and, in the case of insert(), it isn't expecting any kind of callback, so the following line will never be called:

console.log('inserted')

execute()期望回调的唯一实例是在

The only instances where execute() expects callbacks are on TableSelect and CollectionFind. And we are slowly moving away from that API flavour, since now you can also process the result sets by calling fetchOne() or fetchAll() on the Result instance to which that Promise resolves to (see DocResult and RowResult).

无论如何,没有什么可以阻止res.send(200)调用的发生,也没有任何隐式更改底层HTTP框架(您似乎正在使用)的API的情况.因此,您提到的问题似乎与MySQL X DevAPI连接器无关.

In any case, nothing prevents that res.send(200) call to happen and nothing implicitly changes the API of the underlying HTTP framework (which you seem to be using). So, the issue you mention does not seem to be in anyway related to the MySQL X DevAPI connector.

TypeError: res.send is not a function

在调用它之前(以及在调用add()之前),您可能在某个地方覆盖了该res对象.

You are probably overriding that res object somewhere before calling it (and before calling add()).

这可能没有太大帮助,但这是我现在可以从您的帖子中提取的唯一内容.

This isn't probably of much help, but it's the only thing I can extract right now from your post.

免责声明:我是MySQL X DevAPI Connector for Node.js的首席开发人员

Disclaimer: I'm the lead developer of the MySQL X DevAPI Connector for Node.js

这篇关于MySQL XDevAPI如何返回成功状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆