Node8 - async /await feature with node-mysql [on hold]
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
I have been trying to use the new async/await feature of Node 8 with node-mysql module. Have been partial successful in incorporating async/await with mysql. When I create a cluster pool connection with node-mysql client I am unable to do this without the callback. If I write callback I am able to get the data from MySQL but when I am using async/await I am getting weird errors. Although I have been able to write the getConnection function in async/await form but no luck with the connection.query part. Can anybody help in this context ?
**SAMPLE CODE**
**//pool-cluster.js** <br>
var poolCluster = mysql.createPoolCluster();
var masterConfig = ...;
var slaveConfig1 = ...;
poolCluster.add('MASTER', masterConfig);
poolCluster.add('SLAVE1', slaveConfig1);
poolCluster.getConnection = util.promisify(poolCluster.getConnection());
module.exports.PoolCluster = poolCluster;
**//connect-cluster-pool.js**
var poolClusterSrv = require('../pool-cluster');<br>
async fetchRecord() <br>
let queryStr = 'select * from customers';<br>
console.log("inside fetchRecord()...");<br>
try <br>
let connection = await <br>poolClusterSrv.PoolCluster.getConnection('SLAVE1'); --<b>this is working</b>
console.log("Connected to SLAVE1::", connection.threadId);
//getting new threadId every time
let results = await util.promisify(connection.query(queryStr));
//this is not working / working only with callback</b>
console.log(results);
return results;
<br>
catch (error)
console.log("error in fetchRecord()::", error);
<br>
<br>
node.js
put on hold as off-topic by Toby Speight, Stephen Rauch, yuri, Ludisposed, t3chb0t Aug 3 at 8:09
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â Toby Speight, Stephen Rauch, yuri, Ludisposed, t3chb0t
add a comment |Â
up vote
0
down vote
favorite
I have been trying to use the new async/await feature of Node 8 with node-mysql module. Have been partial successful in incorporating async/await with mysql. When I create a cluster pool connection with node-mysql client I am unable to do this without the callback. If I write callback I am able to get the data from MySQL but when I am using async/await I am getting weird errors. Although I have been able to write the getConnection function in async/await form but no luck with the connection.query part. Can anybody help in this context ?
**SAMPLE CODE**
**//pool-cluster.js** <br>
var poolCluster = mysql.createPoolCluster();
var masterConfig = ...;
var slaveConfig1 = ...;
poolCluster.add('MASTER', masterConfig);
poolCluster.add('SLAVE1', slaveConfig1);
poolCluster.getConnection = util.promisify(poolCluster.getConnection());
module.exports.PoolCluster = poolCluster;
**//connect-cluster-pool.js**
var poolClusterSrv = require('../pool-cluster');<br>
async fetchRecord() <br>
let queryStr = 'select * from customers';<br>
console.log("inside fetchRecord()...");<br>
try <br>
let connection = await <br>poolClusterSrv.PoolCluster.getConnection('SLAVE1'); --<b>this is working</b>
console.log("Connected to SLAVE1::", connection.threadId);
//getting new threadId every time
let results = await util.promisify(connection.query(queryStr));
//this is not working / working only with callback</b>
console.log(results);
return results;
<br>
catch (error)
console.log("error in fetchRecord()::", error);
<br>
<br>
node.js
put on hold as off-topic by Toby Speight, Stephen Rauch, yuri, Ludisposed, t3chb0t Aug 3 at 8:09
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â Toby Speight, Stephen Rauch, yuri, Ludisposed, t3chb0t
Did you add<br>
to the end of some of those lines on purpose? If so, those aren't necessary, since the code block is formatted per normal<pre>
and<code>
tags...
â Sam Onela
Aug 2 at 17:31
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have been trying to use the new async/await feature of Node 8 with node-mysql module. Have been partial successful in incorporating async/await with mysql. When I create a cluster pool connection with node-mysql client I am unable to do this without the callback. If I write callback I am able to get the data from MySQL but when I am using async/await I am getting weird errors. Although I have been able to write the getConnection function in async/await form but no luck with the connection.query part. Can anybody help in this context ?
**SAMPLE CODE**
**//pool-cluster.js** <br>
var poolCluster = mysql.createPoolCluster();
var masterConfig = ...;
var slaveConfig1 = ...;
poolCluster.add('MASTER', masterConfig);
poolCluster.add('SLAVE1', slaveConfig1);
poolCluster.getConnection = util.promisify(poolCluster.getConnection());
module.exports.PoolCluster = poolCluster;
**//connect-cluster-pool.js**
var poolClusterSrv = require('../pool-cluster');<br>
async fetchRecord() <br>
let queryStr = 'select * from customers';<br>
console.log("inside fetchRecord()...");<br>
try <br>
let connection = await <br>poolClusterSrv.PoolCluster.getConnection('SLAVE1'); --<b>this is working</b>
console.log("Connected to SLAVE1::", connection.threadId);
//getting new threadId every time
let results = await util.promisify(connection.query(queryStr));
//this is not working / working only with callback</b>
console.log(results);
return results;
<br>
catch (error)
console.log("error in fetchRecord()::", error);
<br>
<br>
node.js
I have been trying to use the new async/await feature of Node 8 with node-mysql module. Have been partial successful in incorporating async/await with mysql. When I create a cluster pool connection with node-mysql client I am unable to do this without the callback. If I write callback I am able to get the data from MySQL but when I am using async/await I am getting weird errors. Although I have been able to write the getConnection function in async/await form but no luck with the connection.query part. Can anybody help in this context ?
**SAMPLE CODE**
**//pool-cluster.js** <br>
var poolCluster = mysql.createPoolCluster();
var masterConfig = ...;
var slaveConfig1 = ...;
poolCluster.add('MASTER', masterConfig);
poolCluster.add('SLAVE1', slaveConfig1);
poolCluster.getConnection = util.promisify(poolCluster.getConnection());
module.exports.PoolCluster = poolCluster;
**//connect-cluster-pool.js**
var poolClusterSrv = require('../pool-cluster');<br>
async fetchRecord() <br>
let queryStr = 'select * from customers';<br>
console.log("inside fetchRecord()...");<br>
try <br>
let connection = await <br>poolClusterSrv.PoolCluster.getConnection('SLAVE1'); --<b>this is working</b>
console.log("Connected to SLAVE1::", connection.threadId);
//getting new threadId every time
let results = await util.promisify(connection.query(queryStr));
//this is not working / working only with callback</b>
console.log(results);
return results;
<br>
catch (error)
console.log("error in fetchRecord()::", error);
<br>
<br>
node.js
asked Aug 2 at 13:22
Mousumi
1
1
put on hold as off-topic by Toby Speight, Stephen Rauch, yuri, Ludisposed, t3chb0t Aug 3 at 8:09
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â Toby Speight, Stephen Rauch, yuri, Ludisposed, t3chb0t
put on hold as off-topic by Toby Speight, Stephen Rauch, yuri, Ludisposed, t3chb0t Aug 3 at 8:09
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â Toby Speight, Stephen Rauch, yuri, Ludisposed, t3chb0t
Did you add<br>
to the end of some of those lines on purpose? If so, those aren't necessary, since the code block is formatted per normal<pre>
and<code>
tags...
â Sam Onela
Aug 2 at 17:31
add a comment |Â
Did you add<br>
to the end of some of those lines on purpose? If so, those aren't necessary, since the code block is formatted per normal<pre>
and<code>
tags...
â Sam Onela
Aug 2 at 17:31
Did you add
<br>
to the end of some of those lines on purpose? If so, those aren't necessary, since the code block is formatted per normal <pre>
and <code>
tags...â Sam Onela
Aug 2 at 17:31
Did you add
<br>
to the end of some of those lines on purpose? If so, those aren't necessary, since the code block is formatted per normal <pre>
and <code>
tags...â Sam Onela
Aug 2 at 17:31
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Did you add
<br>
to the end of some of those lines on purpose? If so, those aren't necessary, since the code block is formatted per normal<pre>
and<code>
tags...â Sam Onela
Aug 2 at 17:31