Skip to content

Commit 0258ec6

Browse files
authored
Merge pull request #6 from socobox/not_contains_support
Not contains support
2 parents 61e73bf + 97e8104 commit 0258ec6

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

sbxpy/QueryBuilder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self):
1212
"GROUP": []
1313
}
1414
self.OP = ["in", "IN", "not in", "NOT IN", "is", "IS", "is not", "IS NOT", "<>", "!=", "=", "<", "<=", ">=", ">",
15-
"like", "LIKE"]
15+
"like", "LIKE", "not like", "NOT LIKE"]
1616

1717
def set_domain(self, domain_id):
1818
self.q['domain'] = domain_id

sbxpy/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ def and_where_contains(self, field, value):
9292
self.query.add_condition(self.lastANDOR, field, 'LIKE', '%' + value + '%')
9393
return self
9494

95+
def and_where_not_contains(self, field, value):
96+
self.lastANDOR = 'AND'
97+
self.query.add_condition(self.lastANDOR, field, 'NOT LIKE', '%' + value + '%')
98+
return self
99+
95100
def and_where_in(self, field, value):
96101
self.lastANDOR = 'AND'
97102
self.query.add_condition(self.lastANDOR, field, 'IN', value)
@@ -157,6 +162,11 @@ def or_where_contains(self, field, value):
157162
self.query.add_condition(self.lastANDOR, field, 'LIKE', '%' + value + '%')
158163
return self
159164

165+
def or_where_not_contains(self, field, value):
166+
self.lastANDOR = 'AND' if (self.lastANDOR is None) else 'OR'
167+
self.query.add_condition(self.lastANDOR, field, 'NOT LIKE', '%' + value + '%')
168+
return self
169+
160170
def or_where_in(self, field, value):
161171
self.lastANDOR = 'AND' if (self.lastANDOR is None) else 'OR'
162172
self.query.add_condition(self.lastANDOR, field, 'IN', value)

sbxpy/service/__init__.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,18 @@ async def get(
2424
cache_key = f"sbx:{result_type.get_model()}:{key}"
2525
cached_keys: Set[str] = set()
2626
model_instance = None
27-
try:
28-
29-
await redis_service.get_connection()
30-
cached_keys: Set[str] = set(
31-
await redis_service.get_keys_index(keys_idx) or []
32-
)
33-
if use_cache and key in cached_keys:
34-
model_instance = await redis_service.get_object(cache_key, result_type)
35-
if model_instance:
36-
return model_instance
37-
except Exception as e:
38-
logger.exception(f"An error occurred while retrieving data: {e}")
39-
27+
await redis_service.get_connection()
28+
if use_cache:
29+
try:
30+
cached_keys: Set[str] = set(
31+
await redis_service.get_keys_index(keys_idx) or []
32+
)
33+
if key in cached_keys:
34+
model_instance = await redis_service.get_object(cache_key, result_type)
35+
if model_instance:
36+
return model_instance
37+
except Exception as e:
38+
logger.exception(f"An error occurred while retrieving data: {e}")
4039
try:
4140
query = SBXCachedService.find(result_type.get_model())
4241
query.where_with_keys([key])

0 commit comments

Comments
 (0)