mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-09-06 08:07:22 +08:00
feat(db): add patch for aiosqlite to ensure proper connection handling
This commit is contained in:
@@ -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():
|
async def init_db():
|
||||||
|
patch_aiosqlite_for_tortoise()
|
||||||
await Tortoise.init(config=TORTOISE_ORM)
|
await Tortoise.init(config=TORTOISE_ORM)
|
||||||
await Tortoise.generate_schemas()
|
await Tortoise.generate_schemas()
|
||||||
await runtime_registry.refresh()
|
await runtime_registry.refresh()
|
||||||
|
|||||||
Reference in New Issue
Block a user