Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

I'm writing an API in Flask which loads queries saved in files to execute them. The query executed depends on the input format. However, all the queries are the same except they may have 1 of these 4

I'm writing an API in Flask which loads queries saved in files to execute them. The query executed depends on the input format. However, all the queries are the same except they may have 1 of these 4 snippets:

--------------------------------------------------

SELECT * FROM shipments

WHERE origin = %(origin)s

AND destination = %(destination)s

--------------------------------------------------

SELECT * FROM shipments

WHERE origin = %(origin)s

AND destination IN %(destination)s

--------------------------------------------------

SELECT * FROM shipments

WHERE origin IN %(origin)s

AND destination = %(destination)s

--------------------------------------------------

SELECT * FROM shipments

WHERE origin IN %(origin)s

AND destination IN %(destination)s

--------------------------------------------------

Is there a better way to save & modify a single SQL query based on the input format, rather than having 4 slightly different copies?

I'm unsure if this is even desirable since they are 4 different queries, but I was wondering if there's a way to parameterize the query itself like:

--------------------------------------------------

SELECT * FROM shipments

WHERE origin %(origin_format)q %(origin)s

AND destination %(destination_format)q %(destination)s

--------------------------------------------------

Where %(origin_format)q and %(destination_format)q would be IN or =

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question