CodeFoodPixels / node-promise-mysql

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

use this package but find can not do transaction #38

Closed Prumeth-shen closed 7 years ago

Prumeth-shen commented 7 years ago

here is my code, I have tested it more than once

const connection = await mysql.createConnection({
        host: host,
        user: user,
        password: password,
        database: database
      });

      try {
        await connection.beginTransaction();
        await connection.query('UPDATE account SET vip_start_time = 11111, vip_end_time = 11111 WHERE user_id = 44');
        await connection.query('INSERT INTO notification SET type = ?, user_id = ?, content = ?, is_read = ?, created_at = ?',
          ['1', 44, 'aaa', 0, Math.floor(new Date() / 1000)]);
      } catch (err) {
        return connection.rollback();
      }

the err stack is about this

{ [Error: ER_LOCK_WAIT_TIMEOUT: Lock wait timeout exceeded; try restarting transaction]
  code: 'ER_LOCK_WAIT_TIMEOUT',
  errno: 1205,
  sqlState: 'HY000',
  index: 0 }

And I find this the first query did not work at all

CodeFoodPixels commented 7 years ago

You've closed the issue so I'm assuming you've sorted it, but the error is a mysql error and not related to this library.