def get_exists_data( TIPE : str , TABLE : str , KEY : str , VAL : str ): db = get_db() result = db.execute('SELECT {0} FROM {1} WHERE {2} = ?'.format(TIPE,TABLE,KEY),VAL).fetchone() return result
class Meta: database = get_db()
def get_edit_query( TABLE : str , COLUMN : str , ID : str , VAL : str ): db = get_db() db.execute('UPDATE {0} SET {1} WHERE {2} = ?'.format(TABLE,COLUMN,ID),VAL) db.commit()
def get_delete_query( TABLE : str , VAL : str ): db = get_db() db.execute('DELETE FROM {0} WHERE id = ?'.format(TABLE), VAL) db.commit()
def get_new_query( TABLECOLUMN : str , QUANTITY : str , VAL : str ): db = get_db() db.execute('INSERT INTO {0} VALUES {1}'.format(TABLECOLUMN, QUANTITY),VAL) db.commit()
def get_query( TYPE : str , TABLE : str , ORDER : str ): db = get_db() rows = db.execute('SELECT {0} FROM {1} ORDER BY {2}'.format(TYPE,TABLE,ORDER)).fetchall() return rows
def reset_database(): with get_db(): migrator.reset_tables()
from jose import JWTError, jwt from datetime import timedelta from typing import Dict, List from models.users import User from schemas.users import UserCreate, UserORM, UserBase from schemas.tokens import TokenData from schemas.words import Choices from core.services import UserService, auth_service, EmailService from core.database import get_db from core.authentication import AuthWithCookie from utils.handlers import text_handler from utils.settings import token_config router = APIRouter() auth_scheme = AuthWithCookie(tokenUrl='/token') user_service = UserService(database=get_db()) email_service = EmailService() async def get_current_user(token: str = Depends(auth_scheme), database: Session = Security(get_db)) -> User: """ [Current User | Depend] Info: Функция-зависимость. Не авторизованный пользователь не имеет доступа к некоторым страницам благодаря этой функции. Raises: HTTPException: Райзится при ошибке авторизации. Возвращает и хедеры.
async def initialize_database(): init_db() with get_db(): migrator.run()