From e47711356cd1c432d6a336d6ffcc206829073e46 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Mon, 31 May 2021 12:24:57 -0700 Subject: [PATCH] Update uniqueness checks to use sqlalchemy orm 2.0 style --- amanuensis/backend/lexicon.py | 5 ++++- amanuensis/backend/user.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/amanuensis/backend/lexicon.py b/amanuensis/backend/lexicon.py index 187d50f..7e20790 100644 --- a/amanuensis/backend/lexicon.py +++ b/amanuensis/backend/lexicon.py @@ -38,7 +38,10 @@ def create( raise ArgumentError('Lexicon prompt must be a string') # Query the db to make sure the lexicon name isn't taken - if db.session.query(func.count(Lexicon.id)).filter(Lexicon.name == name).scalar() > 0: + if db( + select(func.count(Lexicon.id)) + .where(Lexicon.name == name) + ).scalar() > 0: raise ArgumentError('Lexicon name is already taken') new_lexicon = Lexicon( diff --git a/amanuensis/backend/user.py b/amanuensis/backend/user.py index aa3df6d..6b30032 100644 --- a/amanuensis/backend/user.py +++ b/amanuensis/backend/user.py @@ -51,7 +51,10 @@ def create( raise ArgumentError('Email must be a string') # Query the db to make sure the username isn't taken - if db.session.query(func.count(User.id)).filter(User.username == username).scalar() > 0: + if db( + select(func.count(User.id)) + .where(User.username == username) + ).scalar() > 0: raise ArgumentError('Username is already taken') new_user = User(