rollback-transaction.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. module.exports = {
  2. friendlyName: 'Rollback transaction',
  3. description: 'Abort and revert (i.e. "roll back") the database transaction that was begun on the specified active connection.',
  4. extendedDescription: 'The provided connection must already have a transaction begun on it.',
  5. moreInfoUrl: 'http://dev.mysql.com/doc/refman/5.7/en/commit.html',
  6. inputs: {
  7. connection: {
  8. friendlyName: 'Connection',
  9. description: 'An active database connection.',
  10. extendedDescription: 'The provided database connection instance must still be active. Only database connection instances created by the `getConnection()` machine in this driver are supported.',
  11. example: '===',
  12. required: true
  13. },
  14. meta: {
  15. friendlyName: 'Meta (custom)',
  16. description: 'Additional stuff to pass to the driver.',
  17. extendedDescription: 'This is reserved for custom driver-specific extensions. Please refer to the documentation for the driver you are using for more specific information.',
  18. example: '==='
  19. }
  20. },
  21. exits: {
  22. success: {
  23. description: 'The transaction was successfully rolled back.',
  24. extendedDescription: 'Subsequent queries on this connection will no longer be transactional unless a new transaction is begun.',
  25. outputVariableName: 'report',
  26. outputDescription: 'The `meta` property is reserved for custom driver-specific extensions.',
  27. outputExample: '==='
  28. // outputExample: {
  29. // meta: '==='
  30. // }
  31. },
  32. badConnection: {
  33. friendlyName: 'Meta (custom)',
  34. description: 'Additional stuff to pass to the driver.',
  35. extendedDescription: 'This is reserved for custom driver-specific extensions. Please refer to the documentation for the driver you are using for more specific information.',
  36. outputExample: '==='
  37. // outputExample: {
  38. // meta: '==='
  39. // }
  40. }
  41. },
  42. fn: function rollbackTransaction(inputs, exits) {
  43. var Pack = require('../');
  44. // Since we're using `sendNativeQuery()` to access the underlying connection,
  45. // we have confidence it will be validated before being used.
  46. Pack.sendNativeQuery({
  47. connection: inputs.connection,
  48. nativeQuery: 'ROLLBACK'
  49. }).switch({
  50. error: function error(err) {
  51. return exits.error(err);
  52. },
  53. badConnection: function badConnection() {
  54. return exits.badConnection({
  55. meta: inputs.meta
  56. });
  57. },
  58. success: function success() {
  59. return exits.success({
  60. meta: inputs.meta
  61. });
  62. }
  63. });
  64. }
  65. };