MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / asyncio

Function asyncio

test/typing/plain_files/ext/asyncio/engines.py:22–95  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20
21
22async def asyncio() -> None:
23 e = create_async_engine("sqlite://")
24
25 assert_type(e, AsyncEngine)
26
27 async with e.connect() as conn:
28 assert_type(conn, AsyncConnection)
29
30 result = await conn.execute(text("select * from table"))
31
32 assert_type(result, CursorResult[Unpack[tuple[Any, ...]]])
33
34 # stream with direct await
35 async_result = await conn.stream(text("select * from table"))
36
37 assert_type(async_result, AsyncResult[Unpack[tuple[Any, ...]]])
38
39 # stream with context manager
40 async with conn.stream(
41 text("select * from table")
42 ) as ctx_async_result:
43 assert_type(ctx_async_result, AsyncResult[Unpack[tuple[Any, ...]]])
44
45 # stream_scalars with direct await
46 async_scalar_result = await conn.stream_scalars(
47 text("select * from table")
48 )
49
50 assert_type(async_scalar_result, AsyncScalarResult[Any])
51
52 # stream_scalars with context manager
53 async with conn.stream_scalars(
54 text("select * from table")
55 ) as ctx_async_scalar_result:
56 assert_type(ctx_async_scalar_result, AsyncScalarResult[Any])
57
58 async with e.begin() as conn:
59 assert_type(conn, AsyncConnection)
60
61 result = await conn.execute(text("select * from table"))
62
63 assert_type(result, CursorResult[Unpack[tuple[Any, ...]]])
64
65 await conn.run_sync(work_sync, 1)
66
67 # EXPECTED_MYPY: Missing positional argument "foo" in call to "run_sync" of "AsyncConnection"
68 await conn.run_sync(work_sync)
69
70 ce = select(1).compile(e)
71 ce.statement
72 cc = select(1).compile(conn)
73 cc.statement
74
75 async with e.connect() as conn:
76 metadata = MetaData()
77
78 await conn.run_sync(metadata.create_all)
79 await conn.run_sync(metadata.reflect)

Callers

nothing calls this directly

Calls 13

create_async_engineFunction · 0.90
textFunction · 0.90
selectFunction · 0.90
MetaDataClass · 0.90
EnumClass · 0.90
connectMethod · 0.45
executeMethod · 0.45
streamMethod · 0.45
stream_scalarsMethod · 0.45
beginMethod · 0.45
run_syncMethod · 0.45
compileMethod · 0.45

Tested by

no test coverage detected