Exemplo n.º 1
0
def get_by_id(db_model, object_id: Text):
    with DBConnector().conn_session() as session:
        db_object = session.query(db_model).filter_by(id=object_id).first()
        return db_object.to_dict()
Exemplo n.º 2
0
def save(db_model, dict_object):
    with DBConnector().conn_session() as session:
        object_class = db_model(**dict_object)
        session.add(object_class)
        session.flush()
        return str(object_class.id)
Exemplo n.º 3
0
def get_all(db_model):
    with DBConnector().conn_session() as session:
        db_object = session.query(db_model).all()
        return [c.to_dict() for c in db_object]
Exemplo n.º 4
0
def delete(db_model, object_id):
    with DBConnector().conn_session() as session:
        db_object = session.query(db_model).filter_by(id=object_id).first()
        session.delete(db_object)
Exemplo n.º 5
0
def get_delivery_report():
    with DBConnector().conn_session() as session:
        query = get_resume_query(session)
        chunk = query.yield_per(1000)
        return split_generics(500, chunk)
Exemplo n.º 6
0
def get_all_deliveries_by_user(user_id) -> List[Dict]:
    with DBConnector().conn_session() as session:
        deliveries = session.query(Delivery).filter_by(user_id=user_id).all()
        return [delivery.to_dict() for delivery in deliveries]
Exemplo n.º 7
0
def get_user_by_email(email: str) -> Dict:
    with DBConnector().conn_session() as session:
        user = session.query(User).filter_by(email=email).first()
        return user.to_dict()
Exemplo n.º 8
0
def get_all_user_addresses(user_id) -> List[Address]:
    with DBConnector().conn_session() as session:
        addresses = session.query(Address).filter_by(user_id=user_id).all()
        return [address.to_dict() for address in addresses]