simple-ddl-parser icon indicating copy to clipboard operation
simple-ddl-parser copied to clipboard

ENUM and SET values for MySQL

Open hubg398 opened this issue 1 year ago • 1 comments

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 avatar May 23 '24 15:05 hubg398

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

hubg398 avatar May 31 '24 06:05 hubg398

@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_type enum('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 avatar Sep 28 '24 03:09 rayliverified

@rayliverified @hubg398 working on it, will add in 1.6.2 version

xnuinside avatar Sep 30 '24 04:09 xnuinside

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

xnuinside avatar Sep 30 '24 10:09 xnuinside