| 5 | |
| 6 | |
| 7 | async def go(): |
| 8 | async with aiopg.create_pool("host=localhost user=htd") as pool: |
| 9 | async with pool.acquire() as conn: |
| 10 | async with conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur: |
| 11 | await cur.execute(helper.MOST_RECOVERED) |
| 12 | rows = await cur.fetchall() |
| 13 | print('most recoveries', dict(rows[0])) |
| 14 | |
| 15 | await cur.execute("BEGIN") # conn.commit() not available |
| 16 | await cur.execute("DELETE FROM month_cases") |
| 17 | await cur.execute(helper.GROUP_BY_MONTH) |
| 18 | ret = [] |
| 19 | async for row in cur: |
| 20 | ret.append(row) |
| 21 | for row in ret: |
| 22 | print(row) |
| 23 | await cur.execute( |
| 24 | '''INSERT INTO month_cases |
| 25 | (mon, new_cases, recovered) |
| 26 | VALUES (%s, %s, %s)''', row) |
| 27 | await cur.execute("COMMIT") # conn.commit() not available |
| 28 | |
| 29 | |
| 30 | if __name__ == '__main__': |