How to lock table in sequelize, wait until another request to be complete

前端 未结 1 1796
失恋的感觉
失恋的感觉 2021-01-17 15:11

Description:

I have one table in db say Table1. having only one column AppNo(numeric) and only single row, and current val

1条回答
  •  醉梦人生
    2021-01-17 15:43

    This is not very well documented or easy to find, but what you want is a Transaction that wraps your find query which uses a lock option to turn it into a SELECT FOR UPDATE statement.

    The find query with the lock option will lock the row (you don't need to lock the entire table) and because you are using a transaction, the action will either be committed or rolled back depending on whether or not your instance holds the lock.

    You will want to adapt the code found in these examples for your use.

    0 讨论(0)
提交回复
热议问题