services.py 657 B

12345678910111213141516171819202122232425
  1. from models import AppModel
  2. from sqlalchemy.orm import Session
  3. def get_app(db: Session, app_id: str):
  4. return db.query(AppModel).filter(AppModel.app_id == app_id).first()
  5. def get_apps(db: Session, skip: int = 0, limit: int = 100):
  6. return db.query(AppModel).offset(skip).limit(limit).all()
  7. def save_app(db: Session, app_id: str, config: str):
  8. db_app = AppModel(app_id=app_id, config=config)
  9. db.add(db_app)
  10. db.commit()
  11. db.refresh(db_app)
  12. return db_app
  13. def remove_app(db: Session, app_id: str):
  14. db_app = db.query(AppModel).filter(AppModel.app_id == app_id).first()
  15. db.delete(db_app)
  16. db.commit()
  17. return db_app