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
|
from aiohttp import web
|
||||||
import aiohttp_security
|
import aiohttp_security
|
||||||
import datetime
|
import datetime
|
||||||
import aiomysql
|
|
||||||
|
|
||||||
import security
|
import security
|
||||||
|
|
||||||
|
|
@ -17,10 +16,9 @@ def datetime_format(postdata):
|
||||||
|
|
||||||
def init_app(app):
|
def init_app(app):
|
||||||
async def db_query(query, params=()):
|
async def db_query(query, params=()):
|
||||||
cursor = await app['con'].cursor(aiomysql.DictCursor)
|
await app['dcur'].execute(query, params)
|
||||||
await cursor.execute(query, params)
|
q = app['dcur'].mogrify(query, params)
|
||||||
q = cursor.mogrify(query, params)
|
r = await app['dcur'].fetchall()
|
||||||
r = await cursor.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]
|
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)
|
return (q, result)
|
||||||
|
|
||||||
|
|
|
||||||
3
main.py
3
main.py
|
|
@ -22,7 +22,8 @@ async def mysql_engine(app):
|
||||||
try:
|
try:
|
||||||
pool = await aiomysql.create_pool(autocommit=True, **app['config']['database'])
|
pool = await aiomysql.create_pool(autocommit=True, **app['config']['database'])
|
||||||
app['con'] = await pool.acquire()
|
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:
|
except OperationalError as e:
|
||||||
print(e)
|
print(e)
|
||||||
print("Done.")
|
print("Done.")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue