From a0c4eed5bfc058a3692234113e10e34e11826294 Mon Sep 17 00:00:00 2001 From: Vassili Minaev Date: Wed, 19 Mar 2025 06:58:40 -0600 Subject: [PATCH] Fresh cursors! Get your cursors here! --- apps/calendar/app.py | 8 +++----- main.py | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/apps/calendar/app.py b/apps/calendar/app.py index 7a958fa..7d82bab 100644 --- a/apps/calendar/app.py +++ b/apps/calendar/app.py @@ -1,7 +1,6 @@ from aiohttp import web import aiohttp_security import datetime -import aiomysql import security @@ -17,10 +16,9 @@ def datetime_format(postdata): def init_app(app): async def db_query(query, params=()): - cursor = await app['con'].cursor(aiomysql.DictCursor) - await cursor.execute(query, params) - q = cursor.mogrify(query, params) - r = await cursor.fetchall() + await app['dcur'].execute(query, params) + q = app['dcur'].mogrify(query, params) + r = await app['dcur'].fetchall() result = [{k: (str(v) if isinstance(v, datetime.date) or isinstance(v, datetime.timedelta) else v) for k, v in row.items()} for row in r] return (q, result) diff --git a/main.py b/main.py index 98044b7..ba157ea 100644 --- a/main.py +++ b/main.py @@ -22,7 +22,8 @@ async def mysql_engine(app): try: pool = await aiomysql.create_pool(autocommit=True, **app['config']['database']) app['con'] = await pool.acquire() - app['cur'] = await app['con'].cursor() #aiomysql.DictCursor + app['cur'] = await app['con'].cursor() + app['dcur'] = await app['con'].cursor(aiomysql.DictCursor) except OperationalError as e: print(e) print("Done.")