Last active
June 17, 2019 21:27
-
-
Save B4nan/5c0fb52c31fe2af55bfb3279e0cdff27 to your computer and use it in GitHub Desktop.
Perssimistic locking in MikroORM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| await em.transactional(async _em => { | |
| await _em.findOne(Author, id, { lockMode: LockMode.PESSIMISTIC_WRITE }); | |
| }); | |
| // START TRANSACTION | |
| // SELECT `e0`.* FROM `author` AS `e0` WHERE `e0`.`id` = ? FOR UPDATE | |
| // COMMIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const author = orm.em.findOne(Author, id); | |
| // ... | |
| await orm.em.transactional(async em => { | |
| await em.lock(author, LockMode.PESSIMISTIC_READ); | |
| }); | |
| // SELECT `e0`.* FROM `author` AS `e0` WHERE `e0`.`id` = ? | |
| // START TRANSACTION | |
| // SELECT 1 FROM `author` AS `e0` WHERE `e0`.`id` = ? LOCK IN SHARE MODE | |
| // COMMIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment