mirror of
https://github.com/Xtao-Labs/iShotaBot.git
synced 2024-11-25 01:29:45 +00:00
28 lines
821 B
Python
28 lines
821 B
Python
from sqlmodel import SQLModel
|
|
|
|
from models.models.lofter import Lofter
|
|
from models.models.fragment import Fragment
|
|
|
|
__all__ = ["Lofter", "Fragment", "Sqlite"]
|
|
|
|
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)
|
|
|
|
async def create_db_and_tables(self):
|
|
async with self.engine.begin() as session:
|
|
await session.run_sync(SQLModel.metadata.create_all)
|
|
|
|
async def get_session(self):
|
|
async with self.Session() as session:
|
|
yield session
|
|
|
|
def stop(self):
|
|
self.Session.close_all()
|