变更
This commit is contained in:
@@ -99,7 +99,11 @@ class Connection extends Component
|
|||||||
if (!$this->pool->hasChannel($config['cds'])) {
|
if (!$this->pool->hasChannel($config['cds'])) {
|
||||||
$this->pool->initConnections($config['cds'], $config['pool']['max']);
|
$this->pool->initConnections($config['cds'], $config['pool']['max']);
|
||||||
}
|
}
|
||||||
return $this->pool->get($config['cds'], $this->generate($config));
|
|
||||||
|
if (!$this->pool->hasItem($config['cds'])) {
|
||||||
|
return $this->generate($config);
|
||||||
|
}
|
||||||
|
return $this->pool->get($config['cds']);
|
||||||
if (!Context::hasContext($config['cds'])) {
|
if (!Context::hasContext($config['cds'])) {
|
||||||
return Context::setContext($config['cds'], );
|
return Context::setContext($config['cds'], );
|
||||||
} else {
|
} else {
|
||||||
@@ -112,9 +116,8 @@ class Connection extends Component
|
|||||||
* @param array $config
|
* @param array $config
|
||||||
* @return Closure
|
* @return Closure
|
||||||
*/
|
*/
|
||||||
public function generate(array $config): Closure
|
public function generate(array $config): \PDO
|
||||||
{
|
{
|
||||||
return static function () use ($config) {
|
|
||||||
Kiri::getDi()->get(Kiri\Error\StdoutLoggerInterface::class)->alert('create database connect(' . $config['cds'] . ')');
|
Kiri::getDi()->get(Kiri\Error\StdoutLoggerInterface::class)->alert('create database connect(' . $config['cds'] . ')');
|
||||||
|
|
||||||
$link = new \PDO('mysql:dbname=' . $config['dbname'] . ';host=' . $config['cds'], $config['username'], $config['password'], [
|
$link = new \PDO('mysql:dbname=' . $config['dbname'] . ';host=' . $config['cds'], $config['username'], $config['password'], [
|
||||||
@@ -134,7 +137,6 @@ class Connection extends Component
|
|||||||
$link->beginTransaction();
|
$link->beginTransaction();
|
||||||
}
|
}
|
||||||
return $link;
|
return $link;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -155,13 +155,9 @@ class Pool extends Component
|
|||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function get($name, $callback): mixed
|
public function get($name): mixed
|
||||||
{
|
{
|
||||||
$channel = $this->channel($name);
|
return $this->channel($name)->pop();
|
||||||
if ($channel->isEmpty()) {
|
|
||||||
$channel->push($callback());
|
|
||||||
}
|
|
||||||
return $channel->pop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user