-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from jeremydaly/v1.1.0
V1.1.0
- Loading branch information
Showing
3 changed files
with
26 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
* More detail regarding the MySQL module can be found here: | ||
* https://github.com/mysqljs/mysql | ||
* @author Jeremy Daly <[email protected]> | ||
* @version 1.0.0 | ||
* @version 1.1.0 | ||
* @license MIT | ||
*/ | ||
|
||
|
@@ -293,13 +293,19 @@ const transaction = () => { | |
let rollback = () => {} // default rollback event | ||
|
||
return { | ||
query: function(...args) { queries.push([...args]); return this }, | ||
query: function(...args) { | ||
if (typeof args[0] === 'function') { | ||
queries.push(args[0]) | ||
} else { | ||
queries.push(() => [...args]) | ||
} | ||
return this | ||
}, | ||
rollback: function(fn) { | ||
if (typeof fn === 'function') { rollback = fn } | ||
return this | ||
}, | ||
commit: async function() { return await commit(queries,rollback) }, | ||
queries | ||
commit: async function() { return await commit(queries,rollback) } | ||
} | ||
} | ||
|
||
|
@@ -314,7 +320,9 @@ const commit = async (queries,rollback) => { | |
// Loop through queries | ||
for (let i in queries) { | ||
// Execute the queries, pass the rollback as context | ||
results.push(await query.apply({rollback},queries[i])) | ||
let result = await query.apply({rollback},queries[i](results[results.length-1],results)) | ||
// Add the result to the main results accumulator | ||
results.push(result) | ||
} | ||
|
||
// Commit our transaction | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters