'How to make an endpoint with multiple OPTIONAL query params in flask restful with SQL?
I’m having a hard time figuring out how to make a query to the DB with multiple optional query params. That’s because they’re may not be all in the query, so i don’t know how to apply it to a flask endpoint like the following
class auctions(Resource):
def get(self):
breed = request.args.get('breed', type=str)
not_started = request.args.get('notstarted', type=str)
finished = request.args.get('finished', type=str)
if breed:
query = breed_query_param(breed)
else:
query = "select * from auctions"
data = httpUtils.execNonQuery(query)
return data
The httpUtils is going to query but i dont know how to make multiple optional wueerys and pass it to the SQL script
def breed_query_param(breed):
query = f"""
select auctions.id,
auctions.started_price,
auctions.final_price,
auctions.created_at,
auctions.start_at,
auctions.end_at,
auctions.livestock_resume_id,
auctions.user_creator_id,
auctions.winner_user_id,
auctions.namee,
auctions.description,
livestock_breed.breed
from auctions, livestock_breed
where breed = '{breed}'
"""
return query
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
