Saturday 11 March 2017

Lock table during transaction with Knex/Postgresql

Is it possible to ask knex/bookshelf to lock a table during a transaction (in this case before an insert)? I am actually trying to add a randomly generated unique code that matches a very specific format to each entry of this table. But I know that I could face huge issues because of concurrent writings.

What basically happens is :

  • Query the db to know if this code has already been assigned to another entry
  • If not, insert it in the table

How could I proceed to disallow inserts during the entire transaction ?

Thank you in advance



via vesna

No comments:

Post a Comment