jm_homework_datasource_relation.py 906 B

1234567891011121314151617181920212223
  1. import time
  2. from typing import List
  3. from app import models, schemas
  4. from sqlalchemy.orm import Session
  5. def create_jm_hd_relation(db: Session, homework_id: int, item: schemas.JmHomeworkDatasourceRelationCreate):
  6. db_item = models.JmHomeworkDatasourceRelation(**item.dict(),**{
  7. "homework_id": homework_id,
  8. })
  9. db.add(db_item)
  10. db.commit()
  11. db.refresh(db_item)
  12. return db_item
  13. def get_jm_relations(db: Session, homework_id: int):
  14. res: List[models.JmHomeworkDatasourceRelation] = db.query(models.JmHomeworkDatasourceRelation)\
  15. .filter(models.JmHomeworkDatasourceRelation.homework_id == homework_id).all()
  16. return res
  17. def delete_jm_relations(db: Session, homework_id: int):
  18. db.query(models.JmHomeworkDatasourceRelation)\
  19. .filter(models.JmHomeworkDatasourceRelation.homework_id == homework_id).delete()