Skip to content

Commit df2635f

Browse files
lint and cleanup transactional machines
1 parent 56f82fb commit df2635f

File tree

3 files changed

+100
-33
lines changed

3 files changed

+100
-33
lines changed

machines/begin-transaction.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,20 @@ module.exports = {
1212

1313
inputs: {
1414

15-
connection:
16-
require('../constants/connection.input'),
15+
connection: {
16+
friendlyName: 'Connection',
17+
description: 'An active database connection.',
18+
extendedDescription: 'The provided database connection instance must still be active. Only database connection instances created by the `getConnection()` machine in this driver are supported.',
19+
example: '===',
20+
required: true
21+
},
1722

18-
meta:
19-
require('../constants/meta.input')
23+
meta: {
24+
friendlyName: 'Meta (custom)',
25+
description: 'Additional stuff to pass to the driver.',
26+
extendedDescription: 'This is reserved for custom driver-specific extensions. Please refer to the documentation for the driver you are using for more specific information.',
27+
example: '==='
28+
}
2029

2130
},
2231

@@ -33,29 +42,43 @@ module.exports = {
3342
}
3443
},
3544

36-
badConnection:
37-
require('../constants/badConnection.exit')
45+
badConnection: {
46+
friendlyName: 'Bad connection',
47+
description: 'The provided connection is not valid or no longer active. Are you sure it was obtained by calling this driver\'s `getConnection()` method?',
48+
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.',
49+
outputVariableName: 'report',
50+
outputDescription: 'The `meta` property is reserved for custom driver-specific extensions.',
51+
example: {
52+
error: '===',
53+
meta: '==='
54+
}
55+
}
3856

3957
},
4058

4159

42-
fn: function (inputs, exits) {
60+
fn: function beginTransaction(inputs, exits) {
4361
var Pack = require('../');
4462

4563
// Since we're using `sendNativeQuery()` to access the underlying connection,
4664
// we have confidence it will be validated before being used.
4765
Pack.sendNativeQuery({
4866
connection: inputs.connection,
49-
query: 'START TRANSACTION'
67+
nativeQuery: 'BEGIN'
5068
}).exec({
5169
error: function error(err) {
5270
return exits.error(err);
5371
},
54-
badConnection: function badConnection(report){
55-
return exits.badConnection(report);
72+
badConnection: function badConnection(report) {
73+
return exits.badConnection({
74+
error: report,
75+
meta: inputs.meta
76+
});
5677
},
5778
success: function success() {
58-
return exits.success();
79+
return exits.success({
80+
meta: inputs.meta
81+
});
5982
}
6083
});
6184
}

machines/commit-transaction.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,20 @@ module.exports = {
1515

1616
inputs: {
1717

18-
connection:
19-
require('../constants/connection.input'),
18+
connection: {
19+
friendlyName: 'Connection',
20+
description: 'An active database connection.',
21+
extendedDescription: 'The provided database connection instance must still be active. Only database connection instances created by the `getConnection()` machine in this driver are supported.',
22+
example: '===',
23+
required: true
24+
},
2025

21-
meta:
22-
require('../constants/meta.input')
26+
meta: {
27+
friendlyName: 'Meta (custom)',
28+
description: 'Additional stuff to pass to the driver.',
29+
extendedDescription: 'This is reserved for custom driver-specific extensions. Please refer to the documentation for the driver you are using for more specific information.',
30+
example: '==='
31+
}
2332

2433
},
2534

@@ -36,29 +45,43 @@ module.exports = {
3645
}
3746
},
3847

39-
badConnection:
40-
require('../constants/badConnection.exit')
48+
badConnection: {
49+
friendlyName: 'Bad connection',
50+
description: 'The provided connection is not valid or no longer active. Are you sure it was obtained by calling this driver\'s `getConnection()` method?',
51+
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.',
52+
outputVariableName: 'report',
53+
outputDescription: 'The `meta` property is reserved for custom driver-specific extensions.',
54+
example: {
55+
error: '===',
56+
meta: '==='
57+
}
58+
}
4159

4260
},
4361

4462

45-
fn: function (inputs, exits) {
63+
fn: function commitTransaction(inputs, exits) {
4664
var Pack = require('../');
4765

4866
// Since we're using `sendNativeQuery()` to access the underlying connection,
4967
// we have confidence it will be validated before being used.
5068
Pack.sendNativeQuery({
5169
connection: inputs.connection,
52-
query: 'COMMIT'
70+
nativeQuery: 'COMMIT'
5371
}).exec({
5472
error: function error(err) {
5573
return exits.error(err);
5674
},
57-
badConnection: function badConnection(report){
58-
return exits.badConnection(report);
75+
badConnection: function badConnection(report) {
76+
return exits.badConnection({
77+
error: report,
78+
meta: inputs.meta
79+
});
5980
},
6081
success: function success() {
61-
return exits.success();
82+
return exits.success({
83+
meta: inputs.meta
84+
});
6285
}
6386
});
6487
}

machines/rollback-transaction.js

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,20 @@ module.exports = {
1515

1616
inputs: {
1717

18-
connection:
19-
require('../constants/connection.input'),
18+
connection: {
19+
friendlyName: 'Connection',
20+
description: 'An active database connection.',
21+
extendedDescription: 'The provided database connection instance must still be active. Only database connection instances created by the `getConnection()` machine in this driver are supported.',
22+
example: '===',
23+
required: true
24+
},
2025

21-
meta:
22-
require('../constants/meta.input')
26+
meta: {
27+
friendlyName: 'Meta (custom)',
28+
description: 'Additional stuff to pass to the driver.',
29+
extendedDescription: 'This is reserved for custom driver-specific extensions. Please refer to the documentation for the driver you are using for more specific information.',
30+
example: '==='
31+
}
2332

2433
},
2534

@@ -36,29 +45,41 @@ module.exports = {
3645
}
3746
},
3847

39-
badConnection:
40-
require('../constants/badConnection.exit')
48+
badConnection: {
49+
friendlyName: 'Meta (custom)',
50+
description: 'Additional stuff to pass to the driver.',
51+
extendedDescription: 'This is reserved for custom driver-specific extensions. Please refer to the documentation for the driver you are using for more specific information.',
52+
example: {
53+
error: '===',
54+
meta: '==='
55+
}
56+
}
4157

4258
},
4359

4460

45-
fn: function (inputs, exits) {
61+
fn: function rollbackTransaction(inputs, exits) {
4662
var Pack = require('../');
4763

4864
// Since we're using `sendNativeQuery()` to access the underlying connection,
4965
// we have confidence it will be validated before being used.
5066
Pack.sendNativeQuery({
5167
connection: inputs.connection,
52-
query: 'ROLLBACK'
68+
nativeQuery: 'ROLLBACK'
5369
}).exec({
5470
error: function error(err) {
5571
return exits.error(err);
5672
},
57-
badConnection: function badConnection(report){
58-
return exits.badConnection(report);
73+
badConnection: function badConnection(report) {
74+
return exits.badConnection({
75+
error: report,
76+
meta: inputs.meta
77+
});
5978
},
6079
success: function success() {
61-
return exits.success();
80+
return exits.success({
81+
meta: inputs.meta
82+
});
6283
}
6384
});
6485
}

0 commit comments

Comments
 (0)