mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-07-09 22:41:44 +08:00
Initial commit
This commit is contained in:
3
db/__init__.py
Normal file
3
db/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .session import init_db, close_db
|
||||
|
||||
__all__ = ["init_db", "close_db"]
|
||||
22
db/session.py
Normal file
22
db/session.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from tortoise import Tortoise
|
||||
|
||||
from domain.adapters import runtime_registry
|
||||
|
||||
TORTOISE_ORM = {
|
||||
"connections": {"default": "sqlite://data/db/db.sqlite3"},
|
||||
"apps": {
|
||||
"models": {
|
||||
"models": ["models.database"],
|
||||
"default_connection": "default",
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
async def init_db():
|
||||
await Tortoise.init(config=TORTOISE_ORM)
|
||||
await Tortoise.generate_schemas()
|
||||
await runtime_registry.refresh()
|
||||
|
||||
|
||||
async def close_db():
|
||||
await Tortoise.close_connections()
|
||||
Reference in New Issue
Block a user