Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make transactions to wait multiple queries and execute them in a proper order #491

Closed
pleerock opened this Issue Jun 15, 2017 · 9 comments

Comments

Projects
None yet
9 participants
@pleerock
Copy link

pleerock commented Jun 15, 2017

Im migrating from v3 and v4 and now I have

TransactionError: Can't acquire connection for the request. There is another request in progress.

errors. Is it related to Transaction and PreparedStatement internal queues was removed release change somehow? If yes, then can you explain what it means?

@pleerock

This comment has been minimized.

Copy link
Author

pleerock commented Jun 15, 2017

I found this issue is related. What is the problem "to wait" until previous query finishes execution (yeah im talking about a single connection on a single transaction). I think this is how other database drivers (mysql,pg,sqlite,oracle) work as well

@pleerock pleerock changed the title what does "Transaction and PreparedStatement internal queues was removed" mean? make transactions to wait multiple queries and execute them in a proper order Jun 15, 2017

@rurumarisa

This comment has been minimized.

Copy link

rurumarisa commented Sep 1, 2017

I also found this issue in my program when I try to use it in a Promise queue (bluebird, promise.all, when I run my function and then throw this error), it seems like the request.query().then()... method is not a completely Promise.. If someone found out and resolved the question, please tell me about the reason~and I will also find out the resolution.

@davemeech

This comment has been minimized.

Copy link

davemeech commented Oct 16, 2017

Has there been any progress on this issue? I'm encountering this issue as well and I have no idea how to perform a proper transaction in 4.x. My case also has instances of multiple for loops for many to many relationship inserts.

@Jaloko

This comment has been minimized.

Copy link

Jaloko commented Dec 6, 2017

I am also encountering this issue when trying to use Promise.all with a transaction. I assume creating a function that executes an array of promises sequentially would work. For now I can use bulk for my needs. +1 for getting this working if possible though.

@NicoDino

This comment has been minimized.

Copy link

NicoDino commented Jan 12, 2018

Hey guys, I'm facing the same problem any updates on this?. I need to execute multiple insertions within a single transaction and obviously promise.all does not work, I'm trying work it around using a bulk insertion.
cheers!

@lostfields

This comment has been minimized.

Copy link

lostfields commented Mar 12, 2018

instead of results = await Promise.all(queries) you could do a results = []; for(let query of queries) results.push(await query)

but I can say, it's pretty frustrating to rewrite a mssql@3 to mssql@4 and it totally breaks my code since I have to fix all of them as it executes some code well (writes) and other fails in same process.

@mesaugat

This comment has been minimized.

Copy link

mesaugat commented Jun 5, 2018

Upgrading from v3 to v4 and I'm stuck at this. It is too frustrating. Can someone work on the fix?

@DHFW

This comment has been minimized.

Copy link

DHFW commented Aug 31, 2018

I had a similar issue with knex (which uses tediousjs for ms-sql). I had this:

exports.up = function(knex, Promise) {
return Promise.all([
  knex.schema.createTable('users') ...
  knex.schema.createTable('roles') ...
  knex.schema.createTable('userRoles') which references user
]);

Now, I'm using just awaits so everything is executed in order.

// Notice the async keyword
exports.up = async function(knex) {
  await knex.schema.createTable('users') ...
  await knex.schema.createTable('roles') ...
  await knex.schema.createTable('userRoles') which references user
};
@dhensby

This comment has been minimized.

Copy link
Collaborator

dhensby commented Mar 8, 2019

Sorry that the upgrade from 3 -> 4 broke expectations but it does seem that it was clearly documented that in v4 the library wouldn't queue queries for you anymore. If you're using Promise.all to execute queries in order, then you need to change your code to either chain your promises using .then or by awaiting the previous queries.

@dhensby dhensby closed this Mar 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.