This commit is contained in:
2021-03-08 14:43:52 +08:00
parent 8add053094
commit c45665c1fd
3 changed files with 33 additions and 10 deletions
+1 -8
View File
@@ -12,8 +12,6 @@ namespace Database\Base;
use Annotation\Event; use Annotation\Event;
use Annotation\Inject; use Annotation\Inject;
use Annotation\Model\Get;
use Annotation\Model\Set;
use ArrayAccess; use ArrayAccess;
use Database\SqlBuilder; use Database\SqlBuilder;
use Database\Traits\HasBase; use Database\Traits\HasBase;
@@ -75,8 +73,6 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
private array $_annotations = []; private array $_annotations = [];
private array $_fields = [];
/** /**
* @var bool * @var bool
*/ */
@@ -756,10 +752,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
*/ */
public function has($attribute): bool public function has($attribute): bool
{ {
if (empty($this->_fields)) { return static::getColumns()->hasField($attribute);
$this->_fields = static::getColumns()->format();
}
return isset($this->_fields[$attribute]);
} }
/**ƒ /**ƒ
+31 -1
View File
@@ -55,6 +55,9 @@ class Columns extends Component
*/ */
private array $_auto_increment = []; private array $_auto_increment = [];
private array $_fields = [];
/** /**
* @param string $table * @param string $table
* @return $this * @return $this
@@ -206,6 +209,31 @@ class Columns extends Component
return $this->columns('Default', 'Field'); return $this->columns('Default', 'Field');
} }
/**
* @return mixed
* @throws Exception
*/
public function getFields(): array
{
if (empty($this->_fields)) {
$this->structure($this->table);
}
return $this->_fields[$this->table];
}
/**
* @param $name
* @return bool
* @throws Exception
*/
public function hasField(string $name): bool
{
return isset($this->getFields()[$name]);
}
/** /**
* @return int|string|null * @return int|string|null
* @throws Exception * @throws Exception
@@ -282,7 +310,6 @@ class Columns extends Component
throw new Exception("The table " . $table . " not exists."); throw new Exception("The table " . $table . " not exists.");
} }
return $this->columns[$table] = $this->resolve($column, $table); return $this->columns[$table] = $this->resolve($column, $table);
} }
return $this->columns[$table]; return $this->columns[$table];
} }
@@ -299,6 +326,9 @@ class Columns extends Component
$this->addPrimary($item, $table); $this->addPrimary($item, $table);
$column[$key]['Type'] = $this->clean($item['Type']); $column[$key]['Type'] = $this->clean($item['Type']);
} }
$this->_fields[$table] = array_column($column, 'Default', 'Field');
return $column; return $column;
} }
+1 -1
View File
@@ -36,7 +36,7 @@ class OnReceive extends Callback
* @return mixed * @return mixed
* @throws Exception * @throws Exception
*/ */
public function onHandler(\Swoole\Server $server, int $fd, int $reID, string $data): mixed public function onHandler(Server $server, int $fd, int $reID, string $data): mixed
{ {
try { try {
$client = $server->getClientInfo($fd, $reID); $client = $server->getClientInfo($fd, $reID);