datamodel-code-generator icon indicating copy to clipboard operation
datamodel-code-generator copied to clipboard

SQL DDL as source input

Open xnuinside opened this issue 4 years ago • 2 comments
trafficstars

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?

xnuinside avatar Apr 28 '21 09:04 xnuinside

@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

koxudaxi avatar Apr 28 '21 14:04 koxudaxi

@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.

xnuinside avatar Apr 28 '21 15:04 xnuinside