remove databases, use SQLAlechemy 2.0 instead

Among the many changes we switch to using SQLAlchemy's connection pool,
which means we are no longer required to guard against multiple threads
working on the database.
All db funcs now receive a connection to use as their first argument,
this allows the caller to control transaction & rollback behavior.
This commit is contained in:
ducklet 2023-11-27 23:24:35 +01:00
parent c63bee072f
commit 4981de4a04
12 changed files with 876 additions and 765 deletions

View file

@ -17,16 +17,19 @@ def event_loop():
@pytest_asyncio.fixture(scope="session")
async def shared_conn():
c = db._shared_connection()
await c.connect()
"""A database connection, ready to use."""
await db.open_connection_pool()
await db.apply_db_patches(c)
yield c
async with db.new_connection() as c:
db._test_connection = c
yield c
db._test_connection = None
await c.disconnect()
await db.close_connection_pool()
@pytest_asyncio.fixture
async def conn(shared_conn):
async with shared_conn.transaction(force_rollback=True):
async def conn(shared_conn: db.Connection):
"""A transacted database connection, will be rolled back after use."""
async with db.transacted(shared_conn, force_rollback=True):
yield shared_conn