run an ORM statement in a distinct session, returning the frozen results
(async_sessionmaker, statement, merge_results=True)
| 44 | |
| 45 | |
| 46 | async def run_out_of_band(async_sessionmaker, statement, merge_results=True): |
| 47 | """run an ORM statement in a distinct session, |
| 48 | returning the frozen results |
| 49 | """ |
| 50 | |
| 51 | async with async_sessionmaker() as oob_session: |
| 52 | # use AUTOCOMMIT for each connection to reduce transaction |
| 53 | # overhead / contention |
| 54 | await oob_session.connection( |
| 55 | execution_options={"isolation_level": "AUTOCOMMIT"} |
| 56 | ) |
| 57 | |
| 58 | result = await oob_session.execute(statement) |
| 59 | |
| 60 | if merge_results: |
| 61 | return result.freeze() |
| 62 | else: |
| 63 | await result.close() |
| 64 | |
| 65 | |
| 66 | async def async_main(): |
no test coverage detected