|
| 1 | +import asyncio |
| 2 | +import asyncpg |
| 3 | + |
| 4 | +async def test_connection(): |
| 5 | + conn = await asyncpg.connect() |
| 6 | + |
| 7 | + try: |
| 8 | + await conn.copy_from_query("sql", output="filepath") # $ MISSING: getSql="sql" getAPathArgument="filepath" |
| 9 | + await conn.execute("sql") # $ MISSING: getSql="sql" |
| 10 | + await conn.executemany("sql") # $ MISSING: getSql="sql" |
| 11 | + await conn.fetch("sql") # $ MISSING: getSql="sql" |
| 12 | + await conn.fetchrow("sql") # $ MISSING: getSql="sql" |
| 13 | + await conn.fetchval("sql") # $ MISSING: getSql="sql" |
| 14 | + |
| 15 | + finally: |
| 16 | + await conn.close() |
| 17 | + |
| 18 | + |
| 19 | +async def test_prepared_statement(): |
| 20 | + conn = await asyncpg.connect() |
| 21 | + |
| 22 | + try: |
| 23 | + pstmt = await conn.prepare('psql') |
| 24 | + pstmt.executemany() # $ MISSING: getSql="psql" |
| 25 | + pstmt.fetch() # $ MISSING: getSql="psql" |
| 26 | + pstmt.fetchrow() # $ MISSING: getSql="psql" |
| 27 | + pstmt.fetchval() # $ MISSING: getSql="psql" |
| 28 | + |
| 29 | + finally: |
| 30 | + await conn.close() |
| 31 | + |
| 32 | +# The sql statement is executed when the `CursorFactory` (obtained by e.g. `conn.cursor()`) is awaited. |
| 33 | +# See https://magicstack.github.io/asyncpg/current/api/index.html#asyncpg.cursor.CursorFactory |
| 34 | +async def test_cursor(): |
| 35 | + conn = await asyncpg.connect() |
| 36 | + |
| 37 | + try: |
| 38 | + async with conn.transaction(): |
| 39 | + cursor = await conn.cursor("sql") # $ MISSING: getSql="sql" |
| 40 | + await cursor.fetch() |
| 41 | + |
| 42 | + pstmt = await conn.prepare('psql') |
| 43 | + pcursor = await pstmt.cursor() # $ MISSING: getSql="psql" |
| 44 | + await pcursor.fetch() |
| 45 | + |
| 46 | + async for record in conn.cursor("sql"): # $ MISSING: getSql="sql" |
| 47 | + pass |
| 48 | + |
| 49 | + async for record in pstmt.cursor(): # $ MISSING: getSql="psql" |
| 50 | + pass |
| 51 | + |
| 52 | + cursor_factory = conn.cursor("sql") |
| 53 | + cursor = await cursor_factory # $ MISSING: getSql="sql" |
| 54 | + |
| 55 | + pcursor_factory = pstmt.cursor() |
| 56 | + pcursor = await pcursor_factory # $ MISSING: getSql="psql" |
| 57 | + |
| 58 | + finally: |
| 59 | + await conn.close() |
| 60 | + |
| 61 | +async def test_connection_pool(): |
| 62 | + pool = await asyncpg.create_pool() |
| 63 | + |
| 64 | + try: |
| 65 | + await pool.copy_from_query("sql", output="filepath") # $ MISSING: getSql="sql" getAPathArgument="filepath" |
| 66 | + await pool.execute("sql") # $ MISSING: getSql="sql" |
| 67 | + await pool.executemany("sql") # $ MISSING: getSql="sql" |
| 68 | + await pool.fetch("sql") # $ MISSING: getSql="sql" |
| 69 | + await pool.fetchrow("sql") # $ MISSING: getSql="sql" |
| 70 | + await pool.fetchval("sql") # $ MISSING: getSql="sql" |
| 71 | + |
| 72 | + async with pool.acquire() as conn: |
| 73 | + await conn.execute("sql") # $ MISSING: getSql="sql" |
| 74 | + |
| 75 | + conn = await pool.acquire() |
| 76 | + try: |
| 77 | + await conn.fetch("sql") # $ MISSING: getSql="sql" |
| 78 | + finally: |
| 79 | + await pool.release(conn) |
| 80 | + |
| 81 | + finally: |
| 82 | + await pool.close() |
| 83 | + |
| 84 | + async with asyncpg.create_pool() as pool: |
| 85 | + await pool.execute("sql") # $ MISSING: getSql="sql" |
| 86 | + |
| 87 | + async with pool.acquire() as conn: |
| 88 | + await conn.execute("sql") # $ MISSING: getSql="sql" |
| 89 | + |
| 90 | + conn = await pool.acquire() |
| 91 | + try: |
| 92 | + await conn.fetch("sql") # $ MISSING: getSql="sql" |
| 93 | + finally: |
| 94 | + await pool.release(conn) |
0 commit comments