Resolve array of queries in one Transaction
See original GitHub issueUsing a global connection like here #164 for use Transaction. I think this works but how i can do to resolve a array of queries using transaction or multiples transactions, the code i put works only for one querie.
routes/set1Transaction.js
var sql = require('mssql');
module.exports = function(globalConnection) {
return function(req, res, next) {
var transaction = new sql.Transaction(globalConnection);
transaction.begin(function(err) {
// ... error checks
var request = new sql.Request(transaction);
request.query('insert into mytable (mycolumn) values (12345)', function(err, recordset) {
// ... error checks
transaction.commit(function(err, recordset) {
// ... error checks
console.log("Transaction commited.");
});
});
});
req.results=recordset;
next();
}
};
Issue Analytics
- State:
- Created 8 years ago
- Comments:12 (3 by maintainers)
Top Results From Across the Web
How to Implement Multiple Queries Transactions with Node.JS ...
The easiest way to solve this is by having a function that runs a transaction on an undefined number queries and returning all...
Read more >mysql - how to run transaction of a dynamic array of queries
I used node-mysql-transaction var transaction = require('node-mysql-transaction'); var trCon = transaction({connection: [mysql.
Read more >Transactions and promises in Node.js | by Pavel Romanov
We have a database which need to be consistently updated with some batch of data and Node.JS application which executes queries in database....
Read more >Multi-statement transactions | BigQuery - Google Cloud
The following query returns the active transactions for a particular job, specified by the ID of the job that is running the multi-statement...
Read more >node_modules/pg-promise - GitLab - SMHI
Transactions, functions, flexible query formatting; ... When a value/property inside array/object is an array, it is treated as a PostgreSQL Array Type, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I found this during my solution research and I think for v4.x this is nicer with ES6 and
async/awaitHi, only im passing for says thanks and told how i resolved this, i used a constructor function named ‘setUpMultipleQueries’, is a forEach using the ‘listQuery’. Well i leave the code. Thanks!