Mysql: Support for ES6 native Promises

Created on 3 Apr 2017  路  10Comments  路  Source: mysqljs/mysql

Is there plan to support Javascript's native promise syntax that was introduced as a standard of the language in ES6?

I know I can wrap it in promise libraries such as bluebird or Q, but that would be an additional dependency I'd like to avoid if possible.

Most helpful comment

I'm writing my own promise code when using the lib, as simple as below:

function query(connection, sql) {
  return new Promise((resolve, reject) => {
    connection.query(sql, (error, results) => {
      if (error) {
        throw error;
      }

      resolve(results);
    });
  });
}

All 10 comments

Hi @rmullenix there is no real plan, but a lot of that is because the gap is currently filled by the https://www.npmjs.com/package/mysql2 module so there hasn't been a large push to get the work done to add it. You're certainly welcome to make a proposal on what needs to be done to get promises added and / or a PR started.

@rmullenix it's probably very easy to port by adding https://github.com/sidorares/node-mysql2/blob/master/promise.js file to this repo ( need a review and might require some minor modifications )

Note that a lot of people really expect promise wrapper to behave exactly as non-promise and there should be a good documentation update to set expectations correctly

I'm writing my own promise code when using the lib, as simple as below:

function query(connection, sql) {
  return new Promise((resolve, reject) => {
    connection.query(sql, (error, results) => {
      if (error) {
        throw error;
      }

      resolve(results);
    });
  });
}

@vanerleo Do you have experience with such libraries?

using it in production

I think that you guys may think it again to support promises.

Node v10-pre has added promises to the builtin module fs.
It can be used by require('fs/promises') in node v10.

I have seen the source code in node master branch --- node v10 fs/promises

The fs/promises API provides an alternative set of asynchronous file system methods that return Promise objects rather than using callbacks. The API is accessible via require('fs/promises).

--- from node officiall API document

We like using this awesome mysql package, but it has been inconvinent sometimes.

Maybe it's time to have some change in mind about this problem.
Think about it again , think about it for future. Please!

Thanks anyway

Hi @rmullenix there is no real plan, but a lot of that is because the gap is currently filled by the https://www.npmjs.com/package/mysql2 module so there hasn't been a large push to get the work done to add it.

The problem with that is that it's been stated that the mysql2 promise implementation doesn't (and won't) support the full api (https://github.com/sidorares/node-mysql2/issues/609#issuecomment-314441674)

@dougwilson Any updates on this, mate? My code is begging me to make it look cleaner and readable.

There has been no submission per my request in https://github.com/mysqljs/mysql/issues/1687#issuecomment-291225415 I'm going to close since if there hasn't been any for these years, it may just never come. You're welcome to submit one to get it moving, of course!

Was this page helpful?
0 / 5 - 0 ratings