yii-dream-team/yii2-lockable-activerecord

Pessimistic locking behavior for Yii2 ActiveRecord
89,580 18
Install
composer require yii-dream-team/yii2-lockable-activerecord
Latest Version:1.0.5
PHP:>=5.4.0
License:MIT
Last Updated:Aug 3, 2017
Links: GitHub  ·  Packagist
Maintainer: lagman

Pessimistic locking behavior for Yii2 ActiveRecord

This package allows you to use pessimistic locking (select for update) when you work with ActiveRecord models.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yii-dream-team/yii2-lockable-activerecord "*"

or add

"yii-dream-team/yii2-lockable-activerecord": "*"

to the require section of your composer.json.

Usage

Attach the behavior to your controller class.

public function behaviors()
{
    return [
        '\yiidreamteam\behaviors\LockableActiveRecord',
    ];
}

Add @mixin phpdoc to you class definition.

/**
 * Class Sample
 * @package common\models
 *
 * @mixin \yiidreamteam\behaviors\LockableActiveRecord
 */
class Sample extends ActiveRecord { ... }

Use model locks in transaction.

$dbTransaction = $model->getDb()->beginTransaction(\yii\db\Transaction::SERIALIZABLE);
try {
    $model->lock();
    $model->doSomethingWhileLocked();
    $dbTransaction->commit();
} catch(\Exception $e) {
    $dbTransaction->rollBack();
    throw $e;
}

Licence

MIT

Links

Related Packages

pesto/yii2-path-behavior

Automatic generation url path for the model while saving model/

14 0
latrell/lock

支持Redis与Memcached的并发锁。

22,889 32
gilak/nolock

get read of locking file in both laravel and the way laravel use league filesyst...

2,232 2
cyneek/yii2-routes

Routing and filtering extension system for Yii2 framework that emulates the Lara...

2,092 20
sleeping-owl/with-join

Package to convert Eloquent BelongsTo subqueries into one query with left join.

89,890 92