If I run SELECT ... FOR UPDATE inside an interacti...
# prisma-client
j
If I run SELECT ... FOR UPDATE inside an interactive transaction, when is the row actually locked? Is it when that line of code runs, or is it when the transaction is committed?
n
Wouldn’t this depend upon which database you are using and what are your database settings. For Example In the case of MySQL:
Locking of rows for update using
SELECT FOR UPDATE
only applies when autocommit is disabled (either by beginning transaction with
START TRANSACTION
or by setting autocommit to 0. If autocommit is enabled, the rows matching the specification are not locked.
In other words, if you don’t execute your first
SELECT FOR UPDATE
inside a transaction, no rows are locked. Reference: MySQL Docs
j
Yeah, I am on MySQL and executing it inside the prisma interactive transaction callback. Just curious about if the SELECT FOR actually hits the database before the callback completes. From some testing it seems like it does, but confirmation would be great
n
I also think it does, please let me know if you get other unexpected result from testing.