Releases: Vastxiao/asmysql
Releases · Vastxiao/asmysql
v1.0.0
v0.2.0
What's Changed
Features
- Fixed the handling of the
echo
parameter inaiomysql
. - Added the
echo_sql_log
parameter to theAsMysql
class, used to control whetheraiomysql
outputs the executed SQL statements (default is False).
from asmysql import AsMysql
class TestAsMysql(AsMysql):
# This allows controlling whether the executed SQL statements in aiomysql
# are output to Logging.logger.
echo_sql_log = True
# Of course, the `echo_sql_log` parameter can also be passed when instantiating AsMysql.
async def main():
async with TestAsMysql(echo_sql_log=True) as mysql:
result = await mysql.client.execute('select user, authentication_string, host from mysql.user')
if result.err:
print(result.err)
else:
async for item in result.iterate():
print(item)
Features
- 修复aiomysql对echo参数的处理。
- 对AsMysql类新增echo_sql_log参数,用于控制aiomysql是否输出执行的sql语句(默认False)。
from asmysql import AsMysql
class TestAsMysql(AsMysql):
# 这样就可以控制aiomysql库是否在Logging.logger输出执行的sql语句。
echo_sql_log = True
# 当然,echo_sql_log参数也可以在实例化AsMysql时传入。
async def main():
async with TestAsMysql(echo_sql_log=True) as mysql:
result = await mysql.client.execute('select user,authentication_string,host from mysql.user')
if result.err:
print(result.err)
else:
async for item in result.iterate():
print(item)
v0.1.4
Features
1.AsMysql支持异步上下文管理器。
import asyncio
from asmysql import AsMysql
class TestAsMysql(AsMysql):
async def get_users(self):
result = await self.client.execute('select user,authentication_string,host from mysql.user')
if result.err:
print(result.err)
else:
async for item in result.iterate():
print(item)
async def main():
async with TestAsMysql() as mysql:
await mysql.get_users()
if __name__ == '__main__':
asyncio.run(main())