def get_all_stations(load_only_tuple=None):
     if load_only_tuple == None:
         request = db_session.query(Station).all()
     else:
         request = db_session.query(Station).options(
             load_only(*(load_only_tuple))).all()
     return request
 def get_schedule_by_id(schedule_id, load_only_tuple=None):
     if load_only_tuple == None:
         query = db_session.query(Schedule)
     else:
         query = db_session.query(Schedule).options(
             load_only(*(load_only_tuple)))
     bus_request = query.filter(Schedule.id == schedule_id).one()
     return bus_request
 def get_station_by_id(station_id, load_only_tuple=None):
     if load_only_tuple == None:
         query = db_session.query(Station)
     else:
         query = db_session.query(Station).options(
             load_only(*(load_only_tuple)))
     bus_request = query.filter(Station.id == station_id).one()
     return bus_request
예제 #4
0
 def get_customer_by_id(customer_id, load_only_tuple=None):
     if load_only_tuple == None:
         query = db_session.query(Customer)
     else:
         query = db_session.query(Customer).options(
             load_only(*(load_only_tuple)))
     customer_request = query.filter(Customer.id == customer_id).one()
     return customer_request
예제 #5
0
    def get_bus_by_id(bus_id, load_only_tuple):
        if load_only_tuple == None:
            query = db_session.query(Bus)
        else:
            query = db_session.query(Bus).options(
                load_only(*(load_only_tuple)))

        bus_request = query.filter(Bus.id == bus_id).one()
        return bus_request
    def get_all_available_schedule():

        from_date = datetime.now()

        station1 = aliased(Station)
        station2 = aliased(Station)

        query = db_session.query(Schedule)\
            .join(station1, station1.id == Schedule.departure_station_id) \
            .join(station2, station2.id == Schedule.arrival_station_id) \
            .options(
                Load(Schedule).load_only("id", "arrival_time", "departure_time", "price").
                contains_eager(Schedule.departure_station, alias=station1).load_only("id", "name"),
                contains_eager(Schedule.arrival_station, alias=station2).load_only("id", "name")
                ).filter(Schedule.departure_time >= from_date)

        # Equivalent SQL but no contains eager
        # query = db_session.query(Schedule)\
        #     .join(station1, station1.id == Schedule.departure_station_id) \
        #     .join(station2, station2.id == Schedule.arrival_station_id). \
        #     options(
        #     Load(Schedule).load_only("id", "arrival_time", "departure_time", "price"),
        #     Load(station1).load_only("id", "name"),
        #     Load(station2).load_only("id", "name"))\
        #     .filter(Schedule.departure_time >= from_date)

        request = query.all()
        return request
    def get_station_schedule(station_id):

        from_date = datetime.now()
        query = db_session.query(Station)\
            .join(Schedule, and_(Station.id == Schedule.departure_station_id,
                                 Station.id == station_id,
                                 Schedule.departure_time >= from_date))\
            .options(Load(Station).load_only("id", "name").
                     contains_eager(Station.departure_station_schedule).
                     load_only("arrival_time", "departure_time", "price").joinedload(Schedule.arrival_station).load_only("name"))

        request = query.all()
        return request
    def get_all_reservations_per_user(customer_id):
        station1 = aliased(Station)
        station2 = aliased(Station)
        query = db_session.query(Reservation)\
            .join(Schedule, Reservation.schedule_id == Schedule.id) \
            .join(station1, station1.id == Schedule.departure_station_id) \
            .join(station2, station2.id == Schedule.arrival_station_id) \
            .options(
            Load(Reservation).load_only("id").
                contains_eager(Schedule).load_only("id", "arrival_time", "departure_time", "price"),
            contains_eager(Schedule.departure_station, alias=station1).load_only("id", "name"),
            contains_eager(Schedule.arrival_station, alias=station2).load_only("id", "name")
                ).filter(Reservation.customer_id >= customer_id)

        request = query.all()
        return request
예제 #9
0
 def get_all_buses():
     bus_request = db_session.query(Bus).all()
     return bus_request
 def get_all_schedule():
     request = db_session.query(Schedule).all()
     return request
 def get_all_reservations():
     request = db_session.query(Schedule).all()
     return request