Package: simple-ddl-generator
Simple DDL GeneratorWhat is it?Simple DDL Generator generate SQL DDL from 3 different inputs. Idea of the generator same as for parser to support as much as possible DDLs in future.Simple DDL Generator generate SQL DDL from 3 input formats - 1st from output Simple DDL Parser (https://github.com/xnuinside/simple-ddl-parser), 2nd from py-models-parser -https://github.com/xnuinside/py-models-parser. Or you can directly pass TableMeta classes (https://github.com/xnuinside/table-meta) to generatorNow DDL support pure SQL DDL diclaect and bunch of HQL statements.Generate DDL from Django, SQLAlchemy, Dataclasses, Pydantic models and otherGenerator can generate DDL from all models that supported & parsed byhttps://github.com/xnuinside/py-models-parser.If you need DDL generation from another Python Model types - open issue request to add support for this models in parser.How to useAs usually - more samples in tests/pipinstallsimple-ddl-generatorGenerate / Modify using existed DDL with Simple-DDL-ParserSample how you can modify your DDL using Simple DDL Parser & Simple DDL Parserfromsimple_ddl_generatorimportDDLGeneratorfromsimple_ddl_parserimportDDLParser# take initial DDLddl="""CREATE EXTERNAL TABLE IF NOT EXISTS database.table_name
    (
        day_long_nm     string,
        calendar_dt     date,
        source_batch_id string,
        field_qty       decimal(10, 0),
        field_bool      boolean,
        field_float     float,
        create_tmst     timestamp,
        field_double    double,
        field_long      bigint
    ) PARTITIONED BY (batch_id int);"""# get result from parserdata=DDLParser(ddl).run(group_by_type=True,output_mode="bigquery")# rename, for example, table namedata["tables"][0]["table_name"]="new_table_name"g=DDLGenerator(data)g.generate()print(g.result)# and result will be:"""
CREATE EXTERNAL TABLE "database.new_table_name" (
day_long_nm string,
calendar_dt date,
source_batch_id string,
field_qty decimal(10, 0),
field_bool boolean,
field_float float,
create_tmst timestamp,
field_double double,
field_long bigint)
PARTITIONED BY (batch_id int);
"""Generate DDL from various Python Models with py-models-parserfromsimple_ddl_generatorimportDDLGeneratorfrompy_models_parserimportparse# you can also read them from filemodel_from="""
        class Material(BaseModel):

            id: int
            title: str
            description: Optional[str]
            link: str = 'http://'
            type: Optional[MaterialType]
            additional_properties: Optional[Json]
            created_at: Optional[datetime.datetime] = datetime.datetime.now()
            updated_at: Optional[datetime.datetime]
        """# get data with parserresult=parse(model_from)# if you want lower case table name before DDL generation you can just change in the result metadata, like this:# result[0].table_name = "material"# pass data to DDL Generatorg=DDLGenerator(result)g.generate()print(g.result)# resul will be"""CREATE TABLE "Material" (
id INTEGER,
title VARCHAR,
description VARCHAR,
link VARCHAR DEFAULT 'http://',
type MaterialType,
additional_properties JSON,
created_at DATETIME DEFAULT now(),
updated_at DATETIME);
"""Generate DDL Enum types from Python Enum & DDLsNow parser also generate CREATE TYPE statements.For example (sample for generation DDL from Dataclasses):fromsimple_ddl_generatorimportDDLGeneratorfrompy_models_parserimportparsemodel_from="""

    class MaterialType(str, Enum):

        article = 'article'
        video = 'video'


    @dataclass
    class Material:

        id: int
        description: str = None
        additional_properties: Union[dict, list, tuple, anything] = None
        created_at: datetime.datetime = datetime.datetime.now()
        updated_at: datetime.datetime = None

    @dataclass
    class Material2:

        id: int
        description: str = None
        additional_properties: Union[dict, list] = None
        created_at: datetime.datetime = datetime.datetime.now()
        updated_at: datetime.datetime = None

    """result=parse(model_from)g=DDLGenerator(result)g.generate()print(g.result)# result will be:"""CREATE TYPE MaterialType AS ENUM  ('article','video');

CREATE TABLE Material (
id INTEGER,
description VARCHAR DEFAULT NULL,
additional_properties JSON DEFAULT NULL,
created_at DATETIME DEFAULT now(),
updated_at DATETIME DEFAULT NULL);

CREATE TABLE Material2 (
id INTEGER,
description VARCHAR DEFAULT NULL,
additional_properties JSON DEFAULT NULL,
created_at DATETIME DEFAULT now(),
updated_at DATETIME DEFAULT NULL);
"""Changelogv0.4.1New Features:Added COMMENT statement to table generationImprovements:Added test to catch debug output (reminder: stop release at the middle night)Fixes:Fixed issue withv0.4.0New Features:Added base support for REFERENCE statement generationAdded UNIQUE to columnAdded PRIMARY KEY to columnTo DDLGenerator added param lowercase to lowercase tables name.v0.3.0New Features:Added CREATE TYPE generation from Python Enum & simple-ddl-parser types metadataImprovements:Added more test cases with models into testsNow output generated with empty line at the endFixes:Fixed issue with “” in names if quotes already exists in table-name in metadatav0.2.0Updated parser version in tests.Added support for EXTERNAL & IF NOT EXISTS statetements.Added support for using py-models-parser output as input and added sample in README.md:DDL Generation from Pydantic, SQLAlchemy and other python models.v0.1.0Base Generator Functionality with several test cases.