from typing import Optional from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column from sqlalchemy import Column, DateTime from sqlalchemy.sql import func from datetime import datetime engine = create_async_engine("sqlite+aiosqlite:///questions.db") new_session = async_sessionmaker(engine, expire_on_commit=False) class Model(DeclarativeBase): pass class QuestionOrm(Model): __tablename__ = "questions" id: Mapped[int] = mapped_column(primary_key=True) email_user: Mapped[str] type_question: Mapped[bool] question: Mapped[str] answer: Mapped[Optional[str]] question_time: Mapped[datetime] = mapped_column(DateTime, server_default=func.now()) async def create_tables(): async with engine.begin() as conn: await conn.run_sync(Model.metadata.create_all) async def delete_tables(): async with engine.begin() as conn: await conn.run_sync(Model.metadata.drop_all)