mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-08-26 16:40:40 +03:00
lint code + format
This commit is contained in:
parent
efadedaab0
commit
f0ae471c39
@ -14,10 +14,12 @@ target_metadata = app_base.metadata
|
||||
|
||||
|
||||
def do_run_migrations(connection):
|
||||
context.configure(connection=connection,
|
||||
target_metadata=target_metadata,
|
||||
include_schemas=True,
|
||||
version_table_schema=target_metadata.schema)
|
||||
context.configure(
|
||||
connection=connection,
|
||||
target_metadata=target_metadata,
|
||||
include_schemas=True,
|
||||
version_table_schema=target_metadata.schema,
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
@ -10,7 +10,7 @@ import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '957232a5b7ee'
|
||||
revision = "957232a5b7ee"
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
@ -18,104 +18,143 @@ depends_on = None
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('nonsense',
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), autoincrement=True, nullable=True),
|
||||
sa.Column('name', sa.String(), nullable=False),
|
||||
sa.Column('description', sa.String(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('name'),
|
||||
sa.UniqueConstraint('id'),
|
||||
sa.UniqueConstraint('name'),
|
||||
schema='happy_hog'
|
||||
op.create_table(
|
||||
"nonsense",
|
||||
sa.Column(
|
||||
"id", postgresql.UUID(as_uuid=True), autoincrement=True, nullable=True
|
||||
),
|
||||
sa.Column("name", sa.String(), nullable=False),
|
||||
sa.Column("description", sa.String(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("name"),
|
||||
sa.UniqueConstraint("id"),
|
||||
sa.UniqueConstraint("name"),
|
||||
schema="happy_hog",
|
||||
)
|
||||
op.create_table('stuff',
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), autoincrement=True, nullable=True),
|
||||
sa.Column('name', sa.String(), nullable=False),
|
||||
sa.Column('description', sa.String(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('name'),
|
||||
sa.UniqueConstraint('id'),
|
||||
sa.UniqueConstraint('name'),
|
||||
schema='happy_hog'
|
||||
op.create_table(
|
||||
"stuff",
|
||||
sa.Column(
|
||||
"id", postgresql.UUID(as_uuid=True), autoincrement=True, nullable=True
|
||||
),
|
||||
sa.Column("name", sa.String(), nullable=False),
|
||||
sa.Column("description", sa.String(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("name"),
|
||||
sa.UniqueConstraint("id"),
|
||||
sa.UniqueConstraint("name"),
|
||||
schema="happy_hog",
|
||||
)
|
||||
op.create_table('character',
|
||||
sa.Column('id', sa.String(length=32), nullable=False),
|
||||
sa.Column('name', sa.String(length=64), nullable=False),
|
||||
sa.Column('speech_count', sa.Integer(), nullable=False),
|
||||
sa.Column('abbrev', sa.String(length=32), nullable=True),
|
||||
sa.Column('description', sa.String(length=2056), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id', name='character_pkey'),
|
||||
schema='shakespeare'
|
||||
op.create_table(
|
||||
"character",
|
||||
sa.Column("id", sa.String(length=32), nullable=False),
|
||||
sa.Column("name", sa.String(length=64), nullable=False),
|
||||
sa.Column("speech_count", sa.Integer(), nullable=False),
|
||||
sa.Column("abbrev", sa.String(length=32), nullable=True),
|
||||
sa.Column("description", sa.String(length=2056), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id", name="character_pkey"),
|
||||
schema="shakespeare",
|
||||
)
|
||||
op.create_table('wordform',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('plain_text', sa.String(length=64), nullable=False),
|
||||
sa.Column('phonetic_text', sa.String(length=64), nullable=False),
|
||||
sa.Column('stem_text', sa.String(length=64), nullable=False),
|
||||
sa.Column('occurences', sa.Integer(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id', name='wordform_pkey'),
|
||||
schema='shakespeare'
|
||||
op.create_table(
|
||||
"wordform",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("plain_text", sa.String(length=64), nullable=False),
|
||||
sa.Column("phonetic_text", sa.String(length=64), nullable=False),
|
||||
sa.Column("stem_text", sa.String(length=64), nullable=False),
|
||||
sa.Column("occurences", sa.Integer(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("id", name="wordform_pkey"),
|
||||
schema="shakespeare",
|
||||
)
|
||||
op.create_table('work',
|
||||
sa.Column('id', sa.String(length=32), nullable=False),
|
||||
sa.Column('title', sa.String(length=32), nullable=False),
|
||||
sa.Column('long_title', sa.String(length=64), nullable=False),
|
||||
sa.Column('year', sa.Integer(), nullable=False),
|
||||
sa.Column('genre_type', sa.String(length=1), nullable=False),
|
||||
sa.Column('source', sa.String(length=16), nullable=False),
|
||||
sa.Column('total_words', sa.Integer(), nullable=False),
|
||||
sa.Column('total_paragraphs', sa.Integer(), nullable=False),
|
||||
sa.Column('notes', sa.Text(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id', name='work_pkey'),
|
||||
schema='shakespeare'
|
||||
op.create_table(
|
||||
"work",
|
||||
sa.Column("id", sa.String(length=32), nullable=False),
|
||||
sa.Column("title", sa.String(length=32), nullable=False),
|
||||
sa.Column("long_title", sa.String(length=64), nullable=False),
|
||||
sa.Column("year", sa.Integer(), nullable=False),
|
||||
sa.Column("genre_type", sa.String(length=1), nullable=False),
|
||||
sa.Column("source", sa.String(length=16), nullable=False),
|
||||
sa.Column("total_words", sa.Integer(), nullable=False),
|
||||
sa.Column("total_paragraphs", sa.Integer(), nullable=False),
|
||||
sa.Column("notes", sa.Text(), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id", name="work_pkey"),
|
||||
schema="shakespeare",
|
||||
)
|
||||
op.create_table('chapter',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('work_id', sa.String(length=32), nullable=False),
|
||||
sa.Column('section_number', sa.Integer(), nullable=False),
|
||||
sa.Column('chapter_number', sa.Integer(), nullable=False),
|
||||
sa.Column('description', sa.String(length=256), nullable=False),
|
||||
sa.ForeignKeyConstraint(['work_id'], ['shakespeare.work.id'], name='chapter_work_id_fkey'),
|
||||
sa.PrimaryKeyConstraint('id', name='chapter_pkey'),
|
||||
sa.UniqueConstraint('work_id', 'section_number', 'chapter_number', name='chapter_work_id_section_number_chapter_number_key'),
|
||||
schema='shakespeare'
|
||||
op.create_table(
|
||||
"chapter",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("work_id", sa.String(length=32), nullable=False),
|
||||
sa.Column("section_number", sa.Integer(), nullable=False),
|
||||
sa.Column("chapter_number", sa.Integer(), nullable=False),
|
||||
sa.Column("description", sa.String(length=256), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
["work_id"], ["shakespeare.work.id"], name="chapter_work_id_fkey"
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id", name="chapter_pkey"),
|
||||
sa.UniqueConstraint(
|
||||
"work_id",
|
||||
"section_number",
|
||||
"chapter_number",
|
||||
name="chapter_work_id_section_number_chapter_number_key",
|
||||
),
|
||||
schema="shakespeare",
|
||||
)
|
||||
op.create_table('character_work',
|
||||
sa.Column('character_id', sa.String(length=32), nullable=False),
|
||||
sa.Column('work_id', sa.String(length=32), nullable=False),
|
||||
sa.ForeignKeyConstraint(['character_id'], ['shakespeare.character.id'], name='character_work_character_id_fkey'),
|
||||
sa.ForeignKeyConstraint(['work_id'], ['shakespeare.work.id'], name='character_work_work_id_fkey'),
|
||||
sa.PrimaryKeyConstraint('character_id', 'work_id', name='character_work_pkey'),
|
||||
schema='shakespeare'
|
||||
op.create_table(
|
||||
"character_work",
|
||||
sa.Column("character_id", sa.String(length=32), nullable=False),
|
||||
sa.Column("work_id", sa.String(length=32), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
["character_id"],
|
||||
["shakespeare.character.id"],
|
||||
name="character_work_character_id_fkey",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["work_id"], ["shakespeare.work.id"], name="character_work_work_id_fkey"
|
||||
),
|
||||
sa.PrimaryKeyConstraint("character_id", "work_id", name="character_work_pkey"),
|
||||
schema="shakespeare",
|
||||
)
|
||||
op.create_table('paragraph',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('work_id', sa.String(length=32), nullable=False),
|
||||
sa.Column('paragraph_num', sa.Integer(), nullable=False),
|
||||
sa.Column('character_id', sa.String(length=32), nullable=False),
|
||||
sa.Column('plain_text', sa.Text(), nullable=False),
|
||||
sa.Column('phonetic_text', sa.Text(), nullable=False),
|
||||
sa.Column('stem_text', sa.Text(), nullable=False),
|
||||
sa.Column('paragraph_type', sa.String(length=1), nullable=False),
|
||||
sa.Column('section_number', sa.Integer(), nullable=False),
|
||||
sa.Column('chapter_number', sa.Integer(), nullable=False),
|
||||
sa.Column('char_count', sa.Integer(), nullable=False),
|
||||
sa.Column('word_count', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['character_id'], ['shakespeare.character.id'], name='paragraph_character_id_fkey'),
|
||||
sa.ForeignKeyConstraint(['work_id', 'section_number', 'chapter_number'], ['shakespeare.chapter.work_id', 'shakespeare.chapter.section_number', 'shakespeare.chapter.chapter_number'], name='paragraph_chapter_fkey'),
|
||||
sa.ForeignKeyConstraint(['work_id'], ['shakespeare.work.id'], name='paragraph_work_id_fkey'),
|
||||
sa.PrimaryKeyConstraint('id', name='paragraph_pkey'),
|
||||
schema='shakespeare'
|
||||
op.create_table(
|
||||
"paragraph",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("work_id", sa.String(length=32), nullable=False),
|
||||
sa.Column("paragraph_num", sa.Integer(), nullable=False),
|
||||
sa.Column("character_id", sa.String(length=32), nullable=False),
|
||||
sa.Column("plain_text", sa.Text(), nullable=False),
|
||||
sa.Column("phonetic_text", sa.Text(), nullable=False),
|
||||
sa.Column("stem_text", sa.Text(), nullable=False),
|
||||
sa.Column("paragraph_type", sa.String(length=1), nullable=False),
|
||||
sa.Column("section_number", sa.Integer(), nullable=False),
|
||||
sa.Column("chapter_number", sa.Integer(), nullable=False),
|
||||
sa.Column("char_count", sa.Integer(), nullable=False),
|
||||
sa.Column("word_count", sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
["character_id"],
|
||||
["shakespeare.character.id"],
|
||||
name="paragraph_character_id_fkey",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["work_id", "section_number", "chapter_number"],
|
||||
[
|
||||
"shakespeare.chapter.work_id",
|
||||
"shakespeare.chapter.section_number",
|
||||
"shakespeare.chapter.chapter_number",
|
||||
],
|
||||
name="paragraph_chapter_fkey",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["work_id"], ["shakespeare.work.id"], name="paragraph_work_id_fkey"
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id", name="paragraph_pkey"),
|
||||
schema="shakespeare",
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('paragraph', schema='shakespeare')
|
||||
op.drop_table('character_work', schema='shakespeare')
|
||||
op.drop_table('chapter', schema='shakespeare')
|
||||
op.drop_table('work', schema='shakespeare')
|
||||
op.drop_table('wordform', schema='shakespeare')
|
||||
op.drop_table('character', schema='shakespeare')
|
||||
op.drop_table('stuff', schema='happy_hog')
|
||||
op.drop_table('nonsense', schema='happy_hog')
|
||||
op.drop_table("paragraph", schema="shakespeare")
|
||||
op.drop_table("character_work", schema="shakespeare")
|
||||
op.drop_table("chapter", schema="shakespeare")
|
||||
op.drop_table("work", schema="shakespeare")
|
||||
op.drop_table("wordform", schema="shakespeare")
|
||||
op.drop_table("character", schema="shakespeare")
|
||||
op.drop_table("stuff", schema="happy_hog")
|
||||
op.drop_table("nonsense", schema="happy_hog")
|
||||
# ### end Alembic commands ###
|
||||
|
@ -9,7 +9,9 @@ router = APIRouter(prefix="/v1/nonsense")
|
||||
|
||||
|
||||
@router.post("/", status_code=status.HTTP_201_CREATED, response_model=NonsenseResponse)
|
||||
async def create_nonsense(payload: NonsenseSchema, db_session: AsyncSession = Depends(get_db)):
|
||||
async def create_nonsense(
|
||||
payload: NonsenseSchema, db_session: AsyncSession = Depends(get_db)
|
||||
):
|
||||
nonsense = Nonsense(**payload.dict())
|
||||
await nonsense.save(db_session)
|
||||
return nonsense
|
||||
|
@ -13,21 +13,31 @@ logger = get_logger(__name__)
|
||||
|
||||
|
||||
@router.post("/add_many", status_code=status.HTTP_201_CREATED)
|
||||
async def create_multi_stuff(payload: list[StuffSchema], db_session: AsyncSession = Depends(get_db)):
|
||||
async def create_multi_stuff(
|
||||
payload: list[StuffSchema], db_session: AsyncSession = Depends(get_db)
|
||||
):
|
||||
try:
|
||||
stuff_instances = [Stuff(name=stuf.name, description=stuf.description) for stuf in payload]
|
||||
stuff_instances = [
|
||||
Stuff(name=stuf.name, description=stuf.description) for stuf in payload
|
||||
]
|
||||
db_session.add_all(stuff_instances)
|
||||
await db_session.commit()
|
||||
except SQLAlchemyError as ex:
|
||||
# logger.exception(ex)
|
||||
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)) from ex
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)
|
||||
) from ex
|
||||
else:
|
||||
logger.info(f"{len(stuff_instances)} instances of Stuff inserted into database.")
|
||||
logger.info(
|
||||
f"{len(stuff_instances)} instances of Stuff inserted into database."
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
@router.post("", status_code=status.HTTP_201_CREATED, response_model=StuffResponse)
|
||||
async def create_stuff(payload: StuffSchema, db_session: AsyncSession = Depends(get_db)):
|
||||
async def create_stuff(
|
||||
payload: StuffSchema, db_session: AsyncSession = Depends(get_db)
|
||||
):
|
||||
stuff = Stuff(name=payload.name, description=payload.description)
|
||||
await stuff.save(db_session)
|
||||
return stuff
|
||||
|
@ -31,7 +31,9 @@ class Settings(BaseSettings):
|
||||
pg_pass: str = os.getenv("POSTGRES_PASSWORD", "")
|
||||
pg_host: str = os.getenv("SQL_HOST", "")
|
||||
pg_database: str = os.getenv("SQL_DB", "")
|
||||
asyncpg_url: str = f"postgresql+asyncpg://{pg_user}:{pg_pass}@{pg_host}:5432/{pg_database}"
|
||||
asyncpg_url: str = (
|
||||
f"postgresql+asyncpg://{pg_user}:{pg_pass}@{pg_host}:5432/{pg_database}"
|
||||
)
|
||||
|
||||
jwt_secret_key: str = os.getenv("SECRET_KEY", "")
|
||||
jwt_algorithm: str = os.getenv("ALGORITHM", "")
|
||||
|
@ -1,8 +1,6 @@
|
||||
from collections.abc import AsyncGenerator
|
||||
from http.client import HTTPException
|
||||
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
@ -23,7 +21,9 @@ engine = create_async_engine(
|
||||
|
||||
# expire_on_commit=False will prevent attributes from being expired
|
||||
# after commit.
|
||||
AsyncSessionFactory = sessionmaker(engine, autoflush=False, expire_on_commit=False, class_=AsyncSession)
|
||||
AsyncSessionFactory = sessionmaker(
|
||||
engine, autoflush=False, expire_on_commit=False, class_=AsyncSession
|
||||
)
|
||||
|
||||
|
||||
# Dependency
|
||||
@ -31,4 +31,3 @@ async def get_db() -> AsyncGenerator:
|
||||
async with AsyncSessionFactory() as session:
|
||||
logger.debug(f"ASYNC Pool: {engine.pool.status()}")
|
||||
yield session
|
||||
|
||||
|
@ -37,7 +37,9 @@ class Base:
|
||||
db_session.add(self)
|
||||
return await db_session.commit()
|
||||
except SQLAlchemyError as ex:
|
||||
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)) from ex
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)
|
||||
) from ex
|
||||
|
||||
async def delete(self, db_session: AsyncSession):
|
||||
"""
|
||||
@ -50,7 +52,9 @@ class Base:
|
||||
await db_session.commit()
|
||||
return True
|
||||
except SQLAlchemyError as ex:
|
||||
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)) from ex
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)
|
||||
) from ex
|
||||
|
||||
async def update(self, db_session: AsyncSession, **kwargs):
|
||||
"""
|
||||
|
@ -29,7 +29,9 @@ class Nonsense(Base):
|
||||
if instance is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail={"Record not found": f"There is no record for requested name value : {name}"},
|
||||
detail={
|
||||
"Record not found": f"There is no record for requested name value : {name}"
|
||||
},
|
||||
)
|
||||
else:
|
||||
return instance
|
||||
|
@ -20,7 +20,10 @@ metadata = Base.metadata
|
||||
|
||||
class Character(Base):
|
||||
__tablename__ = "character"
|
||||
__table_args__ = (PrimaryKeyConstraint("id", name="character_pkey"), {"schema": "shakespeare"})
|
||||
__table_args__ = (
|
||||
PrimaryKeyConstraint("id", name="character_pkey"),
|
||||
{"schema": "shakespeare"},
|
||||
)
|
||||
|
||||
id = Column(String(32))
|
||||
name = Column(String(64), nullable=False)
|
||||
@ -28,13 +31,18 @@ class Character(Base):
|
||||
abbrev = Column(String(32))
|
||||
description = Column(String(2056))
|
||||
|
||||
work = relationship("Work", secondary="shakespeare.character_work", back_populates="character")
|
||||
work = relationship(
|
||||
"Work", secondary="shakespeare.character_work", back_populates="character"
|
||||
)
|
||||
paragraph = relationship("Paragraph", back_populates="character")
|
||||
|
||||
|
||||
class Wordform(Base):
|
||||
__tablename__ = "wordform"
|
||||
__table_args__ = (PrimaryKeyConstraint("id", name="wordform_pkey"), {"schema": "shakespeare"})
|
||||
__table_args__ = (
|
||||
PrimaryKeyConstraint("id", name="wordform_pkey"),
|
||||
{"schema": "shakespeare"},
|
||||
)
|
||||
|
||||
id = Column(Integer)
|
||||
plain_text = Column(String(64), nullable=False)
|
||||
@ -45,7 +53,10 @@ class Wordform(Base):
|
||||
|
||||
class Work(Base):
|
||||
__tablename__ = "work"
|
||||
__table_args__ = (PrimaryKeyConstraint("id", name="work_pkey"), {"schema": "shakespeare"})
|
||||
__table_args__ = (
|
||||
PrimaryKeyConstraint("id", name="work_pkey"),
|
||||
{"schema": "shakespeare"},
|
||||
)
|
||||
|
||||
id = Column(String(32))
|
||||
title = Column(String(32), nullable=False)
|
||||
@ -57,7 +68,9 @@ class Work(Base):
|
||||
total_paragraphs = Column(Integer, nullable=False)
|
||||
notes = Column(Text)
|
||||
|
||||
character = relationship("Character", secondary="shakespeare.character_work", back_populates="work")
|
||||
character = relationship(
|
||||
"Character", secondary="shakespeare.character_work", back_populates="work"
|
||||
)
|
||||
chapter = relationship("Chapter", back_populates="work")
|
||||
paragraph = relationship("Paragraph", back_populates="work")
|
||||
|
||||
@ -65,10 +78,15 @@ class Work(Base):
|
||||
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"},
|
||||
)
|
||||
@ -88,8 +106,14 @@ t_character_work = Table(
|
||||
metadata,
|
||||
Column("character_id", ForeignKey("shakespeare.character.id"), nullable=False),
|
||||
Column("work_id", ForeignKey("shakespeare.work.id"), 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",
|
||||
)
|
||||
@ -98,13 +122,23 @@ t_character_work = Table(
|
||||
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"},
|
||||
)
|
||||
@ -128,7 +162,13 @@ class Paragraph(Base):
|
||||
|
||||
@classmethod
|
||||
async def find(cls, db_session: AsyncSession, character: str):
|
||||
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)
|
||||
instance = result.scalars().all()
|
||||
return instance
|
||||
|
@ -10,8 +10,12 @@ console = Console(color_system="256", width=200, style="blue")
|
||||
@lru_cache
|
||||
def get_logger(module_name):
|
||||
logger = logging.getLogger(module_name)
|
||||
handler = RichHandler(rich_tracebacks=True, console=console, tracebacks_show_locals=True)
|
||||
handler.setFormatter(logging.Formatter("[ %(threadName)s:%(funcName)s:%(lineno)d ] - %(message)s"))
|
||||
handler = RichHandler(
|
||||
rich_tracebacks=True, console=console, tracebacks_show_locals=True
|
||||
)
|
||||
handler.setFormatter(
|
||||
logging.Formatter("[ %(threadName)s:%(funcName)s:%(lineno)d ] - %(message)s")
|
||||
)
|
||||
logger.addHandler(handler)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
return logger
|
||||
|
34
poetry.lock
generated
34
poetry.lock
generated
@ -430,14 +430,11 @@ python-versions = "*"
|
||||
|
||||
[[package]]
|
||||
name = "packaging"
|
||||
version = "21.3"
|
||||
version = "23.0"
|
||||
description = "Core utilities for Python packages"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
|
||||
[package.dependencies]
|
||||
pyparsing = ">=2.0.2,<3.0.5 || >3.0.5"
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[[package]]
|
||||
name = "parso"
|
||||
@ -558,17 +555,6 @@ python-versions = ">=3.6"
|
||||
[package.extras]
|
||||
plugins = ["importlib-metadata"]
|
||||
|
||||
[[package]]
|
||||
name = "pyparsing"
|
||||
version = "3.0.9"
|
||||
description = "pyparsing module - Classes and methods to define and execute parsing grammars"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.6.8"
|
||||
|
||||
[package.extras]
|
||||
diagrams = ["jinja2", "railroad-diagrams"]
|
||||
|
||||
[[package]]
|
||||
name = "pytest"
|
||||
version = "7.2.1"
|
||||
@ -729,7 +715,7 @@ python-versions = ">=3.7"
|
||||
|
||||
[[package]]
|
||||
name = "safety"
|
||||
version = "2.3.5"
|
||||
version = "2.3.4"
|
||||
description = "Checks installed dependencies for known vulnerabilities and licenses."
|
||||
category = "main"
|
||||
optional = false
|
||||
@ -738,7 +724,7 @@ python-versions = "*"
|
||||
[package.dependencies]
|
||||
Click = ">=8.0.2"
|
||||
dparse = ">=0.6.2"
|
||||
packaging = ">=21.0,<22.0"
|
||||
packaging = ">=21.0"
|
||||
requests = "*"
|
||||
"ruamel.yaml" = ">=0.17.21"
|
||||
setuptools = ">=19.3"
|
||||
@ -1433,8 +1419,8 @@ mypy-extensions = [
|
||||
{file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"},
|
||||
]
|
||||
packaging = [
|
||||
{file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"},
|
||||
{file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"},
|
||||
{file = "packaging-23.0-py3-none-any.whl", hash = "sha256:714ac14496c3e68c99c29b00845f7a2b85f3bb6f1078fd9f72fd20f0570002b2"},
|
||||
{file = "packaging-23.0.tar.gz", hash = "sha256:b6ad297f8907de0fa2fe1ccbd26fdaf387f5f47c7275fedf8cce89f99446cf97"},
|
||||
]
|
||||
parso = [
|
||||
{file = "parso-0.8.3-py2.py3-none-any.whl", hash = "sha256:c001d4636cd3aecdaf33cbb40aebb59b094be2a74c556778ef5576c175e19e75"},
|
||||
@ -1514,10 +1500,6 @@ Pygments = [
|
||||
{file = "Pygments-2.14.0-py3-none-any.whl", hash = "sha256:fa7bd7bd2771287c0de303af8bfdfc731f51bd2c6a47ab69d117138893b82717"},
|
||||
{file = "Pygments-2.14.0.tar.gz", hash = "sha256:b3ed06a9e8ac9a9aae5a6f5dbe78a8a58655d17b43b93c078f094ddc476ae297"},
|
||||
]
|
||||
pyparsing = [
|
||||
{file = "pyparsing-3.0.9-py3-none-any.whl", hash = "sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc"},
|
||||
{file = "pyparsing-3.0.9.tar.gz", hash = "sha256:2b020ecf7d21b687f219b71ecad3631f644a47f01403fa1d1036b0c6416d70fb"},
|
||||
]
|
||||
pytest = [
|
||||
{file = "pytest-7.2.1-py3-none-any.whl", hash = "sha256:c7c6ca206e93355074ae32f7403e8ea12163b1163c976fee7d4d84027c162be5"},
|
||||
{file = "pytest-7.2.1.tar.gz", hash = "sha256:d45e0952f3727241918b8fd0f376f5ff6b301cc0777c6f9a556935c92d8a7d42"},
|
||||
@ -1650,8 +1632,8 @@ ruff = [
|
||||
{file = "ruff-0.0.224.tar.gz", hash = "sha256:3b07c2e8da29605a8577b1aef90f8ca0c34a66683b77b06007f1970bc0689003"},
|
||||
]
|
||||
safety = [
|
||||
{file = "safety-2.3.5-py3-none-any.whl", hash = "sha256:2227fcac1b22b53c1615af78872b48348661691450aa25d6704a5504dbd1f7e2"},
|
||||
{file = "safety-2.3.5.tar.gz", hash = "sha256:a60c11f8952f412cbb165d70cb1f673a3b43a2ba9a93ce11f97e6a4de834aa3a"},
|
||||
{file = "safety-2.3.4-py3-none-any.whl", hash = "sha256:6224dcd9b20986a2b2c5e7acfdfba6bca42bb11b2783b24ed04f32317e5167ea"},
|
||||
{file = "safety-2.3.4.tar.gz", hash = "sha256:b9e74e794e82f54d11f4091c5d820c4d2d81de9f953bf0b4f33ac8bc402ae72c"},
|
||||
]
|
||||
setuptools = [
|
||||
{file = "setuptools-66.0.0-py3-none-any.whl", hash = "sha256:a78d01d1e2c175c474884671dde039962c9d74c7223db7369771fcf6e29ceeab"},
|
||||
|
@ -37,7 +37,7 @@ build-backend = "poetry.core.masonry.api"
|
||||
[tool.ruff]
|
||||
line-length = 120
|
||||
|
||||
select = ["E", "F", "U", "N", "C", "B"]
|
||||
select = ["E", "F", "UP", "N", "C", "B"]
|
||||
|
||||
# Exclude a variety of commonly ignored directories.
|
||||
exclude = ["alembic",]
|
||||
|
@ -75,7 +75,11 @@ async def test_delete_stuff(client: AsyncClient, payload: dict, status_code: int
|
||||
),
|
||||
)
|
||||
async def test_update_stuff(
|
||||
client: AsyncClient, payload: dict, status_code: int, patch_payload: dict, patch_status_code: int
|
||||
client: AsyncClient,
|
||||
payload: dict,
|
||||
status_code: int,
|
||||
patch_payload: dict,
|
||||
patch_status_code: int,
|
||||
):
|
||||
await client.post("/stuff", json=payload)
|
||||
name = payload["name"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user