MySQL DDL Create SQL convert to PlantUML Class diagram code.
Technical principle:
-
Use Lark parse MySQL DDL Create SQL to
dict
, then convertdict
to PlantUML class code. -
MySQL grammar Reference: MySQLParser
- clone this repo.
- install dependencies:
pip install -r requirements.txt
- Start server:
uvicorn main:app --reload
Example in example.py
:
from core import ddl_to_class
if __name__ == '__main__':
ddl_sql = """
create table user (
id INT PRIMARY key comment "user id"
nick_name text PRIMARY key not null comment "user nick"
) comment "user info"
"""
code = ddl_to_class(ddl_sql)
print(code)
output:
entity user {
id : INT
nick_name : text
}
use curl
send post request:
curl -X POST "http://127.0.0.1:8000/api/ddl_to_class/" \
-H "Content-Type: application/json" \
-d '{"ddl_sql": "CREATE TABLE example_table (id INT, name VARCHAR)"}'
response:
{
"code": 200,
"data": "entity example_table { \n id : INT \n name : VARCHAR \n}\n",
"message": "ok"
}
ddl2plantuml is completely free and open-source and licensed under the MIT license.