Skip to content

Commit f497b18

Browse files
committed
✨ NEW: Add indexes section
1 parent 0bdf385 commit f497b18

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

docs/example/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Address(Base):
2222
__table_args__ = (CheckConstraint("number>0", name="check1"),)
2323
pk = Column(types.Integer, primary_key=True)
2424
number = Column(types.Integer, nullable=False, doc="The number of the address.")
25-
postcode = Column(types.String, nullable=False)
25+
postcode = Column(
26+
types.String, nullable=False, index=True, doc="The postcode of the address."
27+
)
2628
user_id = Column(types.Integer, ForeignKey("dbusers.pk"))
2729
user = orm.relationship("User")

sphinx_sqlalchemy/main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from sqlalchemy.sql.schema import (
1212
CheckConstraint,
1313
ForeignKeyConstraint,
14+
Index,
1415
PrimaryKeyConstraint,
1516
UniqueConstraint,
1617
)
@@ -137,6 +138,13 @@ def add_content(self, mapper: Mapper, definition: nodes.definition) -> None:
137138
for text in sorted(contraint_to_str(c) for c in constraints):
138139
definition[-1] += nodes.list_item("", nodes.paragraph(text=text))
139140

141+
# table indexes
142+
if mapper.local_table is not None and mapper.local_table.indexes:
143+
definition += nodes.rubric(text="Indexes:")
144+
definition += nodes.bullet_list()
145+
for text in sorted(index_to_str(c) for c in mapper.local_table.indexes):
146+
definition[-1] += nodes.list_item("", nodes.paragraph(text=text))
147+
140148

141149
def contraint_to_str(constraint: Constraint) -> str:
142150
"""Convert a constraint to a string."""
@@ -153,3 +161,8 @@ def contraint_to_str(constraint: Constraint) -> str:
153161
if isinstance(constraint, CheckConstraint):
154162
return f"CHECK ({constraint.sqltext.text})" # type: ignore
155163
return "UNKNOWN"
164+
165+
166+
def index_to_str(index: Index) -> str:
167+
"""Convert an index to a string."""
168+
return f"{index.name} ({', '.join(c.name for c in index.columns)})"

0 commit comments

Comments
 (0)