simple-ddl-parser
simple-ddl-parser copied to clipboard
ENUM and SET values for MySQL
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
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
@xnuinside I've managed to get all the other types working for omymodels.
This is the final blocker. Enums and sets with defaults crash.
cancellation_typeenum('enabled','disabled') NOT NULL DEFAULT 'enabled'
ddl_parser.py", line 289, in p_error
raise DDLParserError(f"Unknown statement at {p}")
simple_ddl_parser.ddl_parser.DDLParserError: Unknown statement at LexToken(NOT,'NOT',1,387)
Would appreciate your help here.
@rayliverified @hubg398 working on it, will add in 1.6.2 version
UPD: released in version 1.7.0 https://pypi.org/project/simple-ddl-parser/1.7.0/ tests also added - https://github.com/xnuinside/simple-ddl-parser/pull/287/files#diff-c5dbbef7e9cbb2c64b384079070c3006398036d834774db5983a1e347b7747f8 if will be needed anything else - feel free to open new issue