改名
This commit is contained in:
+9
-2
@@ -43,7 +43,11 @@ class Connection extends Component
|
|||||||
|
|
||||||
public string $database = '';
|
public string $database = '';
|
||||||
|
|
||||||
public int $timeout = 1900;
|
public int $connect_timeout = 30;
|
||||||
|
|
||||||
|
public int $read_timeout = 10;
|
||||||
|
|
||||||
|
public array $pool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var bool
|
||||||
@@ -202,7 +206,10 @@ class Connection extends Component
|
|||||||
'username' => $this->username,
|
'username' => $this->username,
|
||||||
'password' => $this->password,
|
'password' => $this->password,
|
||||||
'attributes' => $this->attributes,
|
'attributes' => $this->attributes,
|
||||||
'dbname' => $this->database
|
'connect_timeout' => $this->connect_timeout,
|
||||||
|
'read_timeout' => $this->read_timeout,
|
||||||
|
'dbname' => $this->database,
|
||||||
|
'pool' => $this->pool
|
||||||
], true);
|
], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||||||
namespace Database;
|
namespace Database;
|
||||||
|
|
||||||
|
|
||||||
use Note\Inject;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri\Abstracts\Config;
|
use Kiri\Abstracts\Config;
|
||||||
use Kiri\Abstracts\Providers;
|
use Kiri\Abstracts\Providers;
|
||||||
@@ -12,6 +11,7 @@ use Kiri\Application;
|
|||||||
use Kiri\Events\EventProvider;
|
use Kiri\Events\EventProvider;
|
||||||
use Kiri\Exception\ConfigException;
|
use Kiri\Exception\ConfigException;
|
||||||
use Kiri\Kiri;
|
use Kiri\Kiri;
|
||||||
|
use Note\Inject;
|
||||||
use Server\Events\OnWorkerStart;
|
use Server\Events\OnWorkerStart;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,16 +83,18 @@ class DatabasesProviders extends Providers
|
|||||||
*/
|
*/
|
||||||
private function _settings($database): array
|
private function _settings($database): array
|
||||||
{
|
{
|
||||||
|
$clientPool = $database['pool'] ?? ['min' => 1, 'max' => 5, 'tick' => 60];
|
||||||
return [
|
return [
|
||||||
'class' => Connection::class,
|
|
||||||
'id' => $database['id'],
|
'id' => $database['id'],
|
||||||
'cds' => $database['cds'],
|
'cds' => $database['cds'],
|
||||||
'username' => $database['username'],
|
'username' => $database['username'],
|
||||||
'password' => $database['password'],
|
'password' => $database['password'],
|
||||||
'tablePrefix' => $database['tablePrefix'],
|
'tablePrefix' => $database['tablePrefix'],
|
||||||
'database' => $database['database'],
|
'database' => $database['database'],
|
||||||
'maxNumber' => $this->_pooLength['max'],
|
'connect_timeout' => $database['connect_timeout'] ?? 30,
|
||||||
'minNumber' => $this->_pooLength['min'],
|
'read_timeout' => $database['read_timeout'] ?? 10,
|
||||||
|
'pool' => $clientPool,
|
||||||
|
'attributes' => $database['attributes'] ?? [],
|
||||||
'charset' => $database['charset'] ?? 'utf8mb4',
|
'charset' => $database['charset'] ?? 'utf8mb4',
|
||||||
'slaveConfig' => $database['slaveConfig']
|
'slaveConfig' => $database['slaveConfig']
|
||||||
];
|
];
|
||||||
|
|||||||
+5
-1
@@ -34,6 +34,8 @@ class PDO implements StopHeartbeatCheck
|
|||||||
public string $username;
|
public string $username;
|
||||||
public string $password;
|
public string $password;
|
||||||
public string $charset;
|
public string $charset;
|
||||||
|
public int $connect_timeout;
|
||||||
|
public int $read_timeout;
|
||||||
|
|
||||||
|
|
||||||
public array $attributes = [];
|
public array $attributes = [];
|
||||||
@@ -48,6 +50,8 @@ class PDO implements StopHeartbeatCheck
|
|||||||
$this->cds = $config['cds'];
|
$this->cds = $config['cds'];
|
||||||
$this->username = $config['username'];
|
$this->username = $config['username'];
|
||||||
$this->password = $config['password'];
|
$this->password = $config['password'];
|
||||||
|
$this->connect_timeout = $config['connect_timeout'] ?? 30;
|
||||||
|
$this->read_timeout = $config['read_timeout'] ?? 10;
|
||||||
$this->charset = $config['charset'] ?? 'utf8mb4';
|
$this->charset = $config['charset'] ?? 'utf8mb4';
|
||||||
$this->attributes = $config['attributes'] ?? [];
|
$this->attributes = $config['attributes'] ?? [];
|
||||||
}
|
}
|
||||||
@@ -302,7 +306,7 @@ class PDO implements StopHeartbeatCheck
|
|||||||
$link = new \PDO('mysql:dbname=' . $this->dbname . ';host=' . $this->cds, $this->username, $this->password, [
|
$link = new \PDO('mysql:dbname=' . $this->dbname . ';host=' . $this->cds, $this->username, $this->password, [
|
||||||
\PDO::ATTR_EMULATE_PREPARES => false,
|
\PDO::ATTR_EMULATE_PREPARES => false,
|
||||||
\PDO::ATTR_CASE => \PDO::CASE_NATURAL,
|
\PDO::ATTR_CASE => \PDO::CASE_NATURAL,
|
||||||
\PDO::ATTR_TIMEOUT => 60,
|
\PDO::ATTR_TIMEOUT => $this->connect_timeout,
|
||||||
\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
|
\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
|
||||||
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->charset
|
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->charset
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user