Skip to content

Instantly share code, notes, and snippets.

@Glukhoff
Created October 21, 2022 10:36
Show Gist options
  • Save Glukhoff/12b33bf4bccb00a73ea735e09dbbb781 to your computer and use it in GitHub Desktop.
Save Glukhoff/12b33bf4bccb00a73ea735e09dbbb781 to your computer and use it in GitHub Desktop.
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker, declarative_base
Base = declarative_base()
def create_poll(user: str, password: str, host: str, name: str) -> sessionmaker:
engine = create_async_engine(
f"postgresql+asyncpg://{user}:{password}@{host}/{name}",
future=True
)
return sessionmaker(engine, expire_on_commit=False, class_=AsyncSession)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment