diff --git a/app/common/db.py b/app/common/db.py index 4b9307b..fea6634 100644 --- a/app/common/db.py +++ b/app/common/db.py @@ -15,23 +15,30 @@ async def get_pool() -> aiomysql.Pool: user=get_env("MYSQL_USER"), password=get_env("MYSQL_PASSWORD"), db=get_env("MYSQL_DB"), - autocommit=True, charset="utf8mb4", + minsize=0, + maxsize=30, + connect_timeout=10, ) return _pool +# 쓰기 (INSERT/UPDATE/DELETE) async def execute(sql: str, args: tuple = ()) -> int: pool = await get_pool() async with pool.acquire() as conn: + await conn.ping(reconnect=True) async with conn.cursor() as cur: await cur.execute(sql, args) + await conn.commit() return cur.lastrowid +# 읽기 (SELECT) async def fetchone(sql: str, args: tuple = ()) -> dict | None: pool = await get_pool() async with pool.acquire() as conn: + await conn.ping(reconnect=True) async with conn.cursor(aiomysql.DictCursor) as cur: await cur.execute(sql, args) return await cur.fetchone()