xnuinside / simple-ddl-parser

Simple DDL Parser to parse SQL (HQL, TSQL, AWS Redshift, BigQuery, Snowflake and other dialects) ddl files to json/python dict with full information about columns: types, defaults, primary keys, etc. & table properties, types, domains, etc.
MIT License
175 stars 40 forks source link

ENUM and SET values for MySQL #259

Open hubg398 opened 2 months ago

hubg398 commented 2 months ago

This one is more a feature request, as I don't think the parser supports this yet.

This is for the ENUM column type when the values are specified inline.

Relevant doc for MySQL and example here: https://dev.mysql.com/doc/refman/8.0/en/enum.html

parse_results = DDLParser("""CREATE TABLE shirts (
    name VARCHAR(40),
    size ENUM('x-small', 'small', 'medium', 'large', 'x-large')
);
""", silent=False).run(output_mode='mysql')

print(parse_results)

Gives

DDLParserError: Unknown statement at LexToken(STRING_BASE,"'x-small'",1,58)

Thanks

hubg398 commented 2 months ago

Hey adding this here since it should be in the same part of the parser logic (eg same syntax) as the above, but for SETS

parse_results = DDLParser("""
CREATE TABLE myset (
      randomcolumn SET('a', 'b', 'c', 'd')
);
""", silent=False).run(output_mode='mysql')

Result

Unknown statement at LexToken(STRING_BASE,"'a'",1,32)

Docs: https://dev.mysql.com/doc/refman/8.0/en/set.html