2022-10-06 07:40:03 +00:00
|
|
|
from sqlmodel import SQLModel
|
|
|
|
|
2023-08-18 13:28:16 +00:00
|
|
|
from models.models.bilifav import BiliFav
|
2022-10-06 07:40:03 +00:00
|
|
|
from models.models.lofter import Lofter
|
2022-11-04 15:54:19 +00:00
|
|
|
from models.models.fragment import Fragment
|
2023-08-18 13:28:16 +00:00
|
|
|
from models.models.splash import Splash
|
2022-10-06 07:40:03 +00:00
|
|
|
|
2023-08-18 13:28:16 +00:00
|
|
|
__all__ = ["BiliFav", "Lofter", "Fragment", "Splash", "Sqlite"]
|
2022-10-06 07:40:03 +00:00
|
|
|
|
|
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
|
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
from sqlmodel.ext.asyncio.session import AsyncSession
|
|
|
|
|
|
|
|
|
|
|
|
class Sqlite:
|
|
|
|
def __init__(self):
|
|
|
|
self.engine = create_async_engine("sqlite+aiosqlite:///data/data.db")
|
2023-08-18 13:28:16 +00:00
|
|
|
self.session = sessionmaker(bind=self.engine, class_=AsyncSession)
|
2022-10-06 07:40:03 +00:00
|
|
|
|
|
|
|
async def create_db_and_tables(self):
|
|
|
|
async with self.engine.begin() as session:
|
|
|
|
await session.run_sync(SQLModel.metadata.create_all)
|
|
|
|
|
|
|
|
def stop(self):
|
2023-08-18 13:28:16 +00:00
|
|
|
self.session.close_all()
|