|
| 1 | +import aiomysql |
| 2 | + |
| 3 | +# Only a cursor can execute sql. |
| 4 | +async def test_cursor(): |
| 5 | + # Create connection directly |
| 6 | + conn = await aiomysql.connect() |
| 7 | + cur = await conn.cursor() |
| 8 | + await cur.execute("sql") # $ MISSING: getSql="sql" constructedSql="sql" |
| 9 | + |
| 10 | + # Create connection via pool |
| 11 | + async with aiomysql.create_pool() as pool: |
| 12 | + # Create Cursor via Connection |
| 13 | + async with pool.acquire() as conn: |
| 14 | + async with conn.cursor() as cur: |
| 15 | + await cur.execute("sql") # $ MISSING: getSql="sql" constructedSql="sql" |
| 16 | + |
| 17 | + # Create Cursor directly |
| 18 | + async with pool.cursor() as cur: |
| 19 | + await cur.execute("sql") # $ MISSING: getSql="sql" constructedSql="sql" |
| 20 | + |
| 21 | + # variants using as few `async with` as possible |
| 22 | + pool = await aiomysql.create_pool() |
| 23 | + conn = await pool.acquire() |
| 24 | + cur = await conn.cursor() |
| 25 | + await cur.execute("sql") # $ MISSING: getSql="sql" constructedSql="sql" |
| 26 | + |
| 27 | +# Test SQLAlchemy integration |
| 28 | +from aiomysql.sa import create_engine |
| 29 | + |
| 30 | +async def test_engine(): |
| 31 | + engine = await create_engine() |
| 32 | + conn = await engine.acquire() |
| 33 | + await conn.execute("sql") # $ MISSING: getSql="sql" constructedSql="sql" |
0 commit comments