MySQL Forums
Forum List  »  Connector/Node.js

Re: await in NodeJs
Posted by: Rui Quelhas
Date: September 18, 2020 08:30AM

Hi Max,

it seems like you are using one of "mysql" or "mysql2" drivers. These are community-lead projects and not official MySQL products. The best place to get help is probably to open an issue in their corresponding GitHub repos.

From what I can tell, if you are using the "mysql" driver/module. I think does not support Promises and thus does not support async/await as well, which means you can only use the callback pattern, such as:

connection.query(select * from table', function (err, results, fields) {
// results is an array containing row data
// fields contains the column metadata

If you are using "mysql2". You should be able to use async/await as long as you import the proper wrapper. For instance:

const mysql = require('mysql2/promise')
const connection = mysql.createConnection(/* ... */)

const res = await connection.query('select * from table')

Hope it helps.

Options: ReplyQuote

Written By
September 12, 2020 07:08AM
September 18, 2020 03:53AM
Re: await in NodeJs
September 18, 2020 08:30AM
September 19, 2020 10:41AM
December 22, 2020 05:29AM
December 23, 2020 06:47AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.