Skip to content

Commit c94d7f3

Browse files
authored
Merge pull request #25 from sunsgneayo/main
创建model:新增获取表注释信息
2 parents f8070b2 + 9cb8a09 commit c94d7f3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Commands/MakeModelCommand.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ protected function createModel($class, $namespace, $file)
109109
$table_val = "'$table'";
110110
$table = "{$prefix}{$table}";
111111
}
112+
$tableComment = \support\Db::select('SELECT table_comment FROM information_schema.`TABLES` WHERE table_schema = ? AND table_name = ?', [$database, $table]);
113+
if (!empty($tableComment)) {
114+
$comments = $tableComment[0]->table_comment ?? $tableComment[0]->TABLE_COMMENT;
115+
$properties .= " * {$table} {$comments}" . PHP_EOL;
116+
}
112117
foreach (\support\Db::select("select COLUMN_NAME,DATA_TYPE,COLUMN_KEY,COLUMN_COMMENT from INFORMATION_SCHEMA.COLUMNS where table_name = '$table' and table_schema = '$database'") as $item) {
113118
if ($item->COLUMN_KEY === 'PRI') {
114119
$pk = $item->COLUMN_NAME;
@@ -186,6 +191,11 @@ protected function createTpModel($class, $namespace, $file)
186191
$table = "{$prefix}{$table}s";
187192
$table_val = "'$table'";
188193
}
194+
$tableComment = \support\Db::select('SELECT table_comment FROM information_schema.`TABLES` WHERE table_schema = ? AND table_name = ?', [$database, $table]);
195+
if (!empty($tableComment)) {
196+
$comments = $tableComment[0]->table_comment ?? $tableComment[0]->TABLE_COMMENT;
197+
$properties .= " * {$table} {$comments}" . PHP_EOL;
198+
}
189199
foreach (\think\facade\Db::query("select COLUMN_NAME,DATA_TYPE,COLUMN_KEY,COLUMN_COMMENT from INFORMATION_SCHEMA.COLUMNS where table_name = '$table' and table_schema = '$database'") as $item) {
190200
if ($item['COLUMN_KEY'] === 'PRI') {
191201
$pk = $item['COLUMN_NAME'];

0 commit comments

Comments
 (0)