-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
49 lines (44 loc) · 1.3 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict';
// Load NPM modules
const autoBind = require('auto-bind');
// Load library modules
const PoolCore = require('./lib/pool');
// Build instance
class MySQLPoolManagerInstance extends PoolCore {
// Initial constructor
constructor(options) {
// Allow access to 'this'
super() && autoBind(this);
// Check configuration
return this.config(options);
}
// Function: Assign settings
config(options) {
// Define required properties
const props = [
'idlePoolTimeout',
'errorLimit',
'preInitDelay',
'sessionTimeout',
'maxConnextionTimeout',
'idleCheckInterval',
];
// Validation configuration
props.forEach(prop => {
if (!options.hasOwnProperty(prop)) {
throw new Error(`The required property ${prop} is not defined!`);
}
if (typeof options[prop] !== 'number' && props.includes(prop)) {
throw new Error(`The property ${prop} is not a number!`);
}
});
// Check mysql settings are defined
if (typeof options.mySQLSettings !== 'object') {
throw new Error(`MySQL settings are not defined or not an object!`);
}
// Spread options to this
return (this.options = Object.assign({}, options)) && this;
}
}
// Exports
module.exports = options => new MySQLPoolManagerInstance(options);