Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sbxpy/QueryBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions sbxpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 12 additions & 13 deletions sbxpy/service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down