改名
This commit is contained in:
@@ -766,7 +766,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, \ArrayAccess
|
|||||||
*/
|
*/
|
||||||
public static function setDatabaseConnect($bsName)
|
public static function setDatabaseConnect($bsName)
|
||||||
{
|
{
|
||||||
return Snowflake::get()->db->instance($bsName);
|
return Snowflake::get()->db->get($bsName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+3
-38
@@ -40,18 +40,6 @@ class Connection extends Component
|
|||||||
|
|
||||||
public $maxNumber = 100;
|
public $maxNumber = 100;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*
|
|
||||||
* @example [
|
|
||||||
* ['cds' => 'mysql:dbname=dbname;host=127.0.0.1', 'username' => 'root', 'password' => 'root'],
|
|
||||||
* ['cds' => 'mysql:dbname=dbname;host=127.0.0.1', 'username' => 'root', 'password' => 'root'],
|
|
||||||
* ['cds' => 'mysql:dbname=dbname;host=127.0.0.1', 'username' => 'root', 'password' => 'root'],
|
|
||||||
* ['cds' => 'mysql:dbname=dbname;host=127.0.0.1', 'username' => 'root', 'password' => 'root'],
|
|
||||||
* ]
|
|
||||||
*/
|
|
||||||
public $masterConfig = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var bool
|
||||||
* enable database cache
|
* enable database cache
|
||||||
@@ -63,10 +51,9 @@ class Connection extends Component
|
|||||||
* @var array
|
* @var array
|
||||||
*
|
*
|
||||||
* @example [
|
* @example [
|
||||||
* ['cds' => 'mysql:dbname=dbname;host=127.0.0.1', 'username' => 'root', 'password' => 'root'],
|
* 'cds' => 'mysql:dbname=dbname;host=127.0.0.1',
|
||||||
* ['cds' => 'mysql:dbname=dbname;host=127.0.0.1', 'username' => 'root', 'password' => 'root'],
|
* 'username' => 'root',
|
||||||
* ['cds' => 'mysql:dbname=dbname;host=127.0.0.1', 'username' => 'root', 'password' => 'root'],
|
* 'password' => 'root'
|
||||||
* ['cds' => 'mysql:dbname=dbname;host=127.0.0.1', 'username' => 'root', 'password' => 'root'],
|
|
||||||
* ]
|
* ]
|
||||||
*/
|
*/
|
||||||
public $slaveConfig = [];
|
public $slaveConfig = [];
|
||||||
@@ -186,28 +173,6 @@ class Connection extends Component
|
|||||||
return $pool->getConnection($config, true);
|
return $pool->getConnection($config, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $name
|
|
||||||
* @return Connection
|
|
||||||
* @throws ConfigException
|
|
||||||
*/
|
|
||||||
public function instance($name)
|
|
||||||
{
|
|
||||||
$config = Config::get('databases.' . $name, true);
|
|
||||||
|
|
||||||
$this->cds = $config['cds'];
|
|
||||||
$this->username = $config['username'];
|
|
||||||
$this->password = $config['password'];
|
|
||||||
|
|
||||||
$this->tablePrefix = $config['tablePrefix'];
|
|
||||||
|
|
||||||
$this->slaveConfig = $config['slaveConfig'];
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return PDO
|
* @return PDO
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Database;
|
||||||
|
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Snowflake\Abstracts\Component;
|
||||||
|
use Snowflake\Config;
|
||||||
|
use Snowflake\Exception\ConfigException;
|
||||||
|
use Snowflake\Snowflake;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DatabasesProviders
|
||||||
|
* @package Database
|
||||||
|
*/
|
||||||
|
class DatabasesProviders extends Component
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $name
|
||||||
|
* @return DatabasesProviders
|
||||||
|
* @throws ConfigException
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function get($name)
|
||||||
|
{
|
||||||
|
$config = Config::get('databases.' . $name, true);
|
||||||
|
if (Snowflake::get()->has($name)) {
|
||||||
|
return Snowflake::get()->get($name);
|
||||||
|
}
|
||||||
|
return Snowflake::get()->set($name, [
|
||||||
|
'class' => Connection::class,
|
||||||
|
'id' => 'db',
|
||||||
|
'cds' => $config['cds'],
|
||||||
|
'username' => $config['username'],
|
||||||
|
'password' => $config['password'],
|
||||||
|
'tablePrefix' => $config['tablePrefix'],
|
||||||
|
'maxNumber' => 100,
|
||||||
|
'slaveConfig' => $config['slaveConfig']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -27,8 +27,8 @@ use Snowflake\Pool\RedisClient;
|
|||||||
use Snowflake\Processes;
|
use Snowflake\Processes;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
use Snowflake\Event;
|
use Snowflake\Event;
|
||||||
use Database\Connection as DbConnection;
|
|
||||||
use Snowflake\Pool\Pool as SPool;
|
use Snowflake\Pool\Pool as SPool;
|
||||||
|
use Database\DatabasesProviders;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BaseApplication
|
* Class BaseApplication
|
||||||
@@ -40,7 +40,7 @@ use Snowflake\Pool\Pool as SPool;
|
|||||||
* @property Processes $processes
|
* @property Processes $processes
|
||||||
* @property SPool $pool
|
* @property SPool $pool
|
||||||
* @property Server $servers
|
* @property Server $servers
|
||||||
* @property DbConnection $db
|
* @property DatabasesProviders $db
|
||||||
* @property Connection $connections
|
* @property Connection $connections
|
||||||
* @property Logger $logger
|
* @property Logger $logger
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user