Get an async sqlmodel session to interact with the database. async with rx.asession() as asession: ... Most operations against the `asession` must be awaited. Args: url: The database url. Returns: An async database session.
(url: str | None = None)
| 689 | return sqlmodel.Session(get_engine(url)) |
| 690 | |
| 691 | def asession(url: str | None = None) -> AsyncSession: |
| 692 | """Get an async sqlmodel session to interact with the database. |
| 693 | |
| 694 | async with rx.asession() as asession: |
| 695 | ... |
| 696 | |
| 697 | Most operations against the `asession` must be awaited. |
| 698 | |
| 699 | Args: |
| 700 | url: The database url. |
| 701 | |
| 702 | Returns: |
| 703 | An async database session. |
| 704 | """ |
| 705 | global _AsyncSessionLocal |
| 706 | if url not in _AsyncSessionLocal: |
| 707 | _AsyncSessionLocal[url] = sqlalchemy.ext.asyncio.async_sessionmaker( |
| 708 | bind=get_async_engine(url), |
| 709 | class_=AsyncSession, |
| 710 | expire_on_commit=False, |
| 711 | autocommit=False, |
| 712 | autoflush=False, |
| 713 | ) |
| 714 | return _AsyncSessionLocal[url]() |
| 715 | |
| 716 | else: |
| 717 | get_db_status = _print_db_not_available |
nothing calls this directly
no test coverage detected