MySQL XDevAPI How to return a successful status

Jeb50

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?

ruiquelhas

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

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

mysql-xdevapi getCollections promiseの戻り値

分類Dev

How to return different Http Status Code in ServiceStack

分類Dev

How to return 404 status code in ReactJS?

分類Dev

How to check event scheduler status mysql

分類Dev

NodeJS xdevapi-MySQLデータベースへの接続の作成

分類Dev

Mysql8 xdevapi node.js CRUD table.select problems

分類Dev

bash function return status

分類Dev

Mysql exited with status 1 and restarted every 24 hours? How to debug?

分類Dev

How to return null for certain values mysql

分類Dev

Doctrine how to check if flush() is successful?

分類Dev

xdevapiを使用してmysqlからDateTimeをフェッチする方法

分類Dev

Return response with status code in Express

分類Dev

Dynamic return status from restler

分類Dev

Return status of Busybox `timeout` command

分類Dev

Check status of Mysql replication

分類Dev

How to check if the multipart upload was successful with alamofire image

分類Dev

How to get the single return value from mysql stored function in php

分類Dev

How to return a column value basted on last activity date VIA MySQL

分類Dev

How to query MySQL and return value from PHP to JQuery

分類Dev

MySQL8.0 xdevapi node.jsはキーを返さず、値のみを返します

分類Dev

MySQLエラー5154:無効なプレースホルダー(Node.js XDevAPIコネクター)

分類Dev

loop(repeat) script block until successful db(mysql) password

分類Dev

Curl to return http status code along with the response

分類Dev

Swift alamofire refactoring trying to return status code

分類Dev

return status code from graphql yoga

分類Dev

What response status code should I return?

分類Dev

AngularJS $ http.post return status 0

分類Dev

AngularJS $ http get return null status 0

分類Dev

How do I see mysql status messages in bash stdout over ssh?

Related 関連記事

  1. 1

    mysql-xdevapi getCollections promiseの戻り値

  2. 2

    How to return different Http Status Code in ServiceStack

  3. 3

    How to return 404 status code in ReactJS?

  4. 4

    How to check event scheduler status mysql

  5. 5

    NodeJS xdevapi-MySQLデータベースへの接続の作成

  6. 6

    Mysql8 xdevapi node.js CRUD table.select problems

  7. 7

    bash function return status

  8. 8

    Mysql exited with status 1 and restarted every 24 hours? How to debug?

  9. 9

    How to return null for certain values mysql

  10. 10

    Doctrine how to check if flush() is successful?

  11. 11

    xdevapiを使用してmysqlからDateTimeをフェッチする方法

  12. 12

    Return response with status code in Express

  13. 13

    Dynamic return status from restler

  14. 14

    Return status of Busybox `timeout` command

  15. 15

    Check status of Mysql replication

  16. 16

    How to check if the multipart upload was successful with alamofire image

  17. 17

    How to get the single return value from mysql stored function in php

  18. 18

    How to return a column value basted on last activity date VIA MySQL

  19. 19

    How to query MySQL and return value from PHP to JQuery

  20. 20

    MySQL8.0 xdevapi node.jsはキーを返さず、値のみを返します

  21. 21

    MySQLエラー5154:無効なプレースホルダー(Node.js XDevAPIコネクター)

  22. 22

    loop(repeat) script block until successful db(mysql) password

  23. 23

    Curl to return http status code along with the response

  24. 24

    Swift alamofire refactoring trying to return status code

  25. 25

    return status code from graphql yoga

  26. 26

    What response status code should I return?

  27. 27

    AngularJS $ http.post return status 0

  28. 28

    AngularJS $ http get return null status 0

  29. 29

    How do I see mysql status messages in bash stdout over ssh?

ホットタグ

アーカイブ