Skip to content

Commit

Permalink
up: update the sql to markdown gen, support language
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Oct 26, 2022
1 parent b10966f commit 7c4b74d
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion app/Lib/Parser/DBTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,27 @@ class DBTable
'comment' => '',
];

public const LANG_EN = 'en';
public const LANG_CN = 'zh-CN';

/**
* @var string
*/
protected string $source = '';

/**
* @var string
*/
protected string $lang = self::LANG_CN;

/**
* @var array<string, string>
*/
protected array $langTitles = [
'zh-CN' => ' 字段名 | 类型 | 是否为空 | 默认值 | 注释 ',
'en' => ' Field | Type | Allow Null | Default | Comments ',
];

/**
* @var string
*/
Expand Down Expand Up @@ -164,6 +183,11 @@ public function addIndexExpr(string $expr): self
return $this;
}

public function getLangTitle(): string
{
return $this->langTitles[$this->lang] ?? $this->langTitles[self::LANG_CN];
}

/**
* @return string
*/
Expand Down Expand Up @@ -232,7 +256,7 @@ public function toCreateSQL(): string
public function toMDTable(): string
{
$mdNodes = [
' 字段名 | 类型 | 是否为空 | 默认值 | 注释 ',
$this->getLangTitle(),
'-------|------|---------|--------|-----'
];

Expand Down Expand Up @@ -355,4 +379,28 @@ public function setTableComment(string $tableComment): void
{
$this->tableComment = $tableComment;
}

/**
* @param string $lang
*
* @return DBTable
*/
public function setLang(string $lang): self
{
if ($lang) {
$this->lang = $lang;
}
return $this;
}

/**
* @param array $langTitles
*
* @return DBTable
*/
public function setLangTitles(array $langTitles): self
{
$this->langTitles = array_merge($this->langTitles, $langTitles);
return $this;
}
}

0 comments on commit 7c4b74d

Please sign in to comment.