Skip to content

Commit

Permalink
Merge pull request #1 from douyasi/dev
Browse files Browse the repository at this point in the history
release 1.1 version
  • Loading branch information
ycrao authored Apr 26, 2023
2 parents 387f6e2 + f856355 commit 567bbb2
Show file tree
Hide file tree
Showing 5 changed files with 293 additions and 123 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
.vscode
74 changes: 74 additions & 0 deletions README-en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# MySQL Database Dictionary Exporter

> MySQL database dictionary (document) is automatically exported by a PHP script. You need make comments for database's tables and their fields before export. Comments for database(s) is a good habit.
### CLI Version Usage

Requires [PDO](https://www.php.net/manual/en/ref.pdo-mysql.php) extension with [PHP](https://www.php.net/) runtime.

```bash
# download newest version from raw.githubusercontent.com
wget https://raw.githubusercontent.com/douyasi/db-dict/master/mysql_dict
# or download it from project `release` page
# current newest version 1.1
wget https://github.com/douyasi/db-dict/releases/download/1.1/mysql_dict
chmod +x mysql_dict
# an example
./mysql_dict -h=127.0.0.1 -u=root -p=root -d=test_app -c=utf8mb4 -l=zh-CN
```

Currently, supports the following options (parameters with * are required, and will use default values if not passed).

```
-h : MySQL server host name or ip, default `127.0.0.1`
-u : user for login, default `root`
-p : user password to use when connecting to server, default `root`
-d*: specify the name(s) of database(s)
separate multiple names with commas
-c : the charset for database(s), default `utf8mb4`
-l : locale language for markdown and html document
if locale not supported, will set it to default `en`
example:
./mysql_dict -h=127.0.0.1 -u=root -p=root -d=test_app -c=utf8mb4 -l=zh-CN
```

### Source Code Version Usage

Modify `$config` array values in `mysql_dict.php` file.

```php
$config = [
'host' => '127.0.0.1',
'user' => 'root',
'password' => 'root',
'charset' => 'utf8mb4',
'locale' => 'zh-CN', # locale language, now only support Simplified Chinese(zh-CN) and English(en)
];
```

Specify the name(s) of database(s) when handle export.

```php
# two databases: yascmf_app, test
$dbs = ['yascmf_app', 'test'];
foreach ($dbs as $db) {
export_dict($db, $config);
}
```

### File Formats

Supports two file formats `markdown` and `html`.

See screenshot for `HTML` below.

![dict.png](https://douyasi.com/usr/uploads/2017/06/1954673305.png)

### License

MIT LICENSE

### Special Thanks

![JetBrains Logo (Main) logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)
45 changes: 28 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
# MySQL 数据库数据字典生成脚本 (MySQL Database Dictionary Generator)
# MySQL 数据库数据字典导出器

> 本数据字典由PHP脚本自动导出,字典的备注来自数据库表及其字段的注释 `comment` 。开发者在增改库表及其字段时,请在 `migration` 时写明注释,以备后来者查阅。
[ENGLISH README](README-en.md)

> MySQL 数据库字典(文档)是由 `PHP` 脚本自动导出的。在导出之前,您需要为数据库的表及其字段添加上注释。为数据库(表列)添加注释是一个好习惯。
### 衍生相关

- [ddl-to-object](https://github.com/ycrao/ddl-to-object): 根据 DDL 语句生成各种语言支持的对象类。

### 命令行版本使用说明

依赖于 `PHP` 运行时,且需安装 `PDO` 扩展。
需要 [PHP](https://www.php.net/) 运行时和(安装) [PDO](https://www.php.net/manual/en/ref.pdo-mysql.php) 扩展。

```bash
# raw.githubusercontent.com 如果无法连接,可克隆本项目
# 如果 raw.githubusercontent.com 服务器无法连接连接上,可尝试科学上网并克隆本项目
wget https://raw.githubusercontent.com/douyasi/db-dict/master/mysql_dict
# 或者到项目 `release` 页面下载
# or
wget https://github.com/douyasi/db-dict/releases/download/1.0/mysql_dict
# 当前最新版 1.1
wget https://github.com/douyasi/db-dict/releases/download/1.1/mysql_dict
chmod +x mysql_dict
./mysql_dict -h=127.0.0.1 -u=root -p=root -d=test,yascmf_app -c=utf8mb4
# 示例
./mysql_dict -h=127.0.0.1 -u=root -p=root -d=test_app -c=utf8mb4
```

目前支持以下参数(带*为必传参数,未传递则使用默认值):
目前支持以下参数(带*为必传参数,如未传递则使用默认值):

```
-h 指定MySQL主机名,默认 `127.0.0.1`
-u 指定MySQL用户名,默认 `root`
-p 指定MySQL用户密码,默认 `root`
-d * 指定MySQL数据库名,多个库名请以英文逗号分隔
-c 指定MySQL数据库字符集,默认 `utf8mb4`
如:
./mysql_dict -h=127.0.0.1 -u=root -p=root -d=test,yascmf_app -c=utf8mb4
-h : MySQL服务主机名或 IP ,默认 `127.0.0.1`
-u : 登录的用户(名),默认 `root`
-p : 连接到服务器时使用的用户密码,默认 `root`
-d*: 指定要导出的数据库名称,多个名称之间用(英文)逗号分隔
-c : 数据库的字符集,默认 `utf8mb4`
-l : 导出文档的地区语言
如果不被支持,则设置成默认 `en`
示例:
./mysql_dict -h=127.0.0.1 -u=root -p=root -d=test_app -c=utf8mb4
```


### 源码版本使用说明

请自行修改 `mysql_dict.php` 文件中 `$config` 配置项:
Expand All @@ -43,19 +48,21 @@ $config = [
'user' => 'root',
'password' => 'root',
'charset' => 'utf8mb4', # 如果导出的文档出现乱码 ?,请指定该数据库对应的字符集
'locale' => 'zh-CN', # 文档语言,目前仅支持简体中文(zh-CN)与英文(en)
];
```

导出时,请指定需要生成字典的数据库名:

```php
# 使用你自己的数据库(名)
$dbs = ['yascmf_app', 'test'];
foreach ($dbs as $db) {
export_dict($db, $config);
}
```

### 导出格式
### 导出的文件格式

支持导出 `markdown``html` 两种格式文件,HTML页面预览图如下:

Expand All @@ -64,3 +71,7 @@ foreach ($dbs as $db) {
### 授权协议

MIT LICENSE

### 特别致谢

![JetBrains Logo (Main) logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)
Loading

0 comments on commit 567bbb2

Please sign in to comment.