- Notifications
You must be signed in to change notification settings - Fork11.7k
New feature: skipLocked() on the Query Builder/Eloquent ORM ( SKIP LOCKED )#49451
Unanswered
kevineduardo asked this question inIdeas
-
As far as I know, I need to do |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment
-
This code has been already used in Laravel queue system. I think Laravel team should add this as a feature to Query Builder. publicfunctionlockForUpdateAndSkipLocked(){$connection =$this->getConnection();$databaseEngine =$connection->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME);$databaseVersion =$connection->getConfig('version') ??$connection->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);if (Str::of($databaseVersion)->contains('MariaDB')) {$databaseEngine ='mariadb';$databaseVersion = Str::before(Str::after($databaseVersion,'5.5.5-'),'-'); }elseif (Str::of($databaseVersion)->contains(['vitess','PlanetScale'])) {$databaseEngine ='vitess';$databaseVersion = Str::before($databaseVersion,'-'); }if (($databaseEngine ==='mysql' &&version_compare($databaseVersion,'8.0.1','>=')) || ($databaseEngine ==='mariadb' &&version_compare($databaseVersion,'10.6.0','>=')) || ($databaseEngine ==='pgsql' &&version_compare($databaseVersion,'9.5','>='))) {return$this->lock('FOR UPDATE SKIP LOCKED'); }if ($databaseEngine ==='sqlsrv') {return$this->lock('with(rowlock,updlock,readpast)'); }thrownewException('lockForUpdateAndSkipLocked is not supported with this database connection.');} |
BetaWas this translation helpful?Give feedback.
All reactions
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment