я только начал изучать mysql, а точнее aiomysql, но, как я понял они почти одинаковые за исключением асинхронности
когда я запустил этот код:
(main.py)
import db
loop = db.loop
loop.run_until_complete(db.create())
loop.run_until_complete(db.set('о', 'i'))
(db.py)
import asyncio
import aiomysql
from config_reader import config
loop = asyncio.get_event_loop()
async def create():
conn = await aiomysql.connect(host=config.mysql_host.get_secret_value(),
user=config.mysql_user.get_secret_value(),
password=config.mysql_password.get_secret_value(),
db=config.mysql_db_name.get_secret_value(),
loop=loop)
async with conn.cursor() as cur:
await cur.execute("""CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT,
description TEXT,
icon TEXT,
PRIMARY KEY (id))""")
await conn.commit()
conn.close()
async def get(column, what, is_what):
conn = await aiomysql.connect(host=config.mysql_host.get_secret_value(),
user=config.mysql_user.get_secret_value(),
password=config.mysql_password.get_secret_value(),
db=config.mysql_db_name.get_secret_value(),
loop=loop)
async with conn.cursor() as cur:
await cur.execute(f"SELECT {column} FROM users WHERE {what} = {is_what}")
await conn.commit()
conn.close()
async def set(d, i):
conn = await aiomysql.connect(host=config.mysql_host.get_secret_value(),
user=config.mysql_user.get_secret_value(),
password=config.mysql_password.get_secret_value(),
db=config.mysql_db_name.get_secret_value(),
loop=loop)
async with conn.cursor() as cur:
await cur.execute(f"INSERT INTO users (description, icon) VALUES (?, ?)", (d, i))
await conn.commit()
conn.close()
произошла ошибка:
Traceback (most recent call last):
File "D:\MBOT\liinkyy\t.py", line 4, in <module>
loop.run_until_complete(db.set('о', 'i'))
File "C:\Users\Alex\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 647, in run_until_complete
return future.result()
File "D:\MBOT\liinkyy\db\db.py", line 49, in set
await cur.execute(f"INSERT INTO users (id, description, icon) VALUES (?, ?, ?)", (1, d, i))
File "D:\MBOT\liinkyy\.venv\lib\site-packages\aiomysql\cursors.py", line 237, in execute
query = query % self._escape_args(args, conn)
TypeError: not all arguments converted during string formatting