ehmpathy / sql-dao-generator

Generate data-access-objects from your domain-objects
MIT License
0 stars 0 forks source link

support optimistic locking #9

Open uladkasach opened 2 years ago

uladkasach commented 2 years ago

upserts should support optimisitc locking for concurrency control

for example, the contract could look like

const upsertedSms = await smsDao.upsert({
    dbConnection: dbConnectionInTransaction,
     sms: new Sms({ ...sms, status: statusNow }),
     lockOn: sms.versionId, // abort the txn if the versionId has changed since the read (i.e., there was a parallel, conflicting write that came before it);
});

refs:

uladkasach commented 2 years ago

this should also support saying lockOn: null

this will enable this one simple "upsert" command to be used in high concurrency operations to allow the user to atomically/safely fulfill the use case of:

by letting the user specify to the command their expectation that the row does not exist: