begin-transaction.test.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. var Pack = require('../../');
  2. describe('Transactional ::', function() {
  3. describe.skip('Begin Transaction', function() {
  4. var manager;
  5. var connection;
  6. // Create a manager and connection
  7. before(function(done) {
  8. // Needed to dynamically get the host using the docker container
  9. var host = process.env.MYSQL_PORT_3306_TCP_ADDR || 'localhost';
  10. Pack.createManager({
  11. connectionString: 'mysql://mp:mp@' + host + ':3306/mppg'
  12. })
  13. .exec(function(err, report) {
  14. if (err) {
  15. return done(err);
  16. }
  17. // Store the manager
  18. manager = report.manager;
  19. Pack.getConnection({
  20. manager: manager
  21. })
  22. .exec(function(err, report) {
  23. if (err) {
  24. return done(err);
  25. }
  26. // Store the connection
  27. connection = report.connection;
  28. return done();
  29. });
  30. });
  31. });
  32. // Afterwards close the transaction and release the connection
  33. after(function(done) {
  34. Pack.sendNativeQuery({
  35. connection: connection,
  36. nativeQuery: 'ROLLBACK;'
  37. })
  38. .exec(function(err) {
  39. if (err) {
  40. return done(err);
  41. }
  42. Pack.releaseConnection({
  43. connection: connection
  44. }).exec(done);
  45. });
  46. });
  47. // TODO: Find a way to get a transaction id in mysql??
  48. });
  49. });