Exemplo n.º 1
0
def get_db():
    db = None
    try:
        db = SessionLocal()
        yield db
    finally:
        db.close()
Exemplo n.º 2
0
def init() -> None:
    try:
        db = SessionLocal()
        # Try to create session to check if DB is awake
        db.execute("SELECT 1")
    except Exception as e:
        logger.error(e)
        raise e
Exemplo n.º 3
0
async def get_number_of_questions(data_dict: {}):
    db: Session = SessionLocal()
    db_room: Room = db.query(Room).filter(
        Room.idRoom == data_dict.get('room_id')).first()
    quantity_questions = len(db_room.test.questions)
    db.close()
    return quantity_questions
Exemplo n.º 4
0
async def save_room_data(res, data_dict: {}):
    db: Session = SessionLocal()
    db_room: Room = db.query(Room).filter(
        Room.idRoom == data_dict.get('room_id')).first()
    db_room.roomData = res
    db.flush()
    db.commit()
    db.close()
Exemplo n.º 5
0
def update_turn_off_room(data_dict: {}):
    db: Session = SessionLocal()
    db_room: Room = db.query(Room).filter(
        Room.idRoom == data_dict.get('room_id')).first()
    db_room.isRunning = False
    db_room.isActive = False
    db.flush()
    db.commit()
    db.close()
Exemplo n.º 6
0
def store_user_contributes(data: Dict) -> None:
    db = SessionLocal()

    try:
        user_contributes = models.UserContributes(**data)
        db.add(user_contributes)
        db.commit()
    except Exception as err:
        logger.error(f"error {err}")
Exemplo n.º 7
0
def get_db() -> Generator:
    try:
        db = SessionLocal()
        yield db
    finally:
        db.close()
Exemplo n.º 8
0
def get_db():
    db = SessionLocal()
    return db
Exemplo n.º 9
0
async def verify_is_room_active(data_dict: {}):
    db: Session = SessionLocal()
    db_room: Room = db.query(Room).filter(
        Room.idRoom == data_dict.get('room_id')).first()
    return db_room.isActive
Exemplo n.º 10
0
from sqlalchemy.orm import Session

from app import crud, schemas
from app.config import settings
from app.db import base  # noqa: F401
from app.db.database import Base, SessionLocal, engine  # noqa


def init_db(db: Session) -> None:
    # Base.metadata.create_all(bind=engine)

    user = crud.user.get_by_username(db, username=settings.SUPERUSER_USERNAME)
    if not user:
        user_in = schemas.UserCreate(
            username=settings.SUPERUSER_USERNAME,
            password=settings.SUPERUSER_PASSWORD,
            is_superuser=True,
        )
        crud.user.create(db, user_in)


if __name__ == "__main__":
    init_db(SessionLocal())
Exemplo n.º 11
0
def init() -> None:
    db = SessionLocal()
    init_db(db)
Exemplo n.º 12
0
from app.db.database import SessionLocal
from app.db.models import UserContributes
from sqlalchemy import func
from sqlalchemy_filters import apply_filters

db = SessionLocal()


async def get_user_list():
    return db.query(UserContributes.user.distinct()).all()


async def topics_by_user(username: str):
    res = db.query(
        UserContributes.user,
        UserContributes.title,
        func.count(UserContributes.id_sk)
    ).filter(
        UserContributes.user.ilike(f'%{username}%')
    ).group_by(
        UserContributes.user,
        UserContributes.title
    ).order_by(
        func.count(UserContributes.id_sk).desc()
    ).all()

    return res


async def get_most_active_user(year: int = None, month: int = None, day=None):
    query_params = {