Mysql: How do I allow multiple statements when pooling?

Created on 1 Feb 2016  路  2Comments  路  Source: mysqljs/mysql

https://www.npmjs.com/package/mysql#multiple-statement-queries

How do I allow multiple statements when pooling? I don't see a way to set options via getConnection nor docs about except on createConnection.

module.exports = {

  connect: (config) => {
    return bluebird.try(() => {
      pool = bluebird.promisifyAll(mysql.createPool(config));
      return pool;
    });
  },

  query: (sql, placeholders) => {
    return bluebird.using(pool.getConnectionAsync(), (conn) => {
      return bluebird.promisify(conn.query, {context: conn})(sql, placeholders);
    });
  }
};
question

Most helpful comment

The multipleStatements:true option (and all other options, as far as I can tell) works with createPool, the same as with createConnection.

Be aware that when you sent multiple statements:

select 0; select1;

you will get back an array of result arrays:

[
    [
        {"0": 0}
    ],
    [
        {"1": 1}
    ]
]

All 2 comments

The multipleStatements:true option (and all other options, as far as I can tell) works with createPool, the same as with createConnection.

Be aware that when you sent multiple statements:

select 0; select1;

you will get back an array of result arrays:

[
    [
        {"0": 0}
    ],
    [
        {"1": 1}
    ]
]

Hi @fourq, I hope @dkloke answered your question :)

You can find as the first sentence of the pool options documentation (https://www.npmjs.com/package/mysql#connection-options):

Pools accept all the same options as a connection.

Always feel free to let us know if there is a way to help improve the documentation!

Was this page helpful?
0 / 5 - 0 ratings