diff --git a/app/dao/service_data_retention_dao.py b/app/dao/service_data_retention_dao.py index b95ca5720..cd2c1fd4b 100644 --- a/app/dao/service_data_retention_dao.py +++ b/app/dao/service_data_retention_dao.py @@ -1,3 +1,5 @@ +from sqlalchemy import select, update + from app import db from app.dao.dao_utils import autocommit from app.models import ServiceDataRetention @@ -5,29 +7,31 @@ from app.utils import utc_now def fetch_service_data_retention_by_id(service_id, data_retention_id): - data_retention = ServiceDataRetention.query.filter_by( - service_id=service_id, id=data_retention_id - ).first() - return data_retention + stmt = select(ServiceDataRetention).where( + ServiceDataRetention.service_id == service_id, + ServiceDataRetention.id == data_retention_id, + ) + return db.session.execute(stmt).scalars().first() def fetch_service_data_retention(service_id): - data_retention_list = ( - ServiceDataRetention.query.filter_by(service_id=service_id) + stmt = ( + select(ServiceDataRetention) + .where(ServiceDataRetention.service_id == service_id) .order_by( # in the order that models.notification_types are created (email, sms, letter) ServiceDataRetention.notification_type ) - .all() ) - return data_retention_list + return db.session.execute(stmt).scalars().all() def fetch_service_data_retention_by_notification_type(service_id, notification_type): - data_retention_list = ServiceDataRetention.query.filter_by( - service_id=service_id, notification_type=notification_type - ).first() - return data_retention_list + stmt = select(ServiceDataRetention).where( + ServiceDataRetention.service_id == service_id, + ServiceDataRetention.notification_type == notification_type, + ) + return db.session.execute(stmt).scalars().first() @autocommit @@ -46,16 +50,22 @@ def insert_service_data_retention(service_id, notification_type, days_of_retenti def update_service_data_retention( service_data_retention_id, service_id, days_of_retention ): - updated_count = ServiceDataRetention.query.filter( - ServiceDataRetention.id == service_data_retention_id, - ServiceDataRetention.service_id == service_id, - ).update({"days_of_retention": days_of_retention, "updated_at": utc_now()}) - return updated_count + stmt = ( + update(ServiceDataRetention) + .where( + ServiceDataRetention.id == service_data_retention_id, + ServiceDataRetention.service_id == service_id, + ) + .values({"days_of_retention": days_of_retention, "updated_at": utc_now()}) + ) + result = db.session.execute(stmt) + return result.rowcount def fetch_service_data_retention_for_all_services_by_notification_type( notification_type, ): - return ServiceDataRetention.query.filter( + stmt = select(ServiceDataRetention).where( ServiceDataRetention.notification_type == notification_type - ).all() + ) + return db.session.execute(stmt).scalars().all() diff --git a/app/dao/service_guest_list_dao.py b/app/dao/service_guest_list_dao.py index acd39703c..59d381a8b 100644 --- a/app/dao/service_guest_list_dao.py +++ b/app/dao/service_guest_list_dao.py @@ -1,11 +1,12 @@ +from sqlalchemy import delete, select + from app import db from app.models import ServiceGuestList def dao_fetch_service_guest_list(service_id): - return ServiceGuestList.query.filter( - ServiceGuestList.service_id == service_id - ).all() + stmt = select(ServiceGuestList).where(ServiceGuestList.service_id == service_id) + return db.session.execute(stmt).scalars().all() def dao_add_and_commit_guest_list_contacts(objs): @@ -14,6 +15,7 @@ def dao_add_and_commit_guest_list_contacts(objs): def dao_remove_service_guest_list(service_id): - return ServiceGuestList.query.filter( - ServiceGuestList.service_id == service_id - ).delete() + stmt = delete(ServiceGuestList).where(ServiceGuestList.service_id == service_id) + result = db.session.execute(stmt) + db.session.commit() + return result.rowcount diff --git a/app/dao/webauthn_credential_dao.py b/app/dao/webauthn_credential_dao.py index b34d3c014..4c7a0c888 100644 --- a/app/dao/webauthn_credential_dao.py +++ b/app/dao/webauthn_credential_dao.py @@ -1,13 +1,16 @@ +from sqlalchemy import select + from app import db from app.dao.dao_utils import autocommit from app.models import WebauthnCredential def dao_get_webauthn_credential_by_user_and_id(user_id, webauthn_credential_id): - return WebauthnCredential.query.filter( + stmt = select(WebauthnCredential).where( WebauthnCredential.user_id == user_id, WebauthnCredential.id == webauthn_credential_id, - ).one() + ) + return db.session.execute(stmt).scalars().one() @autocommit