This commit is contained in:
2020-09-03 11:39:20 +08:00
parent 274332207b
commit efbb049824
42 changed files with 101 additions and 101 deletions
+2 -2
View File
@@ -123,7 +123,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, \ArrayAccess
*/
public function getLastError()
{
return Snowflake::get()->getLogger()->getLastError('mysql');
return Snowflake::app()->getLogger()->getLastError('mysql');
}
/**
@@ -768,7 +768,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, \ArrayAccess
*/
public static function setDatabaseConnect($bsName)
{
return Snowflake::get()->db->get($bsName);
return Snowflake::app()->db->get($bsName);
}
/**
+14 -14
View File
@@ -67,7 +67,7 @@ class Connection extends Component
*/
public function init()
{
$event = Snowflake::get()->event;
$event = Snowflake::app()->event;
$event->on(Event::RELEASE_ALL, [$this, 'disconnect']);
$event->on(Event::EVENT_AFTER_REQUEST, [$this, 'clear_connection']);
}
@@ -83,7 +83,7 @@ class Connection extends Component
}
$this->beginTransaction();
$event = Snowflake::get()->event;
$event = Snowflake::app()->event;
$event->on(Connection::TRANSACTION_COMMIT, [$this, 'commit'], false, true);
$event->on(Connection::TRANSACTION_ROLLBACK, [$this, 'rollback'], false, true);
}
@@ -95,7 +95,7 @@ class Connection extends Component
*/
public function getConnect($sql = NULL)
{
$connections = Snowflake::get()->connections;
$connections = Snowflake::app()->connections;
$connections->initConnections($this->cds, true, $this->maxNumber);
$connections->initConnections($this->slaveConfig['cds'], false, $this->maxNumber);
$connections->setTimeout($this->timeout);
@@ -155,7 +155,7 @@ class Connection extends Component
if (!$this->enableCache) {
return null;
}
return Snowflake::get()->get($this->cacheDriver);
return Snowflake::app()->get($this->cacheDriver);
}
/**
@@ -169,7 +169,7 @@ class Connection extends Component
'username' => $this->username,
'password' => $this->password
];
$pool = Snowflake::get()->connections;
$pool = Snowflake::app()->connections;
return $pool->getConnection($config, true);
}
@@ -183,7 +183,7 @@ class Connection extends Component
return $this->masterInstance();
}
$connections = Snowflake::get()->connections;
$connections = Snowflake::app()->connections;
return $connections->getConnection($this->slaveConfig, false);
}
@@ -194,7 +194,7 @@ class Connection extends Component
*/
public function beginTransaction()
{
$connections = Snowflake::get()->connections;
$connections = Snowflake::app()->connections;
$connections->beginTransaction($this->cds);
return $this;
}
@@ -205,7 +205,7 @@ class Connection extends Component
*/
public function inTransaction()
{
$connections = Snowflake::get()->connections;
$connections = Snowflake::app()->connections;
return $connections->inTransaction($this->cds);
}
@@ -215,7 +215,7 @@ class Connection extends Component
*/
public function rollback()
{
$connections = Snowflake::get()->connections;
$connections = Snowflake::app()->connections;
return $connections->rollback($this->cds);
}
@@ -225,7 +225,7 @@ class Connection extends Component
*/
public function commit()
{
$connections = Snowflake::get()->connections;
$connections = Snowflake::app()->connections;
return $connections->commit($this->cds);
}
@@ -275,7 +275,7 @@ class Connection extends Component
*/
public function release()
{
$connections = Snowflake::get()->connections;
$connections = Snowflake::app()->connections;
$connections->release($this->cds, true);
$connections->release($this->slaveConfig['cds'], false);
@@ -287,7 +287,7 @@ class Connection extends Component
*/
public function recovery()
{
$connections = Snowflake::get()->connections;
$connections = Snowflake::app()->connections;
$connections->release($this->cds, true);
$connections->release($this->slaveConfig['cds'], false);
@@ -300,7 +300,7 @@ class Connection extends Component
*/
public function clear_connection()
{
$connections = Snowflake::get()->connections;
$connections = Snowflake::app()->connections;
$connections->release($this->cds, true);
$connections->release($this->slaveConfig['cds'], false);
@@ -312,7 +312,7 @@ class Connection extends Component
*/
public function disconnect()
{
$connections = Snowflake::get()->connections;
$connections = Snowflake::app()->connections;
$connections->disconnect($this->cds);
$connections->disconnect($this->slaveConfig['cds']);
}
+1 -1
View File
@@ -38,7 +38,7 @@ class DatabasesProviders extends Providers
*/
public function get($name)
{
$application = Snowflake::get();
$application = Snowflake::app();
if ($application->has('databases.' . $name)) {
return $application->get('databases.' . $name);
}
+12 -12
View File
@@ -46,7 +46,7 @@ class Db
*/
public static function commit()
{
$event = Snowflake::get()->event;
$event = Snowflake::app()->event;
$event->trigger(Connection::TRANSACTION_COMMIT);
$event->offName(Connection::TRANSACTION_COMMIT);
static::$isActive = false;
@@ -57,7 +57,7 @@ class Db
*/
public static function rollback()
{
$event = Snowflake::get()->event;
$event = Snowflake::app()->event;
$event->trigger(Connection::TRANSACTION_ROLLBACK);
$event->offName(Connection::TRANSACTION_ROLLBACK);
static::$isActive = false;
@@ -96,7 +96,7 @@ class Db
public function get(Connection $db = NULL)
{
if (empty($db)) {
$db = Snowflake::get()->database;
$db = Snowflake::app()->database;
}
$query = $db->getSchema()->getQueryBuilder();
return $db->createCommand($query->getQuery($this))
@@ -120,7 +120,7 @@ class Db
public function find(Connection $db = NULL)
{
if (empty($db)) {
$db = Snowflake::get()->database;
$db = Snowflake::app()->database;
}
$query = $db->getSchema()->getQueryBuilder();
return $db->createCommand($query->getQuery($this))
@@ -135,7 +135,7 @@ class Db
public function count(Connection $db = NULL)
{
if (empty($db)) {
$db = Snowflake::get()->database;
$db = Snowflake::app()->database;
}
$query = $db->getSchema()->getQueryBuilder();
return $db->createCommand($query->count($this))
@@ -150,7 +150,7 @@ class Db
public function exists(Connection $db = NULL)
{
if (empty($db)) {
$db = Snowflake::get()->database;
$db = Snowflake::app()->database;
}
$query = $db->getSchema()->getQueryBuilder();
return $db->createCommand($query->getQuery($this))
@@ -221,7 +221,7 @@ class Db
public function delete($db = null)
{
if (empty($db)) {
$db = Snowflake::get()->database;
$db = Snowflake::app()->database;
}
$query = $db->getBuild()->builder($this);
@@ -238,7 +238,7 @@ class Db
public static function drop($table, $db = null)
{
if (empty($db)) {
$db = Snowflake::get()->database;
$db = Snowflake::app()->database;
}
return $db->createCommand('DROP TABLE ' . $table)->delete();
}
@@ -253,7 +253,7 @@ class Db
{
if (empty($db)) {
$db = Snowflake::get()->database;
$db = Snowflake::app()->database;
}
return $db->createCommand('TRUNCATE ' . $table)->exec();
@@ -269,7 +269,7 @@ class Db
{
if (empty($db)) {
$db = Snowflake::get()->database;
$db = Snowflake::app()->database;
}
@@ -289,7 +289,7 @@ class Db
public static function desc($table, Connection $db = NULL)
{
if (empty($db)) {
$db = Snowflake::get()->database;
$db = Snowflake::app()->database;
}
if (empty($table)) {
@@ -313,7 +313,7 @@ class Db
}
if (empty($db)) {
$db = Snowflake::get()->database;
$db = Snowflake::app()->database;
}
$table = [' const TABLE = \'select * from %s where REFERENCED_TABLE_NAME=%s\';'];