Created
November 18, 2021 09:24
-
-
Save dimasahmad/b67f175c8aab919ac18ef33656f170d0 to your computer and use it in GitHub Desktop.
sql.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import request | |
# ?location=Bandung&gender=male | |
filter_by = {"location": "Bandung", "gender": "male"} | |
where = [] | |
for f, v in filter_by.items(): | |
if f == "location": | |
where.append("location LIKE '%{}% ".format(v)) | |
if f == "gender": | |
if v == "male": | |
where.append("gender != female") | |
if v == "female": | |
where.append("gender != male") | |
column = "jobs_id, jobs_name, c_user_id, jobs_description, jobs_location, jobs_type, jobs_gender, jobs_status" | |
table = "jobs INNER JOIN users ON users.user_id = jobs.c_user_id" | |
sql = "SELECT %s FROM %s WHERE %s" % (column, table, " AND ".join(where)) | |
print(sql) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment