in route.py [0:0]
def filter_dict_by_sql(schema_dict, sql):
schema_dict_ = copy.deepcopy(schema_dict)
keys = list(schema_dict_['tables'].keys())
keys.sort(key=lambda x: - len(x))
# tables
for table in keys:
if f'from {table.lower()}' not in sql.lower() and f'join {table.lower()}' not in sql.lower():
schema_dict_['tables'].pop(table, None)
# columns
keys = list(schema_dict_['tables'].keys())
keys.sort(key=lambda x: - len(x))
for table in keys:
cls_keys = list(schema_dict_['tables'][table].keys())
cls_keys.sort(key=lambda x: - len(x))
tabel_dict = copy.deepcopy(schema_dict_['tables'][table])
for cls in cls_keys:
if cls.lower() not in sql.lower():
schema_dict_['tables'][table].pop(cls, None)
if len(schema_dict_['tables'][table].keys()) == 0:
# schema_dict_['tables'][table] = tabel_dict # for COUNT(*)
for cls in tabel_dict.keys():
if tabel_dict[cls][1] == True:
schema_dict_['tables'][table][cls] = tabel_dict[cls]
if len(schema_dict_['tables'][table].keys()) == 0:
schema_dict_['tables'][table][tabel_dict.keys()[0]] = tabel_dict[tabel_dict.keys()[0]]
schema_dict_['tables'][table][tabel_dict.keys()[1]] = tabel_dict[tabel_dict.keys()[1]]
# for COUNT(*)
return schema_dict_