Skip to content

Commit

Permalink
Merge branch 'main' into some-refactorings-1
Browse files Browse the repository at this point in the history
  • Loading branch information
xnuinside authored Aug 1, 2024
2 parents 1fae5ba + cb4e1b5 commit 2bc0075
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
8 changes: 8 additions & 0 deletions simple_ddl_parser/ddl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ def exceptional_cases(self, value: str) -> bool:
return True
return False

def t_COLLATE(self, t: LexToken):
r"(?i:COLLATE|COLLATE)\b"
if not self.lexer.after_columns:
t.type = "COLLATE"
else:
t.type = "ID"
return self.set_last_token(t)

def t_AUTOINCREMENT(self, t: LexToken):
r"(?i:AUTO_INCREMENT|AUTOINCREMENT)\b"
if not self.lexer.after_columns:
Expand Down
2 changes: 1 addition & 1 deletion simple_ddl_parser/output/dialects.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class SparkSQL(Dialect):

@dataclass
@dialect(name="mysql")
class MySSQL(Dialect):
class MySQL(Dialect):
engine: Optional[str] = field(
default=None, metadata={"exclude_if_not_provided": True}
)
Expand Down
40 changes: 40 additions & 0 deletions tests/dialects/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,43 @@ def test_column_index():
]

assert result == expected


def test_table_properties():
ddl = """CREATE TABLE `posts`(
`integer_column__index` INT NOT NULL INDEX
) ENGINE=InnoDB AUTO_INCREMENT=4682 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='test';"""

result = DDLParser(ddl).run(output_mode="mysql")
expected = [
{
"alter": {},
"checks": [],
"auto_increment": "4682",
"columns": [
{
"check": None,
"default": None,
"index": True,
"name": "`integer_column__index`",
"nullable": False,
"references": None,
"size": None,
"type": "INT",
"unique": False,
}
],
"comment": "'test'",
"default_charset": "utf8mb4",
"engine": "InnoDB",
"index": [],
"partitioned_by": [],
"primary_key": [],
"schema": None,
"table_name": "`posts`",
"tablespace": None,
"table_properties": {"collate": "utf8mb4_unicode_ci"}
}
]
assert result == expected

0 comments on commit 2bc0075

Please sign in to comment.