mysql-await
Advanced tools
Comparing version 2.1.8 to 2.2.0
213
index.js
@@ -17,2 +17,6 @@ /** Require external modules */ | ||
this.config = this.connection.config; | ||
if ( arguments[0] && arguments[0].throwErrors ) | ||
this.config.throwErrors = true; | ||
this.inTransaction = false; | ||
@@ -30,4 +34,10 @@ } | ||
this.connection.beginTransaction((err) => { | ||
if ( err ) | ||
return reject(err); | ||
if ( err ) { | ||
this.connection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
reject(err); | ||
else | ||
resolve(); | ||
} | ||
@@ -49,4 +59,10 @@ this.inTransaction = true; | ||
this.connection.changeUser(params, (err) => { | ||
if ( err ) | ||
return reject(err); | ||
if ( err ) { | ||
this.connection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
reject(err); | ||
else | ||
resolve(); | ||
} | ||
@@ -70,7 +86,17 @@ resolve(); | ||
this.inTransaction = false; | ||
reject(err); | ||
this.connection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
reject(err); | ||
else | ||
resolve(); | ||
}); | ||
} else { | ||
this.inTransaction = false; | ||
reject(err); | ||
this.connection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
reject(err); | ||
else | ||
resolve(); | ||
} | ||
@@ -93,4 +119,10 @@ } else { | ||
this.connection.connect((err) => { | ||
if ( err ) | ||
return reject(err); | ||
if ( err ) { | ||
this.connection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
return reject(err); | ||
else | ||
return resolve(); | ||
} | ||
@@ -110,4 +142,10 @@ resolve(); | ||
this.connection.destroy((err) => { | ||
if ( err ) | ||
return reject(err); | ||
if ( err ) { | ||
this.connection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
return reject(err); | ||
else | ||
return resolve(); | ||
} | ||
@@ -127,4 +165,10 @@ resolve(); | ||
this.connection.end((err) => { | ||
if ( err ) | ||
return reject(err); | ||
if ( err ) { | ||
this.connection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
return reject(err); | ||
else | ||
return resolve(); | ||
} | ||
@@ -141,3 +185,3 @@ resolve(); | ||
* @returns Promise | ||
* @description Queries the MySQL database, returning a [Promise] that resolves when finished or rejects on error. | ||
* @description Queries the MySQL database, returning a [Promise] that resolves when finished, emitting an error if one is encountered. | ||
*/ | ||
@@ -152,6 +196,16 @@ awaitQuery(query, params) { | ||
this.inTransaction = false; | ||
reject(err); | ||
this.connection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
reject(err); | ||
else | ||
resolve(); | ||
}); | ||
} else { | ||
reject(err); | ||
this.connection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
reject(err); | ||
else | ||
resolve(); | ||
} | ||
@@ -168,6 +222,16 @@ } else { | ||
this.inTransaction = false; | ||
reject(err); | ||
this.connection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
reject(err); | ||
else | ||
resolve(); | ||
}); | ||
} else { | ||
reject(err); | ||
this.connection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
reject(err); | ||
else | ||
resolve(); | ||
} | ||
@@ -188,3 +252,3 @@ } else { | ||
awaitRollback() { | ||
return new Promise((resolve, reject) => { | ||
return new Promise((resolve) => { | ||
this.connection.rollback(() => { | ||
@@ -307,5 +371,11 @@ resolve(); | ||
this.pool.end((err) => { | ||
if ( err ) | ||
return reject(err); | ||
if ( err ) { | ||
this.pool.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
return reject(err); | ||
else | ||
return resolve(); | ||
} | ||
resolve(); | ||
@@ -326,4 +396,10 @@ }); | ||
this.pool.getConnection((err, connection) => { | ||
if ( err ) | ||
return reject(err); | ||
if ( err ) { | ||
this.pool.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
return reject(err); | ||
else | ||
return resolve(); | ||
} | ||
@@ -340,4 +416,10 @@ connection.inTransaction = false; | ||
this.beginTransaction((err) => { | ||
if ( err ) | ||
return reject(err); | ||
if ( err ) { | ||
connection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
return reject(err); | ||
else | ||
return resolve(); | ||
} | ||
@@ -359,4 +441,10 @@ this.inTransaction = true; | ||
this.changeUser(params, (err) => { | ||
if ( err ) | ||
return reject(err); | ||
if ( err ) { | ||
connection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
return reject(err); | ||
else | ||
return resolve(); | ||
} | ||
@@ -380,7 +468,17 @@ resolve(); | ||
this.inTransaction = false; | ||
reject(err); | ||
tconnection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
reject(err); | ||
else | ||
resolve(); | ||
}); | ||
} else { | ||
this.inTransaction = false; | ||
reject(err); | ||
connection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
reject(err); | ||
else | ||
resolve(); | ||
} | ||
@@ -400,3 +498,3 @@ } else { | ||
* @returns Promise | ||
* @description Queries the MySQL database, returning a [Promise] that resolves when finished or rejects on error. | ||
* @description Queries the MySQL database, returning a [Promise] that resolves when finished, emitting an error if one is encountered. | ||
*/ | ||
@@ -407,4 +505,10 @@ connection.awaitQuery = function (query, params) { | ||
this.query(query, (err, result) => { | ||
if ( err ) | ||
return reject(err); | ||
if ( err ) { | ||
connection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
return reject(err); | ||
else | ||
return resolve(); | ||
} | ||
@@ -419,6 +523,16 @@ resolve(result); | ||
this.inTransaction = false; | ||
reject(err); | ||
connection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
reject(err); | ||
else | ||
resolve(); | ||
}); | ||
} else { | ||
reject(err); | ||
connection.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
reject(err); | ||
else | ||
resolve(); | ||
} | ||
@@ -439,3 +553,3 @@ } else { | ||
connection.awaitRollback = function () { | ||
return new Promise((resolve, reject) => { | ||
return new Promise((resolve) => { | ||
this.rollback(() => { | ||
@@ -457,3 +571,3 @@ resolve(); | ||
* @returns Promise | ||
* @description Queries the MySQL database, returning a [Promise] that resolves when finished or rejects on error. | ||
* @description Queries the MySQL database, returning a [Promise] that resolves when finished, emitting an error if one is encountered. | ||
*/ | ||
@@ -465,4 +579,10 @@ awaitQuery(query, params) { | ||
this.pool.query(query, (err, result) => { | ||
if ( err ) | ||
return reject(err); | ||
if ( err ) { | ||
this.pool.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
return reject(err); | ||
else | ||
return resolve(); | ||
} | ||
@@ -473,4 +593,10 @@ resolve(result); | ||
this.pool.query(query, params, (err, result) => { | ||
if ( err ) | ||
return reject(err); | ||
if ( err ) { | ||
this.pool.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
return reject(err); | ||
else | ||
return resolve(); | ||
} | ||
@@ -481,3 +607,8 @@ resolve(result); | ||
} catch ( err ) { | ||
reject(err); | ||
this.pool.emit(`error`, err); | ||
if ( this.config.throwErrors ) | ||
reject(err); | ||
else | ||
resolve(); | ||
} | ||
@@ -484,0 +615,0 @@ }); |
{ | ||
"name": "mysql-await", | ||
"version": "2.1.8", | ||
"version": "2.2.0", | ||
"description": "Backward Compatible MySQL Async/Await Connection Wrapper", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
# MySQL Async/Await Wrapper v2.1.8 | ||
# MySQL Async/Await Wrapper v2.2.0 | ||
@@ -59,6 +59,9 @@ Simple wrapper for MySQL async/await functionality. Intended for functionality to mimic the popular [mysql](https://github.com/mysqljs/mysql) Node.js callback-based package, but with additional methods for awaiting execution. Goal is for normal methods to be unaffected and only additional await methods added, though accomplished through intermediary class objects. | ||
"password" : "secret", | ||
"database" : "my_db" | ||
"database" : "my_db", | ||
"throwErrors" : false | ||
} | ||
``` | ||
**Note:** `throwErrors` is used to determine whether MySQL errors should be thrown AND emitted, or only emitted | ||
## Example Using Single Connection | ||
@@ -221,3 +224,4 @@ | ||
* Thanks, @DavidvanDriessche, for identifying a significant issue with error handling | ||
* THanks, @DonaldKellet, for identifying missing arguments on the escape() and escapeId() functions | ||
* Thanks, @DonaldKellet, for identifying missing arguments on the escape() and escapeId() functions | ||
* Thanks, @Andromeda606, for identifying issues with connection.on() events | ||
@@ -224,0 +228,0 @@ ## License |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29514
7
687
229
7