Issue promisifying node-mysql
See original GitHub issueI would expect the following two code fragments to output the same thing:
Promise = require 'bluebird'
mysql = require 'mysql'
Promise.promisifyAll(require("mysql/lib/Pool").prototype)
Promise.promisifyAll(require("mysql/lib/Connection").prototype)
pool = mysql.createPool { database: 'mydb', host: 'localhost', user: 'user', password: 'pw' }
pool.getConnectionAsync().then (db) ->
db.queryAsync('select * from users where id=?', '1').then (rows) ->
console.log rows
mysql = require 'mysql'
pool = mysql.createPool { database: 'mydb', host: 'localhost', user: 'user', password: 'pw' }
pool.getConnection (err, db) ->
db.query('select * from users where id='?', '1', (err, rows) ->
console.log rows
However for the first, the output looks like:
[ [ { id: 1, email: 'myemail', password: 'pw' } ],
[ { catalog: 'def',
db: 'mydb',
table: 'users',
orgTable: 'users',
name: 'id',
orgName: 'id',
charsetNr: 63,
length: 64,
type: 8,
flags: 20483,
decimals: 0,
default: undefined,
zeroFill: false,
protocol41: true }, ...
] ]
and for the second the output is just:
[ { id: 1, email: 'myemail', password: 'pw' } ]
I’m still digging in, but wanted to post an issue to see if this is a known problem (or if it’s a case of PEBKAC)
Issue Analytics
- State:
- Created 9 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
mysql-promisify - npm
Start using mysql-promisify in your project by running `npm i ... There are no other projects in the npm registry using mysql-promisify.
Read more >How to promisify a mysql pool connection in Node js?
Here is an easy example about how I solved it: pool.getConnection = util.promisify(pool.getConnection) let conn = await pool.
Read more >Promisifying MySQL Transactions with Connection Pool
Promisifying MySQL Transactions with Connection Pool. This is a Node.js example on MySQL transactions with promises (using async / await).
Read more >Node.js, MySQL and promises - codeburst
Like most I/O operations in Node.js, database access is asynchronous. ... First we have to “promisify” the database client.
Read more >Promisification - The Modern JavaScript Tutorial
But promises are more convenient, so it makes sense to promisify them. ... In Node.js, there's a built-in util.promisify function for that.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Prieston no. You need to release it yourself. Have a look at Bluebirds
.disposer()
Mysql doesn’t strictly conform to node callback convention, the callback parameters are actually: is
err, rows, columns
which doesn’t map to single return value. So the promise fulfillment value is[rows, columns]
instead of justrows
like you expected, to avoid information loss.You can use
spread
instead:This cannot be fixed until 3.0.0, see https://github.com/petkaantonov/bluebird/issues/307