Update uniqueness checks to use sqlalchemy orm 2.0 style

This commit is contained in:
Tim Van Baak 2021-05-31 12:24:57 -07:00
parent 5e051e7e89
commit e47711356c
2 changed files with 8 additions and 2 deletions

View File

@ -38,7 +38,10 @@ def create(
raise ArgumentError('Lexicon prompt must be a string') raise ArgumentError('Lexicon prompt must be a string')
# Query the db to make sure the lexicon name isn't taken # 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') raise ArgumentError('Lexicon name is already taken')
new_lexicon = Lexicon( new_lexicon = Lexicon(

View File

@ -51,7 +51,10 @@ def create(
raise ArgumentError('Email must be a string') raise ArgumentError('Email must be a string')
# Query the db to make sure the username isn't taken # 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') raise ArgumentError('Username is already taken')
new_user = User( new_user = User(