Skip to content

Commit

Permalink
Merge branch 'release/0.8.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ri-gilfanov committed Jun 7, 2021
2 parents 2cb6860 + 5219ea4 commit 1a460d0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
21 changes: 13 additions & 8 deletions aiohttp_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession
from sqlalchemy.orm import sessionmaker
from typing import TYPE_CHECKING
import warnings

from aiohttp_sqlalchemy.constants import DEFAULT_KEY
from aiohttp_sqlalchemy.decorators import sa_decorator
Expand All @@ -14,25 +15,29 @@
from typing import Callable, Iterable, Union, Tuple

TSessionFactory = Callable[..., AsyncSession]
TEngineOrFactory = Union[AsyncEngine, TSessionFactory]
TSABinding = Tuple[TSessionFactory, str, bool]


__version__ = '0.7.0'
__version__ = '0.8.0'

__all__ = ['DuplicateAppKeyError', 'DuplicateRequestKeyError', 'SABaseView',
'sa_bind', 'sa_decorator', 'sa_middleware', 'SAView', 'setup',]


def sa_bind(
arg: 'TEngineOrFactory', key: str = DEFAULT_KEY, *,
middleware: bool = True) -> 'TSABinding':
def sa_bind(factory: 'TSessionFactory', key: str = DEFAULT_KEY, *,
middleware: bool = True) -> 'TSABinding':
""" Session factory wrapper for binding in setup function. """

if isinstance(arg, AsyncEngine):
arg = sessionmaker(arg, AsyncSession)
if isinstance(factory, AsyncEngine):
msg = (
"`AsyncEngine` type is deprecated in `sa_bind()` signature. "
"Use `sessionmaker(engine, AsyncSession)` or custom session "
"factory returning `AsyncSession` instance."
)
warnings.warn(msg, stacklevel=2)
factory = sessionmaker(factory, AsyncSession)

return arg, key, middleware
return factory, key, middleware


def setup(app: 'Application', bindings: 'Iterable[TSABinding]'):
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.7.0'
release = '0.8.0'


# -- General configuration ---------------------------------------------------
Expand Down
17 changes: 15 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,25 @@ Nested apps
Change log
----------
Version 0.8.0
^^^^^^^^^^^^^
Changed
"""""""
Rename first argument from ``arg`` to ``factory`` in ``sa_bind()`` signature.

Deprecated
""""""""""
``AsyncEngine`` type is deprecated in ``sa_bind()`` signature. Use
``sessionmaker(engine, AsyncSession)`` or custom session factory returning
``AsyncSession`` instance.

Version 0.7.0
^^^^^^^^^^^^^
Changed
"""""""
Usage ``sqlalchemy.orm.sessionmaker`` object is recomended as a first argument
of ``aiohttp_sqlalchemy.sa_bind()``. See examples on documetation.
Usage ``sqlalchemy.orm.sessionmaker`` instance is recomended as a first
argument for ``aiohttp_sqlalchemy.sa_bind()`` signature. See examples
in documetation.

Removed
"""""""
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aiohttp-sqlalchemy"
version = "0.7.0"
version = "0.8.0"
description = "SQLAlchemy 1.4 / 2.0 support for aiohttp."
authors = [
"Ruslan Ilyasovich Gilfanov <ri.gilfanov@yandex.ru>",
Expand All @@ -15,11 +15,12 @@ classifiers = [
"Topic :: Internet",
"Topic :: Internet :: WWW/HTTP",
]
documentation = "https://aiohttp-sqlalchemy.readthedocs.io/"
homepage = "https://github.com/ri-gilfanov/aiohttp-sqlalchemy"
keywords = ["aiohttp", "sqlalchemy"]
license = "BSD-3-Clause"
readme = "README.rst"

documentation = "https://aiohttp-sqlalchemy.readthedocs.io/"
homepage = "https://github.com/ri-gilfanov/aiohttp-sqlalchemy"
repository = "https://github.com/ri-gilfanov/aiohttp-sqlalchemy"

[tool.poetry.dependencies]
Expand Down
16 changes: 9 additions & 7 deletions tests/test_aiohttp_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,31 @@
import aiohttp_sqlalchemy
from aiohttp_sqlalchemy import sa_bind
import pytest
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker
from aiohttp_sqlalchemy.exceptions import DuplicateAppKeyError, DuplicateRequestKeyError


def test_aiohttp_sqlalchemy_setup():
engine = create_async_engine('sqlite+aiosqlite:///')
Session = sessionmaker(engine, AsyncSession)

app = web.Application()
with pytest.raises(DuplicateAppKeyError):
aiohttp_sqlalchemy.setup(app, [
sa_bind(engine),
sa_bind(engine),
sa_bind(Session),
sa_bind(Session),
])

app = web.Application()
with pytest.raises(DuplicateAppKeyError):
aiohttp_sqlalchemy.setup(app, [
sa_bind(engine, 'sa_secondary'),
sa_bind(engine, 'sa_secondary'),
sa_bind(Session, 'sa_secondary'),
sa_bind(Session, 'sa_secondary'),
])

app = web.Application()
aiohttp_sqlalchemy.setup(app, [
sa_bind(engine),
sa_bind(engine, 'sa_secondary'),
sa_bind(Session),
sa_bind(Session, 'sa_secondary'),
])

0 comments on commit 1a460d0

Please sign in to comment.