eip-cloud-services 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/package.json +2 -2
  2. package/src/gcp.js +1 -1
  3. package/src/mysql.js +16 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eip-cloud-services",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Houses a collection of helpers for connecting with Cloud services.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,4 +22,4 @@
22
22
  "mysql": "^2.18.1",
23
23
  "redis": "^4.6.7"
24
24
  }
25
- }
25
+ }
package/src/gcp.js CHANGED
@@ -8,7 +8,7 @@ exports.initialiseGoogleAuth = async () => {
8
8
 
9
9
  try {
10
10
  await readFile ( `${os.tmpdir ()}/gcp.json` );
11
- process.env.GOOGLE_APPLICATION_CREDENTIALS = './gcp.json';
11
+ process.env.GOOGLE_APPLICATION_CREDENTIALS = `${os.tmpdir ()}/gcp.json`;
12
12
 
13
13
  return;
14
14
  }
package/src/mysql.js CHANGED
@@ -1,16 +1,22 @@
1
1
  const mysql = require ( 'mysql' );
2
2
  const config = require ( 'config' );
3
3
 
4
- const pool = mysql.createPool (
5
- {
6
- connectionLimit: config.mysql.connectionLimit,
7
- host: config.mysql.host,
8
- user: config.mysql.user,
9
- password: config.mysql.password,
10
- database: config.mysql.database,
11
- multipleStatements: true
4
+ let pool = null;
5
+
6
+ function getPool () {
7
+ if ( !pool ) {
8
+ pool = mysql.createPool ( {
9
+ connectionLimit: config.mysql.connectionLimit,
10
+ host: config.mysql.host,
11
+ user: config.mysql.user,
12
+ password: config.mysql.password,
13
+ database: config.mysql.database,
14
+ multipleStatements: true
15
+ } );
12
16
  }
13
- );
17
+
18
+ return pool;
19
+ }
14
20
 
15
21
  const newQuery = ( connection, query ) => new Promise ( ( resolve, reject ) => {
16
22
  connection.query ( query, ( error, results, fields ) => {
@@ -27,7 +33,7 @@ const newQuery = ( connection, query ) => new Promise ( ( resolve, reject ) => {
27
33
  } );
28
34
 
29
35
  const getConnection = () => new Promise ( ( resolve, reject ) => {
30
- pool.getConnection ( ( error, connection ) => {
36
+ getPool ().getConnection ( ( error, connection ) => {
31
37
  if ( error ) {
32
38
  console.log ( error );
33
39
  console.error ( 'There was a problem getting a new database connection.' );