MySQL XDevAPI How to return a successful status

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             }                      ); } 

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

Add Comment
1 Answer(s)

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') 

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).

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 

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.

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

Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.