koxudaxi / datamodel-code-generator

Pydantic model and dataclasses.dataclass generator for easy conversion of JSON, OpenAPI, JSON Schema, and YAML data sources.
https://koxudaxi.github.io/datamodel-code-generator/
MIT License
2.79k stars 307 forks source link

SQL DDL as source input #419

Open xnuinside opened 3 years ago

xnuinside commented 3 years ago

Hi, @koxudaxi , first of all thank you for you library - it's awesome. Second, I saw you comment in this PR https://github.com/koxudaxi/datamodel-code-generator/issues/40, you said you expected use DDL of SQL also as source input.

Do you have any work in this way or ideas? I can help with feature. For DDL, for my projects, I started use sqlparse, but it was really sensitive to position of table name, for example, table_name( already was parsed as function & other issues.

I thought make sense create separate parser for DDL, that will aimed only on DDLs, but works well with any dialects. So I did it - https://github.com/xnuinside/simple-ddl-parser. Its generated simple output with information form DDL (a lot of samples in tests - https://github.com/xnuinside/simple-ddl-parser/tree/main/tests).

How you planned to add new features? As extensions with dependencies that they needed? What do you think?

koxudaxi commented 3 years ago

@xnuinside Thank you for posting a good idea. I expect the use-case for creating an ORM model from data. https://fastapi.tiangolo.com/tutorial/sql-databases/?h=orm#use-pydantics-orm_mode

If the feature needs a new dependency then I set an option datamodel-code-generator[sql-ddl] or more good option words. And, We should implement a new Parser like this JsonSchemaParser. https://github.com/koxudaxi/datamodel-code-generator/blob/d57b73895cf749118e93891e9bdf7070bede73fe/datamodel_code_generator/parser/jsonschema.py#L262

xnuinside commented 3 years ago

@koxudaxi, Thanks for your answer! I will take it in work and as soon as something will be ready to show it, I will open WIP PR for review.