Skip to content

Commit 77b54ea

Browse files
authored
Merge pull request #6 from kauelima21/feat/filters
bugfix: return partition_key
2 parents ad9edc7 + 4d05192 commit 77b54ea

File tree

2 files changed

+3
-76
lines changed

2 files changed

+3
-76
lines changed

dynolayer/dynolayer.py

+2-75
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,6 @@ def query_by(
9999
self._secondary_index = secondary_index
100100
return self.find_by(key, comparator, key_value)
101101

102-
"""
103-
Args:
104-
key (str): The table key to filter on.
105-
key_value: The value to use on the filter.
106-
107-
Returns:
108-
self: The DynoLayer.
109-
or_query_by('likes', '<', 20)
110-
"""
111-
112-
def or_query_by(
113-
self,
114-
key: str,
115-
comparator: Literal["=", "<", "<=", ">", ">=", "BETWEEN", "begins_with"],
116-
key_value,
117-
secondary_index=None
118-
):
119-
self._is_query_operation = True
120-
self._secondary_index = secondary_index
121-
return self.or_find_by(key, comparator, key_value)
122-
123102
"""
124103
Args:
125104
filter_expression (str): The filter expression string.
@@ -211,58 +190,6 @@ def find_by(
211190

212191
return self
213192

214-
"""
215-
Args:
216-
attribute (str): The table attribute to filter on.
217-
attribute_value: The value to use on the filter.
218-
219-
Returns:
220-
self: The DynoLayer.
221-
"""
222-
223-
def or_find_by(
224-
self,
225-
attribute: str,
226-
comparator: Literal["=", "<", "<=", ">", ">=", "BETWEEN", "begins_with"],
227-
attribute_value
228-
):
229-
use_or_operator = ' OR '
230-
old_att = ''
231-
if self._is_find_by:
232-
if str(self._filter_params.get(f':{attribute}', '')):
233-
letters = string.ascii_lowercase
234-
random_str = ''
235-
for i in range(4):
236-
random_str += random.choice(letters)
237-
old_att = attribute
238-
attribute = random_str + attribute
239-
240-
if not self._is_find_by:
241-
self._is_find_by = True
242-
243-
if isinstance(attribute_value, dict) or (isinstance(attribute_value, list) and comparator != 'BETWEEN'):
244-
attribute_value = json.dumps(attribute_value)
245-
246-
filter_param = {
247-
f':{attribute}': attribute_value
248-
}
249-
if comparator == 'BETWEEN':
250-
self._filter_expression += f'{use_or_operator}(#{attribute} {comparator} :{attribute[0]} AND :{attribute[1]})'
251-
filter_param = {
252-
f':{attribute[0]}': attribute_value[0],
253-
f':{attribute[1]}': attribute_value[1]
254-
}
255-
elif comparator == 'begins_with':
256-
self._filter_expression += f'{use_or_operator}({comparator}(#{attribute},:{attribute}))'
257-
else:
258-
self._filter_expression += f'{use_or_operator}(#{attribute} {comparator} :{attribute})'
259-
self._filter_params.update(filter_param)
260-
self._filter_params_name.update({
261-
f'#{attribute}': old_att if old_att else attribute
262-
})
263-
264-
return self
265-
266193
"""
267194
This function create a FilterExpression for a query operation
268195
Args:
@@ -508,7 +435,7 @@ def save(self) -> bool:
508435
self._table.put_item(
509436
Item=data
510437
)
511-
self._data['id'] = data[self._partition_key]
438+
self._data[self._partition_key] = data[self._partition_key]
512439
return True
513440
except Exception as e:
514441
self._error = str(e)
@@ -556,7 +483,7 @@ def _safe(self):
556483
zone = os.environ.get('TIMESTAMP_TIMEZONE', 'America/Sao_Paulo')
557484
timezone = pytz.timezone(zone)
558485
current_date = datetime.now(timezone)
559-
if not self._data.get(self._partition_key):
486+
if not self._data.get('created_at', None):
560487
self._data['created_at'] = int(current_date.timestamp())
561488
self._data['updated_at'] = int(current_date.timestamp())
562489

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name='dynolayer',
10-
version='0.4.0',
10+
version='0.4.1',
1111
license='MIT License',
1212
packages=['dynolayer'],
1313
install_requires=['boto3', 'pytz', 'python-dotenv'],

0 commit comments

Comments
 (0)