feat(db): add patch for aiosqlite to ensure proper connection handling

This commit is contained in:
shiyu
2025-12-23 09:53:31 +08:00
parent adb80d0a6c
commit e7e34cda54

View File

@@ -13,7 +13,21 @@ TORTOISE_ORM = {
}
def patch_aiosqlite_for_tortoise() -> None:
import aiosqlite
if hasattr(aiosqlite.Connection, "start"):
return
def start(self) -> None: # type: ignore[no-redef]
if not self._thread.is_alive():
self._thread.start()
aiosqlite.Connection.start = start # type: ignore[attr-defined]
async def init_db():
patch_aiosqlite_for_tortoise()
await Tortoise.init(config=TORTOISE_ORM)
await Tortoise.generate_schemas()
await runtime_registry.refresh()