Kaynağa Gözat

新增获取字段方法

zjh 4 ay önce
ebeveyn
işleme
7e475cf0f4
1 değiştirilmiş dosya ile 19 ekleme ve 8 silme
  1. 19 8
      src/Driver/Entity/Entity.php

+ 19 - 8
src/Driver/Entity/Entity.php

@@ -38,6 +38,24 @@ class Entity {
         $this->namespace = $namespace;
     }
 
+    /**
+     * 返回表的字段
+     *
+     * @param string $table
+     * @return mixed
+     * @throws \Exception
+     */
+    public function getTableInfo($table){
+        $db = $this->db();
+        if($db->isError()) {
+            throw new \Exception($db->getError());
+        }
+        $tableInfo = $db->getTableInfo($table);
+        if(!$tableInfo || empty($tableInfo['fields'])) {
+            throw new \Exception($table . ' does not have any field');
+        }
+        return $tableInfo;
+    }
     /**
      * 通过 Entity 获取数据表的字段
      *
@@ -71,14 +89,7 @@ class Entity {
      * @throws \Exception
      */
     public function generateProperties($table, $className = '') {
-        $db = $this->db();
-        $tableInfo = $db->getTableInfo($table);
-        if($db->isError()) {
-            throw new \Exception($db->getError());
-        }
-        if(!$tableInfo || empty($tableInfo['fields'])) {
-            throw new \Exception($table . ' does not have any field');
-        }
+        $tableInfo = $this->getTableInfo($table);
         $properties = [];
         $docs = [];
         $defaults = [];