Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safer implementation for both MySQL and Postgres #1

Open
mpyw opened this issue Jul 14, 2022 · 0 comments
Open

Safer implementation for both MySQL and Postgres #1

mpyw opened this issue Jul 14, 2022 · 0 comments

Comments

@mpyw
Copy link

mpyw commented Jul 14, 2022

mpyw/laravel-database-advisory-lock: Advisory Locking Features for Postgres/MySQL on Laravel

It would be safer with this library. Why don't you adopt this?

<?php

namespace Jangaraev\EloquentModelAdvisoryLock;

use Illuminate\Support\Facades\DB;
use Illuminate\Database\ConnectionInterface;

trait AppliesAdvisoryLock
{
    /**
     * @phpstan-template T
     * @phpstan-param callable(ConnectionInterface): T
     * @phpstan-return T
     */
    public static function advisoryLocking(callable $callback, int $timeout = 0): mixed
    {
        return self::getConnection()->advisoryLocker()->forSession()->withLocking($key, $callback, $timeout);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant