modify plugin name
This commit is contained in:
@@ -90,10 +90,25 @@ class Connection extends Component
|
|||||||
public function get(mixed $config, bool $isMaster = false): ?PDO
|
public function get(mixed $config, bool $isMaster = false): ?PDO
|
||||||
{
|
{
|
||||||
$coroutineName = $this->name('Mysql:' . $config['cds'], $isMaster);
|
$coroutineName = $this->name('Mysql:' . $config['cds'], $isMaster);
|
||||||
|
if ($isMaster == false) {
|
||||||
|
return $this->_get($config, $coroutineName);
|
||||||
|
}
|
||||||
if (($pdo = Context::getContext($coroutineName)) instanceof PDO) {
|
if (($pdo = Context::getContext($coroutineName)) instanceof PDO) {
|
||||||
|
$pdo = Context::setContext($coroutineName, $this->_get($config, $coroutineName));
|
||||||
|
}
|
||||||
return $pdo;
|
return $pdo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $config
|
||||||
|
* @param string $coroutineName
|
||||||
|
* @return PDO
|
||||||
|
* @throws Kiri\Exception\ConfigException
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private function _get(mixed $config, string $coroutineName): PDO
|
||||||
|
{
|
||||||
$minx = Config::get('databases.pool.min', 1);
|
$minx = Config::get('databases.pool.min', 1);
|
||||||
|
|
||||||
/** @var PDO $connections */
|
/** @var PDO $connections */
|
||||||
@@ -101,7 +116,7 @@ class Connection extends Component
|
|||||||
if (Context::hasContext('begin_' . $coroutineName)) {
|
if (Context::hasContext('begin_' . $coroutineName)) {
|
||||||
$connections->beginTransaction();
|
$connections->beginTransaction();
|
||||||
}
|
}
|
||||||
return Context::setContext($coroutineName, $connections);
|
return $connections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -147,25 +162,38 @@ class Connection extends Component
|
|||||||
/**
|
/**
|
||||||
* @param $coroutineName
|
* @param $coroutineName
|
||||||
* @param $isMaster
|
* @param $isMaster
|
||||||
* @param array $config
|
|
||||||
* @throws Kiri\Exception\ConfigException
|
* @throws Kiri\Exception\ConfigException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function release($coroutineName, $isMaster, array $config)
|
public function release($coroutineName, $isMaster)
|
||||||
{
|
{
|
||||||
$coroutineName = $this->name('Mysql:' . $coroutineName, $isMaster);
|
$coroutineName = $this->name('Mysql:' . $coroutineName, $isMaster);
|
||||||
/** @var PDO $client */
|
|
||||||
if (!($client = Context::getContext($coroutineName)) instanceof PDO) {
|
$client = Context::getContext($coroutineName);
|
||||||
$client = call_user_func($this->create($coroutineName, $config));
|
if (!($client instanceof PDO) || $client->inTransaction()) {
|
||||||
}
|
|
||||||
if ($client->inTransaction()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->getPool()->push($coroutineName, $client);
|
$this->getPool()->push($coroutineName, $client);
|
||||||
Context::remove($coroutineName);
|
Context::remove($coroutineName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $coroutineName
|
||||||
|
* @param PDO $PDO
|
||||||
|
* @param bool $isMaster
|
||||||
|
* @return void
|
||||||
|
* @throws Exception
|
||||||
|
* @throws Kiri\Exception\ConfigException
|
||||||
|
*/
|
||||||
|
public function recover($coroutineName, PDO $PDO, bool $isMaster = false)
|
||||||
|
{
|
||||||
|
$coroutineName = $this->name('Mysql:' . $coroutineName, $isMaster);
|
||||||
|
$this->getPool()->push($coroutineName, $PDO);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $coroutineName
|
* @param $coroutineName
|
||||||
* @return bool
|
* @return bool
|
||||||
|
|||||||
Reference in New Issue
Block a user