Skip to content

Commit 4a9cbd1

Browse files
committed
Finish stubbing compatibility.
1 parent c23aa14 commit 4a9cbd1

9 files changed

+209
-41
lines changed

constants/badConnection.exit.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ module.exports = {
77
description: 'The provided connection is not valid or no longer active. Are you sure it was obtained by calling this driver\'s `getConnection()` method?',
88
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.',
99
outputVariableName: 'report',
10-
outputDescription: 'The `error` property is a JavaScript Error instance containing the raw error from the database. The `meta` property is reserved for custom driver-specific extensions.',
10+
outputDescription: 'The `meta` property is reserved for custom driver-specific extensions.',
1111
example: {
12-
error: '===',
1312
meta: '==='
1413
}
1514
};

machines/create-manager.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
module.exports = {
2+
3+
4+
friendlyName: 'Create manager',
5+
6+
7+
description: 'Build and initialize a connection manager instance for this database.',
8+
9+
10+
extendedDescription:
11+
'The `manager` instance returned by this method contains any configuration that is necessary '+
12+
'for communicating with the database and establishing connections (e.g. host, user, password) '+
13+
'as well as any other relevant metadata. The manager will often also contain a reference '+
14+
'to some kind of native container (e.g. a connection pool).\n'+
15+
'\n'+
16+
'Note that a manager instance does not necessarily need to correspond with a pool though--'+
17+
'it might simply be a container for storing config, or it might refer to multiple pools '+
18+
'(e.g. a ClusterPool from felixge\'s `mysql` package).',
19+
20+
21+
inputs: {
22+
23+
connectionString: {
24+
description: 'A connection string to use to connect to a MySQL database.',
25+
extendedDescription: 'Be sure to include credentials. You can also optionally provide the name of an existing database on your MySQL server.',
26+
moreInfoUrl: 'https://gist.github.com/mikermcneil/46d10fd816c980cd3d9f',
27+
whereToGet: {
28+
url: 'https://gist.github.com/mikermcneil/46d10fd816c980cd3d9f'
29+
},
30+
example: 'mysql://mikermcneil:p4ssw02D@localhost:3306/some_db',
31+
required: true
32+
},
33+
34+
onUnexpectedFailure: {
35+
description: 'A function to call any time an unexpected error event is received from this manager or any of its connections.',
36+
extendedDescription:
37+
'This can be used for anything you like, whether that\'s sending an email to devops, '+
38+
'or something as simple as logging a warning to the console.\n'+
39+
'\n'+
40+
'For example:\n'+
41+
'```\n'+
42+
'onUnexpectedFailure: function (err) {\n'+
43+
' console.warn(\'Unexpected failure in database manager:\',err);\n'+
44+
'}\n'+
45+
'```',
46+
example: '->'
47+
},
48+
49+
meta:
50+
require('../constants/meta.input')
51+
52+
},
53+
54+
55+
exits: {
56+
57+
success: {
58+
description: 'The manager was successfully created.',
59+
extendedDescription:
60+
'The new manager should be passed in to `getConnection()`.'+
61+
'Note that _no matter what_, this manager must be capable of '+
62+
'spawning an infinite number of connections (i.e. via `getConnection()`). '+
63+
'The implementation of how exactly it does this varies on a driver-by-driver '+
64+
'basis; and it may also vary based on the configuration passed into the `meta` input.',
65+
outputVariableName: 'report',
66+
outputDescription: 'The `manager` property is a manager instance that will be passed into `getConnection()`. The `meta` property is reserved for custom driver-specific extensions.',
67+
example: {
68+
manager: '===',
69+
meta: '==='
70+
}
71+
},
72+
73+
malformed: {
74+
description: 'The provided connection string is not valid for MySQL.',
75+
outputVariableName: 'report',
76+
outputDescription: 'The `error` property is a JavaScript Error instance explaining that (and preferably "why") the provided connection string is invalid. The `meta` property is reserved for custom driver-specific extensions.',
77+
example: {
78+
error: '===',
79+
meta: '==='
80+
}
81+
},
82+
83+
failed: {
84+
description: 'Could not create a connection manager for this database using the specified connection string.',
85+
extendedDescription:
86+
'If this exit is called, it might mean any of the following:\n'+
87+
' + the credentials encoded in the connection string are incorrect\n'+
88+
' + there is no database server running at the provided host (i.e. even if it is just that the database process needs to be started)\n'+
89+
' + there is no software "database" with the specified name running on the server\n'+
90+
' + the provided connection string does not have necessary access rights for the specified software "database"\n'+
91+
' + this Node.js process could not connect to the database, perhaps because of firewall/proxy settings\n'+
92+
' + any other miscellaneous connection error\n'+
93+
'\n'+
94+
'Note that even if the database is unreachable, bad credentials are being used, etc, '+
95+
'this exit will not necessarily be called-- that depends on the implementation of the driver '+
96+
'and any special configuration passed to the `meta` input. e.g. if a pool is being used that spins up '+
97+
'multiple connections immediately when the manager is created, then this exit will be called if any of '+
98+
'those initial attempts fail. On the other hand, if the manager is designed to produce adhoc connections, '+
99+
'any errors related to bad credentials, connectivity, etc. will not be caught until `getConnection()` is called.',
100+
outputVariableName: 'report',
101+
outputDescription: 'The `error` property is a JavaScript Error instance with more information and a stack trace. The `meta` property is reserved for custom driver-specific extensions.',
102+
example: {
103+
error: '===',
104+
meta: '==='
105+
}
106+
}
107+
108+
},
109+
110+
111+
fn: function (inputs, exits){
112+
// TODO
113+
return exits.error();
114+
}
115+
116+
117+
};

machines/destroy-manager.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
module.exports = {
2+
3+
4+
friendlyName: 'Destroy manager',
5+
6+
7+
description: 'Destroy the specified connection manager and destroying all of its active connections.',
8+
9+
10+
extendedDescription: 'This may involve destroying a single connection, destroying a pool and its connections, destroying multiple pools and their connections, or something even more exotic. The implementation is left up to the driver.',
11+
12+
13+
inputs: {
14+
15+
manager: {
16+
friendlyName: 'Manager',
17+
description: 'The connection manager instance to destroy.',
18+
extendedDescription: 'Only managers built using the `createManager()` method of this driver are supported. Also, the database connection manager instance provided must not have been destroyed--i.e. once `destroyManager()` is called on a manager, it cannot be destroyed again (also note that all existing connections become inactive).',
19+
example: '===',
20+
required: true
21+
},
22+
23+
meta:
24+
require('../constants/meta.input')
25+
26+
},
27+
28+
29+
exits: {
30+
31+
success: {
32+
description: 'The specified manager and all of its active connections were successfully destroyed.',
33+
outputVariableName: 'report',
34+
outputDescription: 'The `meta` property is reserved for custom driver-specific extensions.',
35+
example: {
36+
meta: '==='
37+
}
38+
},
39+
40+
badManager: {
41+
friendlyName: 'Bad manager',
42+
description: 'The provided connection manager is no longer active; or possibly never was.',
43+
extendedDescription:
44+
'Usually, this means the manager has already been destroyed. But depending on the driver '+
45+
'it could also mean that database cannot be accessed. In production, this can mean that the database '+
46+
'server(s) became overwhelemed or were shut off while some business logic was in progress.',
47+
outputVariableName: 'report',
48+
outputDescription: 'The `error` property is a JavaScript Error instance with more information and a stack trace. The `meta` property is reserved for custom driver-specific extensions.',
49+
example: {
50+
error: '===',
51+
meta: '==='
52+
}
53+
}
54+
55+
},
56+
57+
58+
fn: function (inputs, exits){
59+
// TODO
60+
return exits.error();
61+
}
62+
63+
64+
};

machines/get-connection.js

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ module.exports = {
99

1010
inputs: {
1111

12-
connectionString: {
13-
description: 'A connection string to use to connect to a MySQL database.',
14-
extendedDescription: 'Be sure to include credentials. You can also optionally provide the name of an existing database on your MySQL server.',
15-
moreInfoUrl: 'https://gist.github.com/mikermcneil/46d10fd816c980cd3d9f',
16-
whereToGet: {
17-
url: 'https://gist.github.com/mikermcneil/46d10fd816c980cd3d9f'
18-
},
19-
example: 'mysql://mikermcneil:p4ssw02D@localhost:3306/some_db',
12+
manager: {
13+
friendlyName: 'Manager',
14+
description: 'The connection manager instance to acquire the connection from.',
15+
extendedDescription:
16+
'Only managers built using the `createManager()` method of this driver are supported. '+
17+
'Also, the database connection manager instance provided must not have been destroyed--'+
18+
'i.e. once `destroyManager()` is called on a manager, no more connections can be acquired '+
19+
'from it (also note that all existing connections become inactive-- see `destroyManager()` '+
20+
'for more on that).',
21+
example: '===',
2022
required: true
2123
},
2224

@@ -44,19 +46,8 @@ module.exports = {
4446
}
4547
},
4648

47-
malformed: {
48-
description: 'The provided connection string is malformed.',
49-
extendedDescription: 'The provided connection string is not valid for MySQL.',
50-
outputVariableName: 'report',
51-
outputDescription: 'The `error` property is a JavaScript Error instance explaining that (and preferably "why") the provided connection string is invalid. The `meta` property is reserved for custom driver-specific extensions.',
52-
example: {
53-
error: '===',
54-
meta: '==='
55-
}
56-
},
57-
58-
failedToConnect: {
59-
description: 'Could not acquire a connection to the database using the specified connection string.',
49+
failed: {
50+
description: 'Could not acquire a connection to the database using the specified manager.',
6051
extendedDescription: 'This might mean any of the following:\n'+
6152
' + the credentials encoded in the connection string are incorrect\n'+
6253
' + there is no database server running at the provided host (i.e. even if it is just that the database process needs to be started)\n'+

machines/parse-native-query-error.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ module.exports = {
1818

1919
inputs: {
2020

21-
queryType: {
22-
description: 'The type of query operation this raw error came from.',
23-
extendedDescription: 'Either "select", "insert", "delete", or "update". This determines how the provided raw error will be parsed/coerced.',
24-
required: true,
25-
example: 'select',// (select|insert|delete|update)
26-
},
27-
2821
nativeQueryError: {
2922
description: 'The error sent back from the database as a result of a failed native query.',
3023
extendedDescription: 'This is referring to the raw error; i.e. the `error` property of the dictionary returned through the `queryFailed` exit of `sendNativeQuery()` in this driver.',

machines/parse-native-query-result.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@ module.exports = {
1717

1818
queryType: {
1919
description: 'The type of query operation this raw result came from.',
20-
extendedDescription: 'Either "select", "insert", "delete", or "update". This determines how the provided raw result will be parsed/coerced.',
20+
moreInfoUrl: 'https://github.com/node-machine/waterline-driver-interface#query-results',
21+
extendedDescription:
22+
'Either "select", "insert", "destroy", "update", "count", "sum", or "avg". '+
23+
'This determines how the provided raw result will be parsed/coerced.',
2124
required: true,
22-
example: 'select',// (select|insert|delete|update)
25+
example: 'select',// (select|insert|destroy|update|count|sum|avg)
2326
},
2427

2528
nativeQueryResult: {
2629
description: 'The result data sent back from the the database as a result of a native query.',
2730
extendedDescription: 'Specifically, be sure to use the `result` property of the output report from a successful native query (i.e. don\'t include `meta`!) The data provided will be coerced to a JSON-serializable value if it isn\'t one already (see [rttc.dehydrate()](https://github.com/node-machine/rttc#dehydratevalue-allownullfalse-dontstringifyfunctionsfalse)). That means any Date instances therein will be converted to timezone-agnostic ISO timestamp strings (i.e. JSON timestamps).',
2831
required: true,
29-
example: '*'
32+
example: '==='
3033
},
3134

3235
meta:

machines/release-connection.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ module.exports = {
4949
// Release connection.
5050
try {
5151
inputs.connection.release();
52+
53+
// If we made it here, releasing the connection gracefully must have worked.
54+
return exits.success();
5255
}
5356
catch (_releaseErr) {
5457
// If the connection cannot be released back to the pool gracefully,
@@ -62,13 +65,9 @@ module.exports = {
6265
}
6366

6467
// Otherwise, forcing a disconnect worked:
65-
console.warn('Could not release MySQL connection gracefully, but connection was forcibly destroyed. Details:\n=== === ===\n'+_releaseErr.stack);
6668
return exits.success();
69+
// console.warn('Could not release MySQL connection gracefully, but connection was forcibly destroyed. Details:\n=== === ===\n'+_releaseErr.stack);
6770
}
68-
69-
// If we made it here, releasing the connection gracefully must have worked.
70-
return exits.success();
71-
7271
}
7372

7473

machines/send-native-query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = {
3737
outputDescription: 'The `result` property is the result data the database sent back. The `meta` property is reserved for custom driver-specific extensions.',
3838
moreInfoUrl: 'https://github.com/felixge/node-mysql#getting-the-id-of-an-inserted-row',
3939
example: {
40-
result: '*',
40+
result: '===',
4141
meta: '==='
4242
}
4343
},

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
"begin-transaction",
3636
"commit-transaction",
3737
"rollback-transaction",
38-
"compile-statement"
38+
"compile-statement",
39+
"create-manager",
40+
"destroy-manager"
3941
],
4042
"interfaces": [
4143
"driveable",
@@ -47,4 +49,4 @@
4749
"type": "git",
4850
"url": "[email protected]:particlebanana/machinepack-mysql.git"
4951
}
50-
}
52+
}

0 commit comments

Comments
 (0)