Skip to content

add table comment to generated code #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
8 changes: 7 additions & 1 deletion src/sqlacodegen/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,9 @@ def render_models(self, models: list[Model]) -> str:

def render_class(self, model: ModelClass) -> str:
sections: list[str] = []

comments = self.render_table_comment(model)
if comments:
sections.append(comments)
# Render class variables / special declarations
Comment on lines +1113 to 1114
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a blank line after a control block ends.

Suggested change
sections.append(comments)
# Render class variables / special declarations
sections.append(comments)
# Render class variables / special declarations

class_vars: str = self.render_class_variables(model)
if class_vars:
Expand Down Expand Up @@ -1147,6 +1149,10 @@ def render_class_declaration(self, model: ModelClass) -> str:
)
return f"class {model.name}({parent_class_name}):"

def render_table_comment(self, model: ModelClass) -> str:
if model.table.comment:
return f'"""{model.table.comment}"""'
Copy link
Owner

@agronholm agronholm Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No wrapping for long docstrings then...?


def render_class_variables(self, model: ModelClass) -> str:
variables = [f"__tablename__ = {model.table.name!r}"]

Expand Down
Loading