Ejemplo n.º 1
0
from sqlalchemy import and_

from models.database import DATABASE_NAME, Session
import create_database as db_creator
from models.lesson import Lesson, association_table
from models.student import Student
from models.group import Group

if __name__ == '__main__':
    db_is_created = os.path.exists(DATABASE_NAME)
    if not db_is_created:
        db_creator.create_database()

    session = Session()
    for it in session.query(Lesson):
        print(it)
    print('*' * 30)
    for it in session.query(Lesson).filter(Lesson.id > 3):
        print(it)
    print('*' * 30)
    for it in session.query(Lesson).filter(
            and_(Lesson.id >= 3, Lesson.lesson_title.like('Ф%'))):
        print(it)
    print('*' * 30)
    for it in session.query(Student).join(Group).filter(
            Group.group_name == '1-МДА-9'):
        print(it)
    print('*' * 30)
    for it, gr in session.query(Student, Group):
        print(it, gr)
Ejemplo n.º 2
0
def get_department(id: str):
    session = Session()
    dep_out = session.query(Department).filter(Department.id == id).first()
    return dep_out
Ejemplo n.º 3
0
def get_department_objects(id: str):
    session = Session()
    obj_out = session.query(Object).join(Department).filter(
        Department.id == id).all()
    obj_list = schemas.ObjectList(objects=obj_out)
    return obj_list
Ejemplo n.º 4
0
def get_departments():
    session = Session()
    dep_out = session.query(Department).all()
    dep_list = schemas.DepartmentList(departments=dep_out)
    return dep_list