Optimistic and pessimistic blocking in Node / Postgres?

I plan to use Node for my next project, because it seems to be suitable for the problem I am solving.

One thing I need to find out is an optimistic and pessimistic block. http://guides.rubyonrails.org/active_record_querying.html#locking-records-for-update

Let's say the user has balance 1. Two Node instances make requests simultaneously with revocation 1. Two requests can simultaneously check for sufficient balance, thus making two successful withdrawals, resulting in a balance of -1.

Rails provides a wrapper for Postgres transactional and blocking functions. Is there any similar shell for Node?

How do you solve this in Node / Postgresql?

I know this is a database function, but I wonder if Node or some library can ignore writing raw SQL queries?

+4
source share

All Articles