I have one table, when a new row is added to it, all existing rows need to be updated. Essentially, before one "insert" is finished, I don't want to allow another "insert" to take place.
So I guess normal row level lock or read lock is not enough and want to directly lock the tables during the transaction.
Is there a way to manually lock tables (in ACCESS EXCLUSIVE mode) in Knex?
My guess is that this will involve:
running raw sqls (lock and unlock) and make sure the same
connection is used for the transaction.
Is there a way to do that? or I there are better solution to my problem.
p.s. another approach I'm exploring is to use a job queue and let a single worker to insert records (using a raw sql connection). But I was told this will not work in a multiple node scenario.