iShotaBot/models/sqlite.py

26 lines
818 B
Python
Raw Permalink Normal View History

2022-10-06 07:40:03 +00:00
from sqlmodel import SQLModel
from models.models.bilifav import BiliFav
2022-10-06 07:40:03 +00:00
from models.models.lofter import Lofter
from models.models.fragment import Fragment
from models.models.splash import Splash
2022-10-06 07:40:03 +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")
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):
self.session.close_all()