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