how to bluebird promisifyAll mysql2
See original GitHub issueHello, I’m in the process of converting my current implementation of node-mysql driver to mysql2 and fully utilize promises (bluebird). i figured the upgrade to mysql 2 should be a simple matter of changing ‘mysql’ to ‘mysql2’ but i am getting some errors and figured i’d ask for some help.
currently i have this setup for node-mysql
const Promise = require('bluebird');
const mysql = require('mysql');
const Pool = require('mysql/lib/Pool');
const options = { ... };
const Connection = require('mysql/lib/Connection');
Promise.promisifyAll([Pool, Connection]);
const pool = mysql.createPool(options);
module.exports = pool;
i tried
Promise.promisifyAll(require('mysql2'));
i also tried
const Promise = require('bluebird');
const mysql = require('mysql2');
const Pool = require('mysql2/lib/Pool');
const Connection = require('mysql2/lib/Connection');
Promise.promisifyAll([Pool, Connection]);
const options = { ... };
const pool = mysql.createPool(options);
module.exports = pool;
both gives me the error below.
TypeError: pool.getConnectionAsync is not a function
so the question is, how do i promisifyAll this module? Any help would be great, thanks!
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
node.js - How to promisify a MySql function using bluebird?
I have done this way and it is working fine. const connection = mysql.createConnection({.....}); global.db = Bluebird.
Read more >Promisification | bluebird
The usual way to use promises in node is to Promise.promisifyAll some API and start exclusively calling promise returning versions of the APIs...
Read more >mysql2-bluebird
Promises wrapper for mysql2 , powered by bluebird . Build Status. Installation. This module is installed via npm: $ npm install mysql2 ......
Read more >Bluebird NPM: Bluebird JS Promise with Example
Bluebird is a fully featured Promise library for JavaScript. In this Bluebird JS tutorial, you will learn about Bluebird JS Promises with ...
Read more >promise-mysql | Yarn - Package Manager
Promise -mysql is a wrapper for mysqljs/mysql that wraps function calls with Bluebird promises. API. mysql.createConnection(connectionOptions). This will return ...
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
working version
on top of that, my tests now run faster
before
now
yay for more speed
Hi!
I’m trying to keep file names lower case, and path to pool is
/lib/pool.js
, so you should be able to do