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()
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)
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]
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)
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)
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]
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()
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]