Optimize signal read paths and enforce score invariants
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
from collections.abc import AsyncGenerator
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy.dialects.postgresql import insert as postgresql_insert
|
||||
from sqlalchemy.dialects.sqlite import insert as sqlite_insert
|
||||
from sqlalchemy.ext.asyncio import (
|
||||
AsyncSession,
|
||||
async_sessionmaker,
|
||||
@@ -28,6 +31,13 @@ class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
|
||||
def insert_for_session(session: AsyncSession, table: Any) -> Any:
|
||||
"""Build a dialect-native INSERT that supports conflict handling."""
|
||||
if session.get_bind().dialect.name == "postgresql":
|
||||
return postgresql_insert(table)
|
||||
return sqlite_insert(table)
|
||||
|
||||
|
||||
async def get_session() -> AsyncGenerator[AsyncSession, None]:
|
||||
async with async_session_factory() as session:
|
||||
yield session
|
||||
|
||||
Reference in New Issue
Block a user