jm_job_node.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import time
  2. from typing import List
  3. from app import models, schemas
  4. from sqlalchemy.orm import Session
  5. def create_jm_job_node(db: Session, item: models.JmJobNode):
  6. db.add(item)
  7. db.commit()
  8. db.refresh(item)
  9. return item
  10. def create_jm_job_edge(db: Session, item: models.JmJobEdge):
  11. db.add(item)
  12. db.commit()
  13. db.refresh(item)
  14. return item
  15. def get_one_job_nodes(db: Session, job_id: int):
  16. res: List[models.JmJobNode] = db.query(models.JmJobNode)\
  17. .filter(models.JmJobNode.job_id == job_id).all()
  18. return res
  19. def get_one_job_edges(db: Session, job_id: int):
  20. res: List[models.JmJobEdge] = db.query(models.JmJobEdge)\
  21. .filter(models.JmJobEdge.job_id == job_id).all()
  22. return res
  23. def find_by_homework_and_job(db: Session, job_ids: List[int], homework_id: int):
  24. res: List[models.JmJobNode] = db.query(models.JmJobNode)\
  25. .filter(models.JmJobNode.homework_id == homework_id)\
  26. .filter(models.JmJobNode.job_id.in_(job_ids)).all()
  27. return res
  28. def delete_job_node(db: Session, job_id: int):
  29. db.query(models.JmJobNode).filter(models.JmJobNode.job_id == job_id).delete()
  30. db.query(models.JmJobEdge).filter(models.JmJobEdge.job_id == job_id).delete()
  31. def find_homework_by_job(db: Session, job_id: int):
  32. res: List[models.JmJobNode] = db.query(models.JmJobNode)\
  33. .filter(models.JmJobNode.job_id == job_id)\
  34. .filter(models.JmJobNode.start_point == 1).all()
  35. return res