-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #746 from Kwaizer/bs_203_sqla_v2
Migrate Sqlalcehmy to the v2
- Loading branch information
Showing
4 changed files
with
1,010 additions
and
607 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
# -*- mode:python; coding:utf-8; -*- | ||
# author: Vyacheslav Potoropin <[email protected]> | ||
# created: 2021-06-22 | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import scoped_session, sessionmaker | ||
from sqlalchemy import MetaData, create_engine | ||
from sqlalchemy.ext.asyncio import ( | ||
AsyncAttrs, | ||
AsyncSession, | ||
create_async_engine, | ||
) | ||
from sqlalchemy.orm import DeclarativeBase, scoped_session, sessionmaker | ||
from sqlalchemy.pool import NullPool | ||
|
||
from alws.config import settings | ||
|
@@ -18,12 +21,22 @@ | |
sync_engine = create_engine( | ||
settings.sync_database_url, pool_pre_ping=True, pool_recycle=3600 | ||
) | ||
Base = declarative_base() | ||
|
||
|
||
class Base(AsyncAttrs, DeclarativeBase): | ||
__allow_unmapped__ = True | ||
metadata = MetaData() | ||
|
||
|
||
sync_session_factory = sessionmaker(sync_engine, expire_on_commit=False) | ||
Session = sessionmaker(engine, expire_on_commit=False, class_=AsyncSession) | ||
SyncSession = scoped_session(sync_session_factory) | ||
|
||
PulpBase = declarative_base() | ||
|
||
class PulpBase(AsyncAttrs, DeclarativeBase): | ||
__allow_unmapped__ = True | ||
|
||
|
||
pulp_engine = create_engine( | ||
settings.pulp_database_url, pool_pre_ping=True, pool_recycle=3600 | ||
) | ||
|
Oops, something went wrong.
2e54521
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage report for changed files •