phase 4
This commit is contained in:
@@ -246,6 +246,7 @@ class PydanticGenerator(BaseGenerator):
|
||||
"",
|
||||
]
|
||||
|
||||
|
||||
def _generate_enum(self, enum_def: EnumDefinition) -> List[str]:
|
||||
lines = [f"class {enum_def.name}(str, Enum):"]
|
||||
for name, value in enum_def.values:
|
||||
|
||||
@@ -99,14 +99,9 @@ def _resolve_field(name, type_hint, default):
|
||||
return ""
|
||||
|
||||
|
||||
def _to_snake_plural(name):
|
||||
"""CamelCase → snake_case_plural for table names."""
|
||||
s = re.sub(r"(?<=[a-z])(?=[A-Z])", "_", name).lower()
|
||||
if s.endswith("y") and not s.endswith("ey"):
|
||||
return s[:-1] + "ies"
|
||||
if s.endswith("s"):
|
||||
return s + "es"
|
||||
return s + "s"
|
||||
def _to_snake(name):
|
||||
"""CamelCase → snake_case for table names."""
|
||||
return re.sub(r"(?<=[a-z])(?=[A-Z])", "_", name).lower()
|
||||
|
||||
|
||||
_HEADER = [
|
||||
@@ -162,7 +157,7 @@ class SQLModelGenerator(PydanticGenerator):
|
||||
|
||||
def _build_table(name, docstring, hints, fields, resolve_type_fn):
|
||||
"""Build a SQLModel table class from field data."""
|
||||
table_name = _to_snake_plural(name)
|
||||
table_name = _to_snake(name)
|
||||
lines = [
|
||||
f"class {name}(SQLModel, table=True):",
|
||||
f' """{docstring.strip().split(chr(10))[0]}"""',
|
||||
|
||||
@@ -54,6 +54,7 @@ PYDANTIC_RESOLVERS: dict[Any, Callable[[Any], str]] = {
|
||||
int: lambda _: "int",
|
||||
float: lambda _: "float",
|
||||
bool: lambda _: "bool",
|
||||
Any: lambda _: "Any",
|
||||
"UUID": lambda _: "UUID",
|
||||
"datetime": lambda _: "datetime",
|
||||
"dict": lambda _: "Dict[str, Any]",
|
||||
|
||||
Reference in New Issue
Block a user