2017 © Pedro Peláez
 

yii-extension yii2lockable-query

MySQL InnoDB lock support(select for update) for ActiveRecord

image

amoydavid/yii2lockable-query

MySQL InnoDB lock support(select for update) for ActiveRecord

  • Saturday, January 20, 2018
  • by amoydavid
  • Repository
  • 1 Watchers
  • 1 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 40 % Grown

The README.md

Yii2 Lockable ActiveQuery

This package allows you to use pessimistic locking (select for update) when you work with ActiveRecord Query., (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist amoydavid/yii2lockable-query "*"

or add, (*4)

"amoydavid/yii2lockable-query": "*"

to the require section of your composer.json., (*5)

Usage

Set schema map for database connection, (*6)

<?php
return [
    'class' => 'yii\db\Connection',
    'schemaMap' => [
        'mysql' => '\amoydavid\Yii2LockableQuery\mysql\Schema', // set up mysql schema
        'mssql' => '\amoydavid\Yii2LockableQuery\mssql\Schema', // set up mssql schema
    ],
    'dsn' => 'mysql:host=localhost;dbname=yii',
    'username' => 'root',
    'password' => '',
    'charset' => 'utf8',

    // Schema cache options (for production environment)
    //'enableSchemaCache' => true,
    //'schemaCacheDuration' => 60,
    //'schemaCache' => 'cache',
]; 

Extend your ActiveRecord class via \amoydavid\Yii2LockableQuery\ActiveRecord, (*7)

/**
 * Class Sample
 * @package common\models
 *
 */
class Sample extends \amoydavid\Yii2LockableQuery\ActiveRecord { ... }

Use model locks in transaction., (*8)

$dbTransaction = $model->getDb()->beginTransaction();
try {
    $model = Sample::find()->where(['id'=>1])->forUpdate()->one();
    $dbTransaction->commit();
} catch(\Exception $e) {
    $dbTransaction->rollBack();
    throw $e;
}

Licence

MIT, (*9)

The Versions

20/01 2018

dev-master

9999999-dev

MySQL InnoDB lock support(select for update) for ActiveRecord

  Sources   Download

MIT

The Requires

 

by Wei Liu

06/01 2018

1.0.0

1.0.0.0

MySQL InnoDB lock support for ActiveRecord

  Sources   Download

MIT

The Requires

 

by Wei Liu