Mysql: Pool Prototype beginTransaction

Created on 4 Apr 2018  路  1Comment  路  Source: mysqljs/mysql

When using a pool connection you seem to be missing the beginTransaction method.

const connection = mysql.createPool({
  host: process.env.HOST,
  user: process.env.USER,
  password: process.env.PASSWORD,
  database: process.env.DATABASE,
  connectionLimit: 10
})

here is the current pool connection I am using, could be a user error but I did not see the option available to the pool.

question

Most helpful comment

Hi @hkd987 this is as designed. The createPool method doesn't return a connection, it returns a pool object. A transaction is specific to a single connection, so you need to first get the specific connection you want to begin a transaction on from the pool using .getConnection. Then you can begin and end the transaction and return to the pool when done 馃憤

>All comments

Hi @hkd987 this is as designed. The createPool method doesn't return a connection, it returns a pool object. A transaction is specific to a single connection, so you need to first get the specific connection you want to begin a transaction on from the pool using .getConnection. Then you can begin and end the transaction and return to the pool when done 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

skilbjo picture skilbjo  路  3Comments

johnrc picture johnrc  路  3Comments

macias picture macias  路  3Comments

abou7mied picture abou7mied  路  4Comments

hohozhao picture hohozhao  路  4Comments