Best practice for querying then updating to a model with lb

22 vistas
Ir al primer mensaje no leído

xiaolu liu

no leída,
4 ago 2017, 7:45:04 a.m.4/8/17
para LoopbackJS

Hi guys,
Thanks for providing such amazing framework, however, I am not sure how to handle the following cases with loopback:

  1. I have a 'idInjected' model, so the primary id is unknown. I have to findOne with a condition first then save or create the instance according to the finding result.
  2. I know the primary Id, but I don't know the current field value, so I have to findById first then do some caculation based on the current value. e.g. page.viewed += 1; page.save();

However, we may face a race condition when some concurrent requests hit, due to find/update are async methods.

Do we have locker or something for loopback to handle these cases. Any suggestions are welcome!

Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos