usermod/Crud/AppCrud.py

27 lines
644 B
Python
Raw Normal View History

2023-02-08 14:57:18 +08:00
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
2023-02-08 15:40:03 +08:00
2023-02-13 14:42:35 +08:00
def add_app(db: Session, app_id: str, name: str, secret_key: str, allowed: bool) -> App:
app = App(id=app_id, secret_key=secret_key, name=name, allowed=allowed)
2023-02-08 15:40:03 +08:00
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()