Skip to content

Commit

Permalink
Make sure if a sort_key is provided in the case of dynamodb backend
Browse files Browse the repository at this point in the history
  • Loading branch information
romaryd committed May 30, 2018
1 parent 0f110b1 commit b818387
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion jsonrepo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
Copyright (C) 2017 Romary Dupuis
"""

__version__ = '0.1.5'
__version__ = '0.1.6'
__all__ = ['repository', 'mixin', 'record']
20 changes: 14 additions & 6 deletions jsonrepo/backends/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ def dynamodb_server(self):

def get(self, key, sort_key):
self.logger.debug('Storage - get {}'.format(self.prefixed(key)))
res = self.dynamodb_server.get_item(Key={
query = {
self._key: self.prefixed(key),
self._sort_key: sort_key
})
}
if sort_key is not None:
query.update({
self._sort_key: sort_key
})
res = self.dynamodb_server.get_item(Key=query)
if 'Item' in res and 'value' in res['Item']:
return res['Item']['value']

Expand All @@ -54,10 +58,14 @@ def set(self, key, sort_key, value):

def delete(self, key, sort_key):
self.logger.debug('Storage - delete {}'.format(self.prefixed(key)))
return self.dynamodb_server.delete_item(Key={
query = {
self._key: self.prefixed(key),
self._sort_key: sort_key
})
}
if sort_key is not None:
query.update({
self._sort_key: sort_key
})
return self.dynamodb_server.delete_item(Key=query)

def history(self, key, _from='-', _to='+', _desc=True):
if _from != '-':
Expand Down

0 comments on commit b818387

Please sign in to comment.