code format

This commit is contained in:
Jakub Miazek
2024-04-24 10:37:08 +02:00
parent 43fe665608
commit c2975fd260
19 changed files with 358 additions and 173 deletions

View File

@@ -34,7 +34,10 @@ class Character(Base):
"""
__tablename__ = "character"
__table_args__ = (PrimaryKeyConstraint("id", name="character_pkey"), {"schema": "shakespeare"})
__table_args__ = (
PrimaryKeyConstraint("id", name="character_pkey"),
{"schema": "shakespeare"},
)
id: Mapped[str] = mapped_column(String(32), primary_key=True)
name: Mapped[str] = mapped_column(String(64))
@@ -45,7 +48,9 @@ class Character(Base):
work: Mapped[list["Work"]] = relationship(
"Work", secondary="shakespeare.character_work", back_populates="character"
)
paragraph: Mapped[list["Paragraph"]] = relationship("Paragraph", back_populates="character")
paragraph: Mapped[list["Paragraph"]] = relationship(
"Paragraph", back_populates="character"
)
class Wordform(Base):
@@ -65,7 +70,10 @@ class Wordform(Base):
"""
__tablename__ = "wordform"
__table_args__ = (PrimaryKeyConstraint("id", name="wordform_pkey"), {"schema": "shakespeare"})
__table_args__ = (
PrimaryKeyConstraint("id", name="wordform_pkey"),
{"schema": "shakespeare"},
)
id: Mapped[int] = mapped_column(Integer, primary_key=True)
plain_text: Mapped[str] = mapped_column(String(64))
@@ -98,7 +106,10 @@ class Work(Base):
"""
__tablename__ = "work"
__table_args__ = (PrimaryKeyConstraint("id", name="work_pkey"), {"schema": "shakespeare"})
__table_args__ = (
PrimaryKeyConstraint("id", name="work_pkey"),
{"schema": "shakespeare"},
)
id: Mapped[str] = mapped_column(String(32), primary_key=True)
title: Mapped[str] = mapped_column(String(32))
@@ -114,7 +125,9 @@ class Work(Base):
"Character", secondary="shakespeare.character_work", back_populates="work"
)
chapter: Mapped[list["Chapter"]] = relationship("Chapter", back_populates="work")
paragraph: Mapped[list["Paragraph"]] = relationship("Paragraph", back_populates="work")
paragraph: Mapped[list["Paragraph"]] = relationship(
"Paragraph", back_populates="work"
)
class Chapter(Base):
@@ -137,10 +150,15 @@ class Chapter(Base):
__tablename__ = "chapter"
__table_args__ = (
ForeignKeyConstraint(["work_id"], ["shakespeare.work.id"], name="chapter_work_id_fkey"),
ForeignKeyConstraint(
["work_id"], ["shakespeare.work.id"], name="chapter_work_id_fkey"
),
PrimaryKeyConstraint("id", name="chapter_pkey"),
UniqueConstraint(
"work_id", "section_number", "chapter_number", name="chapter_work_id_section_number_chapter_number_key"
"work_id",
"section_number",
"chapter_number",
name="chapter_work_id_section_number_chapter_number_key",
),
{"schema": "shakespeare"},
)
@@ -152,7 +170,9 @@ class Chapter(Base):
description: Mapped[str] = mapped_column(String(256))
work: Mapped["Work"] = relationship("Work", back_populates="chapter")
paragraph: Mapped[list["Paragraph"]] = relationship("Paragraph", back_populates="chapter")
paragraph: Mapped[list["Paragraph"]] = relationship(
"Paragraph", back_populates="chapter"
)
t_character_work = Table(
@@ -160,8 +180,14 @@ t_character_work = Table(
Base.metadata,
Column("character_id", String(32), primary_key=True, nullable=False),
Column("work_id", String(32), primary_key=True, nullable=False),
ForeignKeyConstraint(["character_id"], ["shakespeare.character.id"], name="character_work_character_id_fkey"),
ForeignKeyConstraint(["work_id"], ["shakespeare.work.id"], name="character_work_work_id_fkey"),
ForeignKeyConstraint(
["character_id"],
["shakespeare.character.id"],
name="character_work_character_id_fkey",
),
ForeignKeyConstraint(
["work_id"], ["shakespeare.work.id"], name="character_work_work_id_fkey"
),
PrimaryKeyConstraint("character_id", "work_id", name="character_work_pkey"),
schema="shakespeare",
)
@@ -198,13 +224,23 @@ class Paragraph(Base):
__tablename__ = "paragraph"
__table_args__ = (
ForeignKeyConstraint(["character_id"], ["shakespeare.character.id"], name="paragraph_character_id_fkey"),
ForeignKeyConstraint(
["character_id"],
["shakespeare.character.id"],
name="paragraph_character_id_fkey",
),
ForeignKeyConstraint(
["work_id", "section_number", "chapter_number"],
["shakespeare.chapter.work_id", "shakespeare.chapter.section_number", "shakespeare.chapter.chapter_number"],
[
"shakespeare.chapter.work_id",
"shakespeare.chapter.section_number",
"shakespeare.chapter.chapter_number",
],
name="paragraph_chapter_fkey",
),
ForeignKeyConstraint(["work_id"], ["shakespeare.work.id"], name="paragraph_work_id_fkey"),
ForeignKeyConstraint(
["work_id"], ["shakespeare.work.id"], name="paragraph_work_id_fkey"
),
PrimaryKeyConstraint("id", name="paragraph_pkey"),
{"schema": "shakespeare"},
)
@@ -222,7 +258,9 @@ class Paragraph(Base):
char_count: Mapped[int] = mapped_column(Integer)
word_count: Mapped[int] = mapped_column(Integer)
character: Mapped["Character"] = relationship("Character", back_populates="paragraph")
character: Mapped["Character"] = relationship(
"Character", back_populates="paragraph"
)
chapter: Mapped["Chapter"] = relationship("Chapter", back_populates="paragraph")
work: Mapped["Work"] = relationship("Work", back_populates="paragraph")
@@ -244,6 +282,12 @@ class Paragraph(Base):
- List[Paragraph]: A list of `Paragraph` objects that are associated with the specified character.
"""
stmt = select(cls).join(Character).join(Chapter).join(Work).where(Character.name == character)
stmt = (
select(cls)
.join(Character)
.join(Chapter)
.join(Work)
.where(Character.name == character)
)
result = await db_session.execute(stmt)
return result.scalars().all()