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) diff --git a/sbxpy/service/__init__.py b/sbxpy/service/__init__.py index 212ad5d..3e6dd54 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])