Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
Signed-off-by: Praneeth Bedapudi <[email protected]>
  • Loading branch information
bedapudi6788 committed Feb 19, 2024
1 parent 4f5cde0 commit 713454d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion liteindex/defined_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def search(

update_columns = ", ".join([f'"{h}" = ?' for h in update.keys()])

sql_query = f"UPDATE {self.name} SET {update_columns} WHERE id IN ({sql_query}) RETURNING {', '.join(('integer_id', 'id', 'updated_at') + select_keys)}"
sql_query = f"""UPDATE {self.name} SET {update_columns} WHERE id IN ({sql_query}) RETURNING {', '.join(('integer_id', 'id', 'updated_at') + tuple('"' + __ + '"' for __ in select_keys))}"""

sql_params = [_ for _ in update.values()] + sql_params

Expand Down
26 changes: 15 additions & 11 deletions liteindex/query_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def process_nested_query(value, prefix):
sub_conditions = []
for sub_key, sub_value in value.items():
if sub_value is None and sub_key == "$ne":
sub_conditions.append(f"{column} IS NOT NULL")
sub_conditions.append(f'"{column}" IS NOT NULL')

elif sub_key in ["$ne", "$like", "$gt", "$lt", "$gte", "$lte"]:
operator = {
Expand All @@ -44,17 +44,17 @@ def process_nested_query(value, prefix):
f"JSON_EXTRACT({column}, '$[*]') {operator} ?"
)
else:
sub_conditions.append(f"{column} {operator} ?")
sub_conditions.append(f'"{column}" {operator} ?')

params.append(sub_value)
elif sub_key == "$in":
sub_conditions.append(
f"{column} IN ({', '.join(['?' for _ in sub_value])})"
f""""{column}" IN ({', '.join(['?' for _ in sub_value])})"""
)
params.extend(sub_value)
elif sub_key == "$nin":
sub_conditions.append(
f"{column} NOT IN ({', '.join(['?' for _ in sub_value])})"
f""""{column}" NOT IN ({', '.join(['?' for _ in sub_value])})"""
)
params.extend(sub_value)
else:
Expand All @@ -70,12 +70,12 @@ def process_nested_query(value, prefix):
params.extend(json.dumps(val) for val in value)
else:
where_conditions.append(
f"{column} IN ({', '.join(['?' for _ in value])})"
f""""{column}" IN ({', '.join(['?' for _ in value])})"""
)
params.extend(value)

elif value is None:
where_conditions.append(f"{column} IS NULL")
where_conditions.append(f'"{column}" IS NULL')
else:
column_type = schema.get(column)
if column_type == "other":
Expand All @@ -94,7 +94,7 @@ def process_nested_query(value, prefix):
# TODO: Handle compressed strings
pass

where_conditions.append(f"{column} = ?")
where_conditions.append(f'"{column}" = ?')
params.append(value)

for key, value in query.items():
Expand Down Expand Up @@ -151,7 +151,9 @@ def search_query(
):
where_conditions, params = parse_query(query, schema)

selected_columns = ", ".join(select_columns) if select_columns else "*"
selected_columns = (
", ".join([f'"{_}"' for _ in select_columns]) if select_columns else "*"
)

query_str = f"SELECT {selected_columns} FROM {table_name}"

Expand All @@ -170,15 +172,17 @@ def search_query(
for sort_item in sort_by:
if isinstance(sort_item, tuple):
sort_list.append(
f"{sort_item[0]} {'DESC' if sort_item[1] else 'ASC'}"
f""""{sort_item[0]}" {'DESC' if sort_item[1] else 'ASC'}"""
)
else:
sort_list.append(
f"{sort_item} {'DESC' if reversed_sort else 'ASC'}"
f""""{sort_item}" {'DESC' if reversed_sort else 'ASC'}"""
)
query_str += ", ".join(sort_list)
else:
query_str += f" ORDER BY {sort_by} {'DESC' if reversed_sort else 'ASC'}"
query_str += (
f""" ORDER BY "{sort_by}" {'DESC' if reversed_sort else 'ASC'}"""
)

query_str += f" LIMIT {n if n is not None else -1} OFFSET {offset if offset is not None else 0}"

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
EMAIL = "[email protected]"
AUTHOR = "BEDAPUDI PRANEETH"
REQUIRES_PYTHON = ">=3.6.0"
VERSION = "0.0.2.dev57"
VERSION = "0.0.2.dev58"

# What packages are required for this module to be executed?
REQUIRED = []
Expand Down

0 comments on commit 713454d

Please sign in to comment.