From 588dd0624dfb1456353e5dcf3b501e31ead59abd Mon Sep 17 00:00:00 2001 From: HansOspina Date: Thu, 18 Jan 2024 16:34:24 -0500 Subject: [PATCH 1/2] skip cache if skipCache :) --- sbxpy/service/__init__.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/sbxpy/service/__init__.py b/sbxpy/service/__init__.py index 9646118..a677253 100644 --- a/sbxpy/service/__init__.py +++ b/sbxpy/service/__init__.py @@ -24,19 +24,18 @@ async def get( cache_key = f"sbx:{result_type.get_model()}:{key}" cached_keys: Set[str] = set() model_instance = None - try: - - await redis_service.get_connection() - cached_keys: Set[str] = set( - await redis_service.get_keys_index(keys_idx) or [] - ) - if use_cache and key in cached_keys: - model_instance = await redis_service.get_object(cache_key, result_type) - if model_instance: - return model_instance - except Exception as e: - logger.exception(f"An error occurred while retrieving data: {e}") - + await redis_service.get_connection() + if use_cache: + try: + cached_keys: Set[str] = set( + await redis_service.get_keys_index(keys_idx) or [] + ) + if key in cached_keys: + model_instance = await redis_service.get_object(cache_key, result_type) + if model_instance: + return model_instance + except Exception as e: + logger.exception(f"An error occurred while retrieving data: {e}") try: query = SBXCachedService.find(result_type.get_model()) query.where_with_keys([key]) From 97e8104e757eed89333b09b5854d4ab8b982a1bb Mon Sep 17 00:00:00 2001 From: HansOspina Date: Mon, 3 Mar 2025 11:19:44 -0500 Subject: [PATCH 2/2] not_contains_support --- sbxpy/QueryBuilder.py | 2 +- sbxpy/__init__.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/sbxpy/QueryBuilder.py b/sbxpy/QueryBuilder.py index 05a3f32..3484d9a 100644 --- a/sbxpy/QueryBuilder.py +++ b/sbxpy/QueryBuilder.py @@ -12,7 +12,7 @@ def __init__(self): "GROUP": [] } self.OP = ["in", "IN", "not in", "NOT IN", "is", "IS", "is not", "IS NOT", "<>", "!=", "=", "<", "<=", ">=", ">", - "like", "LIKE"] + "like", "LIKE", "not like", "NOT LIKE"] def set_domain(self, domain_id): self.q['domain'] = domain_id diff --git a/sbxpy/__init__.py b/sbxpy/__init__.py index c2d0c81..4b13df2 100644 --- a/sbxpy/__init__.py +++ b/sbxpy/__init__.py @@ -92,6 +92,11 @@ def and_where_contains(self, field, value): self.query.add_condition(self.lastANDOR, field, 'LIKE', '%' + value + '%') return self + def and_where_not_contains(self, field, value): + self.lastANDOR = 'AND' + self.query.add_condition(self.lastANDOR, field, 'NOT LIKE', '%' + value + '%') + return self + def and_where_in(self, field, value): self.lastANDOR = 'AND' self.query.add_condition(self.lastANDOR, field, 'IN', value) @@ -157,6 +162,11 @@ def or_where_contains(self, field, value): self.query.add_condition(self.lastANDOR, field, 'LIKE', '%' + value + '%') return self + def or_where_not_contains(self, field, value): + self.lastANDOR = 'AND' if (self.lastANDOR is None) else 'OR' + self.query.add_condition(self.lastANDOR, field, 'NOT LIKE', '%' + value + '%') + return self + def or_where_in(self, field, value): self.lastANDOR = 'AND' if (self.lastANDOR is None) else 'OR' self.query.add_condition(self.lastANDOR, field, 'IN', value)