From 6fa91bc76a5011e271f8ecf33973b5dddcadfcd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Fl=C3=B3rez?= Date: Thu, 31 May 2012 11:32:25 -0500 Subject: [PATCH 1/4] Added ConsistentRead option --- simpledb/simpledb.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/simpledb/simpledb.py b/simpledb/simpledb.py index adc794e..01764a6 100644 --- a/simpledb/simpledb.py +++ b/simpledb/simpledb.py @@ -478,7 +478,7 @@ def delete_attributes(self, domain, item, attributes=None): request = Request("POST", self._sdb_url(), data) self._make_request(request) - def get_attributes(self, domain, item, attributes=None): + def get_attributes(self, domain, item, attributes=None, consistent_read=False): """ Returns all of the attributes associated with the item. @@ -501,6 +501,9 @@ def get_attributes(self, domain, item, attributes=None): 'DomainName': domain, 'ItemName': item, } + if consistent_read: + data.update(ConsistentRead='true') + if attributes: for i, attr in enumerate(attributes): data['AttributeName.%s' % i] = attr @@ -920,9 +923,9 @@ def values(self, *args): def item_names(self): return self._get_query().item_names() - def get(self, name): + def get(self, name, consistent_read=False): if name not in self.items: - self.items[name] = Item.load(self.simpledb, self, name) + self.items[name] = Item.load(self.simpledb, self, name, consistent_read) item = self.items[name] if not item: raise ItemDoesNotExist(name) @@ -965,7 +968,7 @@ def _get_query(self): class Item(DictMixin): @classmethod - def load(cls, simpledb, domain, name): + def load(cls, simpledb, domain, name, consistent_read=False): attrs = simpledb.get_attributes(domain, name) return cls(simpledb, domain, name, attrs) From fc6b7c551a76bd446345160aa09a33c5b708f5ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Fl=C3=B3rez?= Date: Thu, 31 May 2012 11:32:25 -0500 Subject: [PATCH 2/4] Added ConsistentRead option --- simpledb/models.py | 5 +++-- simpledb/simpledb.py | 11 +++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/simpledb/models.py b/simpledb/models.py index 62832af..b0050e6 100644 --- a/simpledb/models.py +++ b/simpledb/models.py @@ -172,8 +172,9 @@ def values(self, *args): def item_names(self): return self._get_query().item_names() - def get(self, name): - return self.model.from_item(self.model.Meta.domain.get(name)) + def get(self, name, consistent_read=False): + return self.model.from_item(self.model.Meta.domain.get(name, + consistent_read)) def _get_query(self): return Query(self.model.Meta.domain) diff --git a/simpledb/simpledb.py b/simpledb/simpledb.py index adc794e..01764a6 100644 --- a/simpledb/simpledb.py +++ b/simpledb/simpledb.py @@ -478,7 +478,7 @@ def delete_attributes(self, domain, item, attributes=None): request = Request("POST", self._sdb_url(), data) self._make_request(request) - def get_attributes(self, domain, item, attributes=None): + def get_attributes(self, domain, item, attributes=None, consistent_read=False): """ Returns all of the attributes associated with the item. @@ -501,6 +501,9 @@ def get_attributes(self, domain, item, attributes=None): 'DomainName': domain, 'ItemName': item, } + if consistent_read: + data.update(ConsistentRead='true') + if attributes: for i, attr in enumerate(attributes): data['AttributeName.%s' % i] = attr @@ -920,9 +923,9 @@ def values(self, *args): def item_names(self): return self._get_query().item_names() - def get(self, name): + def get(self, name, consistent_read=False): if name not in self.items: - self.items[name] = Item.load(self.simpledb, self, name) + self.items[name] = Item.load(self.simpledb, self, name, consistent_read) item = self.items[name] if not item: raise ItemDoesNotExist(name) @@ -965,7 +968,7 @@ def _get_query(self): class Item(DictMixin): @classmethod - def load(cls, simpledb, domain, name): + def load(cls, simpledb, domain, name, consistent_read=False): attrs = simpledb.get_attributes(domain, name) return cls(simpledb, domain, name, attrs) From 6d13f72fcc754d93de2764c6f52a2bd9e78f6807 Mon Sep 17 00:00:00 2001 From: Ronald Date: Thu, 11 Oct 2012 16:24:51 -0500 Subject: [PATCH 3/4] Update simpledb/simpledb.py --- simpledb/simpledb.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/simpledb/simpledb.py b/simpledb/simpledb.py index 845fc38..2a6f760 100644 --- a/simpledb/simpledb.py +++ b/simpledb/simpledb.py @@ -660,13 +660,11 @@ def _make_condition(self, attribute, operation, value, encoder): operation, self._quote(value)) def _make_eq_condition(self, attribute, operation, value, encoder): - value = encoder(attribute, value) if value is None: return '%s IS NULL' % attribute return self._make_condition(attribute, operation, value, encoder) def _make_noteq_condition(self, attribute, operation, value, encoder): - value = encoder(attribute, value) if value is None: return '%s IS NOT NULL' % attribute return self._make_condition(attribute, operation, value, encoder) From 5ef3de7ce9214fdec5bc802873baeeae9ad7fa29 Mon Sep 17 00:00:00 2001 From: Ronald Date: Thu, 10 Jan 2013 15:13:49 -0500 Subject: [PATCH 4/4] Update simpledb/simpledb.py Remove cache load item --- simpledb/simpledb.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/simpledb/simpledb.py b/simpledb/simpledb.py index 2a6f760..26d79c1 100644 --- a/simpledb/simpledb.py +++ b/simpledb/simpledb.py @@ -922,9 +922,14 @@ def item_names(self): return self._get_query().item_names() def get(self, name, consistent_read=False): + """ if name not in self.items: self.items[name] = Item.load(self.simpledb, self, name, consistent_read) item = self.items[name] + """ + + item = Item.load(self.simpledb, self, name, consistent_read) + if not item: raise ItemDoesNotExist(name) return item