This commit is contained in:
2021-01-19 18:58:09 +08:00
parent 602bf0cf76
commit 58c3705910
2 changed files with 35 additions and 1 deletions
+25 -1
View File
@@ -14,6 +14,7 @@ use Database\Db;
use Exception;
use JetBrains\PhpStorm\ArrayShape;
use Snowflake\Abstracts\Config;
use Snowflake\Abstracts\Input;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\ConfigException;
@@ -110,10 +111,33 @@ class Gii
*/
private function getModel($make, $input): array
{
if (!$this->db) {
if ($this->db) {
return $this->makeByDatabases($make, $input);
}
if ($this->input->exists('databases')) {
$db = $this->input->get('databases', 'db');
$this->db = Snowflake::app()->db->get($db);
return $this->makeByDatabases($make, $input);
}
$array = [];
foreach (Config::get('databases') as $key => $connection) {
$this->db = Snowflake::app()->db->get($key);
$array[$key] = $this->makeByDatabases($make, $input);
}
return $array;
}
/**
* @param $make
* @param $input
* @return array
* @throws ComponentException
*/
private function makeByDatabases($make, $input): array
{
$redis = Snowflake::app()->getRedis();
if (!empty($input->get('table'))) {
$this->tableName = $input->get('table');
+10
View File
@@ -45,6 +45,16 @@ class Input
return $this->_argv[$key] ?? $default;
}
/**
* @param $key
* @return bool
*/
public function exists($key): bool
{
return isset($this->_argv[$key]);
}
/**
* @param $key
* @param $value