commit-transaction.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. module.exports = {
  2. friendlyName: 'Commit transaction',
  3. description: 'Commit the database transaction on the provided 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 committed.',
  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: 'Bad connection',
  34. description: 'The provided connection is not valid or no longer active. Are you sure it was obtained by calling this driver\'s `getConnection()` method?',
  35. extendedDescription: 'Usually, this means the connection to the database was lost due to a logic error or timing issue in userland code. In production, this can mean that the database became overwhelemed or was shut off while some business logic was in progress.',
  36. outputVariableName: 'report',
  37. outputDescription: 'The `meta` property is reserved for custom driver-specific extensions.',
  38. outputExample: '==='
  39. // outputExample: {
  40. // meta: '==='
  41. // }
  42. }
  43. },
  44. fn: function commitTransaction(inputs, exits) {
  45. var Pack = require('../');
  46. // Since we're using `sendNativeQuery()` to access the underlying connection,
  47. // we have confidence it will be validated before being used.
  48. Pack.sendNativeQuery({
  49. connection: inputs.connection,
  50. nativeQuery: 'COMMIT'
  51. }).switch({
  52. error: function error(err) {
  53. return exits.error(err);
  54. },
  55. badConnection: function badConnection() {
  56. return exits.badConnection({
  57. meta: inputs.meta
  58. });
  59. },
  60. success: function success() {
  61. return exits.success({
  62. meta: inputs.meta
  63. });
  64. }
  65. });
  66. }
  67. };