usermod/Crud/AppCrud.py

27 lines
590 B
Python

from sqlalchemy.orm import Session
from Model.AppModel import App
def get_app_by_id(db: Session, app_id):
app = db.query(App).filter_by(id=app_id).first()
return app
def add_app(db: Session, app_id: str, secret_key: str) -> App:
app = App(id=app_id, secret_key=secret_key)
db.add(app)
db.commit()
db.flush(app)
return app
def delete_app(db: Session, app_id):
db.query(App).filter_by(id=app_id).delete()
db.commit()
def change_app(db: Session, app_id: str, new_data: dict):
db.query(App).filter_by(ip=app_id).update(new_data)
db.commit()