Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

New feature: skipLocked() on the Query Builder/Eloquent ORM ( SKIP LOCKED )#49451

Unanswered
kevineduardo asked this question inIdeas
Discussion options

As far as I know, I need to dolock('FOR UPDATE SKIP LOCKED') to work with skip locked, but would be much easier to just have a method like "skipLocked()".

You must be logged in to vote

Replies: 1 comment

Comment options

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.');}
You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Ideas
Labels
None yet
2 participants
@kevineduardo@MohammadZarifiyan

[8]ページ先頭

©2009-2025 Movatter.jp