diff --git a/liteindex/defined_index.py b/liteindex/defined_index.py index c053908..61a9214 100644 --- a/liteindex/defined_index.py +++ b/liteindex/defined_index.py @@ -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 diff --git a/liteindex/query_parser.py b/liteindex/query_parser.py index c12c42a..e6eaff5 100644 --- a/liteindex/query_parser.py +++ b/liteindex/query_parser.py @@ -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 = { @@ -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: @@ -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": @@ -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(): @@ -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}" @@ -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}" diff --git a/setup.py b/setup.py index b96b79f..f55d934 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ EMAIL = "praneeth@bpraneeth.com" 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 = []