/ddl2plantuml

DDL Create SQL convert to PlantUML Class disgram code.

Primary LanguagePythonMIT LicenseMIT

ddl2plantuml

MySQL DDL Create SQL convert to PlantUML Class diagram code.

Technical principle:

  • Use Lark parse MySQL DDL Create SQL to dict, then convert dict to PlantUML class code.

  • MySQL grammar Reference: MySQLParser

Quickstart

  1. clone this repo.
  2. install dependencies:
    pip install -r requirements.txt
  3. Start server:
    uvicorn main:app --reload

Hello World

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 
}

HTTP Call

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"
}

Similar projects

Dependencies

License

ddl2plantuml is completely free and open-source and licensed under the MIT license.