I am creating a Python Flask webservice and this is basically how I am doing all of my database calls if a webservice needs to interact with the database:
@event.route("/somepath/<value>", methods = ['GET'])
def getValue(value):
result = getValueHelper(value)
if (result != None)
#format result and return...
else
#Format error and return...
def getValueHelper(value):
try:
db = getDBConnection()
query = text('select * from my_table where value=:q_value')
Result = db.execute(query, q_value=value)
return Result
except Exception, e:
current_app.logger.error("Some sort of error message")
return None
finally:
db.close()
Is this a good way to be doing it? I am fairly new to Flask and SQLAlchemy, so I'm not sure if what I am doing would be considered a good practice.