CodeFoodPixels / node-promise-mysql

A wrapper for mysqljs/mysql that wraps function calls with Bluebird promises.
MIT License
338 stars 64 forks source link

setup session parameter while making a connection #76

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi, Is there any way to setup session parameter in underlying library. like

set session autocommit=ON;

Thanks !

CodeFoodPixels commented 6 years ago

From looking at https://github.com/mysqljs/mysql#pool-events, you can listen for the connection event. You should be able to use it like this:

pool = mysql.createPool({
  host: 'localhost',
  user: 'sauron',
  password: 'theonetruering',
  database: 'mordor',
  connectionLimit: 10
});

pool.on('connection', function (connection) {
  connection.query('set session autocommit=ON')
});
ghost commented 6 years ago

Thank You !