Skip to content

Commit

Permalink
Merge branch 'release/0.9.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
ri-gilfanov committed Jun 9, 2021
2 parents fc8cd3d + 3cda233 commit 7fe6dc2
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 19 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ python:
before_install:
- pip install poetry
install:
- pip install coveralls
- poetry install
script:
- pytest --cov=aiohttp_sqlalchemy tests/
- pytest --cov=aiohttp_sqlalchemy
after_success:
- coveralls
14 changes: 11 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@ aiohttp-sqlalchemy

SQLAlchemy 1.4 / 2.0 support for aiohttp.

Library forward a ``sqlalchemy.ext.asyncio.AsyncSession`` object as
``request['sa_main']`` or ``SAView.sa_session()`` by default.
The library provides the next features:

* forwarding SQLAlchemy asynchronous sessions for function handlers, class
organized handlers, and class based view methods;
* a middleware factory ``sa_middleware(key: str = 'sa_main')'`` for forwarding
sessions as ``request[key]`` for all your request handlers;
* a decorator ``sa_decorator(key: str = 'sa_main')`` for forwarding sessions
as ``request[key]`` for your chosen handlers;
* a parent class ``SAView`` for forwarding sessions as
``SAView.sa_session(key: str = 'sa_main')`` method.


Documentation
-------------
https://aiohttp-sqlalchemy.readthedocs.io/
https://aiohttp-sqlalchemy.readthedocs.io


Installation
Expand Down
5 changes: 3 additions & 2 deletions aiohttp_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from aiohttp_sqlalchemy.constants import DEFAULT_KEY
from aiohttp_sqlalchemy.decorators import sa_decorator
from aiohttp_sqlalchemy.exceptions import DuplicateAppKeyError, DuplicateRequestKeyError
from aiohttp_sqlalchemy.exceptions import DuplicateAppKeyError, \
DuplicateRequestKeyError
from aiohttp_sqlalchemy.middlewares import sa_middleware
from aiohttp_sqlalchemy.views import SAAbstractView, SABaseView, SAView

Expand All @@ -16,7 +17,7 @@
TSABinding = Tuple[TSessionFactory, str, bool]


__version__ = '0.9.2'
__version__ = '0.9.3'

__all__ = ['DuplicateAppKeyError', 'DuplicateRequestKeyError',
'SAAbstractView', 'SABaseView', 'sa_bind', 'sa_decorator',
Expand Down
10 changes: 9 additions & 1 deletion aiohttp_sqlalchemy/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@
from aiohttp.web import Request, StreamResponse
from typing import Awaitable, Callable, Union, Type

TSADecoratorResult = Callable[
...,
Union[
Type[AbstractView],
Callable[[Request], Awaitable[StreamResponse]]
]
]


def sa_decorator(key: str = DEFAULT_KEY) \
-> 'Callable[..., Union[Type[AbstractView], Callable[[Request], Awaitable[StreamResponse]]]]':
-> 'TSADecoratorResult':
""" SQLAlchemy asynchronous handler decorator. """
def wrapper(handler):
@wraps(handler)
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Ruslan Ilyasovich Gilfanov'

# The full version, including alpha/beta/rc tags
release = '0.9.2'
release = '0.9.3'


# -- General configuration ---------------------------------------------------
Expand Down
29 changes: 27 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,35 @@ Welcome to aiohttp-sqlalchemy's documentation!

Overview
--------
.. image:: https://readthedocs.org/projects/aiohttp-sqlalchemy/badge/?version=latest
:target: https://aiohttp-sqlalchemy.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

.. image:: https://badge.fury.io/py/aiohttp-sqlalchemy.svg
:target: https://badge.fury.io/py/aiohttp-sqlalchemy

.. image:: https://img.shields.io/pypi/dm/aiohttp-sqlalchemy
:target: https://pypistats.org/packages/aiohttp-sqlalchemy
:alt: Downloads count

.. image:: https://travis-ci.com/ri-gilfanov/aiohttp-sqlalchemy.svg?branch=master
:target: https://travis-ci.com/ri-gilfanov/aiohttp-sqlalchemy

.. image:: https://coveralls.io/repos/github/ri-gilfanov/aiohttp-sqlalchemy/badge.svg?branch=master
:target: https://coveralls.io/github/ri-gilfanov/aiohttp-sqlalchemy?branch=master

SQLAlchemy 1.4 / 2.0 support for aiohttp.

Library forward a ``sqlalchemy.ext.asyncio.AsyncSession`` object as
``request['sa_main']`` or ``SAView.sa_session()`` by default.
The library provides the next features:

* forwarding SQLAlchemy asynchronous sessions for function handlers, class
organized handlers, and class based view methods;
* a middleware factory ``sa_middleware(key: str = 'sa_main')'`` for forwarding
sessions as ``request[key]`` for all your request handlers;
* a decorator ``sa_decorator(key: str = 'sa_main')`` for forwarding sessions
as ``request[key]`` for your chosen handlers;
* a parent class ``SAView`` for forwarding sessions as
``SAView.sa_session(key: str = 'sa_main')`` method.


Installation
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aiohttp-sqlalchemy"
version = "0.9.2"
version = "0.9.3"
description = "SQLAlchemy 1.4 / 2.0 support for aiohttp."
authors = [
"Ruslan Ilyasovich Gilfanov <ri.gilfanov@yandex.ru>",
Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine

import aiohttp_sqlalchemy
from aiohttp_sqlalchemy import sa_bind, sa_middleware
from aiohttp_sqlalchemy.constants import DEFAULT_KEY
from aiohttp_sqlalchemy import DEFAULT_KEY, sa_bind, sa_middleware


pytest_plugins = 'aiohttp.pytest_plugin'
Expand Down
3 changes: 1 addition & 2 deletions tests/test_decorators.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import pytest
from sqlalchemy.ext.asyncio import AsyncSession

from aiohttp_sqlalchemy import DuplicateRequestKeyError, sa_decorator
from aiohttp_sqlalchemy.constants import DEFAULT_KEY
from aiohttp_sqlalchemy import DEFAULT_KEY, DuplicateRequestKeyError, sa_decorator
from tests.conftest import ClassBasedView, ClassHandler, function_handler


Expand Down
3 changes: 1 addition & 2 deletions tests/test_middlewares.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import pytest
from sqlalchemy.ext.asyncio import AsyncSession

from aiohttp_sqlalchemy import DuplicateRequestKeyError
from aiohttp_sqlalchemy.constants import DEFAULT_KEY
from aiohttp_sqlalchemy import DEFAULT_KEY, DuplicateRequestKeyError
from tests.conftest import function_handler


Expand Down
3 changes: 1 addition & 2 deletions tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from aiohttp_sqlalchemy import SABaseView
from aiohttp_sqlalchemy.constants import DEFAULT_KEY
from aiohttp_sqlalchemy import DEFAULT_KEY, SABaseView


def test_sa_session(mocked_request, sa_session):
Expand Down

0 comments on commit 7fe6dc2

Please sign in to comment.