Commit 1745b0b9 authored by alexjubs's avatar alexjubs
Browse files

filtering

parent 57d26244
......@@ -43,39 +43,42 @@ def handle_filtering_on_table(attributes, filters):
int_operators = ["=", ">", "<", ">=", "<=", "<>"]
string_operators = ["LIKE", "="]
bool_operators = ["="]
for i in range(len(attributes)):
should_filter = input(f"apply filter for `{attributes[i]}`? 'y' or 'yes': ")
if should_filter in {'y', 'yes'}:
print(f"Filtering on {attributes[i]}. The type is {attribute_type[attributes[i]]}")
if attribute_type[attributes[i]] == int:
should_filter = input(f"Would you like to apply a filter for any of `{attributes}`? \n 'y' or 'yes': ") in {"y", "yes"}
while (should_filter):
filtering_attribute = input(f"Which would you like to filter on out of {attributes}: ")
while (filtering_attribute not in attributes):
filtering_attribute = input(f"Which would you like to filter on out of {attributes}: ")
print(f"Filtering on {filtering_attribute}. The type is {attribute_type[filtering_attribute]}")
if attribute_type[filtering_attribute] == int:
operator = input(f"Enter the operator (in {int_operators}): ")
while operator not in int_operators:
operator = input(f"Enter the operator (in {int_operators}): ")
while operator not in int_operators:
operator = input(f"Enter the operator (in {int_operators}): ")
value = int(input("Enter the filtering value (must be int): "))
value = int(input("Enter the filtering value (must be int): "))
if attribute_type[attributes[i]] == str:
print("note: wildcard matching works on 'LIKE' operator")
if attribute_type[filtering_attribute] == str:
print("note: wildcard matching works on 'LIKE' operator")
operator = input(f"Pick an operator ({string_operators}): ")
while operator not in string_operators:
operator = input(f"Pick an operator ({string_operators}): ")
while operator not in string_operators:
operator = input(f"Pick an operator ({string_operators}): ")
value = input("Enter the filtering value: ")
value = input("Enter the filtering value: ")
if attribute_type[attributes[i]] == bool:
if attribute_type[filtering_attribute] == bool:
operator = input(f"Pick an operator ({bool_operators}): ")
while operator not in bool_operators:
operator = input(f"Pick an operator ({bool_operators}): ")
while operator not in bool_operators:
operator = input(f"Pick an operator ({bool_operators}): ")
value = input("Enter the filtering value (1 or 0): ")
while value not in {"0", "1"}:
value = input("Enter the filtering value (1 or 0): ")
while value not in {"0", "1"}:
value = input("Enter the filtering value (1 or 0): ")
filters[attributes[i]] = {
"value" : value,
"operator" : operator
}
else:
filters[attributes[i]] = None
filters[filtering_attribute] = {
"value" : value,
"operator" : operator
}
should_filter = input(f"Would you like to apply another filter for any of `{attributes}`? \n 'y' or 'yes': ") in {"y", "yes"}
def insert_base_func(command):
insert_entry_args = insert_entry_parser.parse_args(command[1:])
......@@ -111,7 +114,7 @@ def delete_base_func(command):
filters=filters
)
print(f"DELETING rows from {delete_rows_args.table}: \n {filters} \n")
print(f"DELETING rows from {delete_rows_args.table}: \n with filters: {filters} \n")
def get_base_func(command):
get_rows_args = get_rows_parser.parse_args(command[1:])
......@@ -123,4 +126,4 @@ def get_base_func(command):
filters=filters
)
print(f"GETTING rows from {get_rows_args.table}: \n {filters} \n")
print(f"GETTING rows from {get_rows_args.table}: \n with filters: {filters} \n")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment