Fresh cursors! Get your cursors here!
This commit is contained in:
parent
6c30537db1
commit
a0c4eed5bf
2 changed files with 5 additions and 6 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
3
main.py
3
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.")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue