改名
This commit is contained in:
@@ -766,7 +766,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, \ArrayAccess
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* @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
|
||||
* enable database cache
|
||||
@@ -63,10 +51,9 @@ class Connection extends Component
|
||||
* @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'],
|
||||
* 'cds' => 'mysql:dbname=dbname;host=127.0.0.1',
|
||||
* 'username' => 'root',
|
||||
* 'password' => 'root'
|
||||
* ]
|
||||
*/
|
||||
public $slaveConfig = [];
|
||||
@@ -186,28 +173,6 @@ class Connection extends Component
|
||||
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
|
||||
* @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\Snowflake;
|
||||
use Snowflake\Event;
|
||||
use Database\Connection as DbConnection;
|
||||
use Snowflake\Pool\Pool as SPool;
|
||||
use Database\DatabasesProviders;
|
||||
|
||||
/**
|
||||
* Class BaseApplication
|
||||
@@ -40,7 +40,7 @@ use Snowflake\Pool\Pool as SPool;
|
||||
* @property Processes $processes
|
||||
* @property SPool $pool
|
||||
* @property Server $servers
|
||||
* @property DbConnection $db
|
||||
* @property DatabasesProviders $db
|
||||
* @property Connection $connections
|
||||
* @property Logger $logger
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user