MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / run_out_of_band

Function run_out_of_band

examples/asyncio/gather_orm_statements.py:46–63  ·  view source on GitHub ↗

run an ORM statement in a distinct session, returning the frozen results

(async_sessionmaker, statement, merge_results=True)

Source from the content-addressed store, hash-verified

44
45
46async 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
66async def async_main():

Callers 1

async_mainFunction · 0.85

Calls 5

async_sessionmakerClass · 0.90
connectionMethod · 0.45
executeMethod · 0.45
freezeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected