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?
The
execute()
method also returns back aPromise
and, in the case ofinsert()
, it isn't expecting any kind of callback, so the following line will never be called:The only instances where
execute()
expects callbacks are onTableSelect
andCollectionFind
. And we are slowly moving away from that API flavour, since now you can also process the result sets by callingfetchOne()
orfetchAll()
on theResult
instance to which thatPromise
resolves to (seeDocResult
andRowResult
).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.You are probably overriding that
res
object somewhere before calling it (and before callingadd()
).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