Skip to content

Commit

Permalink
Update docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
ri-gilfanov committed Jun 22, 2021
1 parent 7b704b6 commit 6448016
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
5 changes: 4 additions & 1 deletion aiohttp_sqlalchemy/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@


def sa_decorator(key: str = SA_DEFAULT_KEY) -> THandlerWrapper:
"""SQLAlchemy asynchronous handler decorator."""
"""SQLAlchemy asynchronous handler decorator.
:param key: key of SQLAlchemy binding. Has default.
"""

def wrapper(handler: THandler) -> THandler:
@wraps(handler)
Expand Down
5 changes: 4 additions & 1 deletion aiohttp_sqlalchemy/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@


def sa_middleware(key: str = SA_DEFAULT_KEY) -> THandler:
"""SQLAlchemy asynchronous middleware factory."""
"""SQLAlchemy asynchronous middleware factory.
:param key: key of SQLAlchemy binding. Has default.
"""

@middleware
async def sa_middleware_(request: Request, handler: THandler) -> StreamResponse:
Expand Down
19 changes: 17 additions & 2 deletions aiohttp_sqlalchemy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ async def init_db(
metadata: MetaData,
key: str = SA_DEFAULT_KEY,
) -> None:
"""Create all tables, indexes and etc.
:param app: instance of ``aiohttp.web_app.Application``.
:param metadata: instance of ``sqlalchemy.scql.schema.MetaData``.
:param key: key of SQLAlchemy binding. Has default.
"""
session_factory = sa_session_factory(app, key)
async with session_factory() as session:
async with session.bind.begin() as connection:
Expand All @@ -23,7 +29,11 @@ def sa_session(
request: Request,
key: str = SA_DEFAULT_KEY,
) -> AsyncSession:
"""Return ``AsyncSession`` instance."""
"""Return ``AsyncSession`` instance.
:param request: instance of ``aiohttp.web_request.Request``.
:param key: key of SQLAlchemy binding. Has default.
"""
if not isinstance(request, Request):
raise TypeError(f"{request} is not {Request}.")

Expand All @@ -38,7 +48,12 @@ def sa_session_factory(
source: Union[Request, Application],
key: str = SA_DEFAULT_KEY,
) -> TSessionFactory:
"""Return callable object which returns an ``AsyncSession`` instance."""
"""Return callable object which returns an ``AsyncSession`` instance.
:param sorce: instance of ``aiohttp.web_request.Request`` or
``aiohttp.web_app.Application``.
:param key: key of SQLAlchemy binding. Has default.
"""
return cast(TSessionFactory, getattr(source, "app", source).get(key))


Expand Down

0 comments on commit 6448016

Please sign in to comment.