|
12 | 12 | from functools import wraps |
13 | 13 | from typing import Any, Concatenate, Optional, ParamSpec, TypeVar, cast |
14 | 14 |
|
15 | | -from sqlalchemy import NullPool, create_engine, delete, select |
16 | | -from sqlalchemy.ext.asyncio import AsyncSession |
17 | | -from sqlalchemy.orm import Session, selectinload, sessionmaker |
| 15 | +from sqlalchemy import NullPool, delete, select |
| 16 | +from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine |
| 17 | +from sqlalchemy.orm import selectinload |
18 | 18 | from sqlalchemy.sql import Select, and_, not_, or_ |
19 | 19 | from sqlalchemy.sql.expression import false, true |
20 | 20 |
|
@@ -147,17 +147,16 @@ async def decorated_function(self: Any, *args: _P.args, **kwargs: _P.kwargs) -> |
147 | 147 | class ResourcePoolRepository(_Base): |
148 | 148 | """The adapter used for accessing resource pools with SQLAlchemy.""" |
149 | 149 |
|
150 | | - def initialize(self, sync_connection_url: str, rp: models.ResourcePool) -> None: |
| 150 | + async def initialize(self, async_connection_url: str, rp: models.ResourcePool) -> None: |
151 | 151 | """Add the default resource pool if it does not already exist.""" |
152 | | - engine = create_engine(sync_connection_url, poolclass=NullPool) |
153 | | - session_maker = sessionmaker( |
| 152 | + engine = create_async_engine(async_connection_url, poolclass=NullPool) |
| 153 | + session_maker = async_sessionmaker( |
154 | 154 | engine, |
155 | | - class_=Session, |
156 | 155 | expire_on_commit=True, |
157 | 156 | ) |
158 | | - with session_maker() as session, session.begin(): |
| 157 | + async with session_maker() as session, session.begin(): |
159 | 158 | stmt = select(schemas.ResourcePoolORM.default == true()) |
160 | | - res = session.execute(stmt) |
| 159 | + res = await session.execute(stmt) |
161 | 160 | default_rp = res.scalars().first() |
162 | 161 | if default_rp is None: |
163 | 162 | orm = schemas.ResourcePoolORM.load(rp) |
|
0 commit comments