I'm currently using Peewee as an ORM in my project. In my current situation, I have some processes each having a database connection. All of these processes need to access a certain table simultaneously. I'm looking for some way to make them coordinated without using a central controller. For this, when a row is read by a process, it must get locked and no other process could read that row. Blocked processes should continue with other non-blocked rows.
I searched around and found that MySql already has an internal locking mechanism, described here and apparently it must be used on indexed columns to behave as expected (from here). But I couldn't find anything related in the peewee documents. Is there any extension providing these feature? Or should i write raw SQL queries containing FOR Update
clause?
NOWAIT
orSKIP LOCKED
? I can't find anything in the documents. Another question, you said that "usingFOR UPDATE
won't prevent other clients from reading", so how can i prevent these reads ? I know thatSELECT ... FOR SHARE
are blocked but simpleSELECT
queries are not blocked. – Malanie