def _get_item_async(self, context, table_info, hash_key, range_key, attributes_to_get, consistent=True): payload = dict(table_name=table_info.name, hash_key=hash_key, range_key=range_key, attributes_to_get=attributes_to_get, consistent=consistent) self._notifier.info( context, notifier.EVENT_TYPE_DATA_GETITEM_START, payload) select_type = ( SelectType.all() if attributes_to_get is None else SelectType.specific_attributes(attributes_to_get) ) hash_key_condition_list = [IndexedCondition.eq(hash_key)] range_key_condition_list = ( None if range_key is None else [IndexedCondition.eq(range_key)] ) result = self._execute_async( self._storage_driver.select_item, context, table_info, hash_key_condition_list, range_key_condition_list, select_type, consistent=consistent ) self._notifier.info( context, notifier.EVENT_TYPE_DATA_GETITEM_END, payload) return result
def _get_item_async(self, context, table_info, hash_key, range_key, attributes_to_get, consistent=True): payload = dict(table_name=table_info.name, hash_key=hash_key, range_key=range_key, attributes_to_get=attributes_to_get, consistent=consistent) notifier.notify(context, notifier.EVENT_TYPE_DATA_SELECTITEM_START, payload) select_type = ( SelectType.all() if attributes_to_get is None else SelectType.specific_attributes(attributes_to_get) ) hash_key_condition_list = [IndexedCondition.eq(hash_key)] range_key_condition_list = ( None if range_key is None else [IndexedCondition.eq(range_key)] ) result = self._execute_async( self._storage_driver.select_item, context, table_info, hash_key_condition_list, range_key_condition_list, select_type, consistent=consistent ) notifier.notify(context, notifier.EVENT_TYPE_DATA_SELECTITEM_END, payload) return result
def parse_select_type(cls, select, attributes_to_get, select_on_index=False): if select is None: if attributes_to_get: return SelectType.specific_attributes(attributes_to_get) else: if select_on_index: return SelectType.all_projected() else: return SelectType.all() if select == Values.SPECIFIC_ATTRIBUTES: assert attributes_to_get return SelectType.specific_attributes(attributes_to_get) assert not attributes_to_get if select == Values.ALL_ATTRIBUTES: return SelectType.all() if select == Values.ALL_PROJECTED_ATTRIBUTES: assert select_on_index return SelectType.all_projected() if select == Values.COUNT: return SelectType.count() assert False, "Select type wasn't recognized"
def parse_select_type(cls, select, attributes_to_get, select_on_index=False): if select is None: if attributes_to_get: return SelectType.specific_attributes( attributes_to_get ) else: if select_on_index: return SelectType.all_projected() else: return SelectType.all() if select == Values.SPECIFIC_ATTRIBUTES: assert attributes_to_get return SelectType.specific_attributes(attributes_to_get) assert not attributes_to_get if select == Values.ALL_ATTRIBUTES: return SelectType.all() if select == Values.ALL_PROJECTED_ATTRIBUTES: assert select_on_index return SelectType.all_projected() if select == Values.COUNT: return SelectType.count() assert False, "Select type wasn't recognized"
def test_select_item_count(self): self.storage_mocker.StubOutWithMock(storage, 'select_item') storage.select_item( IgnoreArg(), IgnoreArg(), IgnoreArg(), select_type=SelectType.count(), index_name=IgnoreArg(), limit=IgnoreArg(), exclusive_start_key=IgnoreArg(), consistent=IgnoreArg(), order_type=IgnoreArg() ).AndReturn( models.SelectResult( count=100500 ) ) self.storage_mocker.ReplayAll() table = Table('test_table', connection=self.DYNAMODB_CON) count = table.query_count(consistent=False, hash_key__eq=1) self.assertEqual(count, 100500) self.storage_mocker.VerifyAll()
def test_select_item_count(self): self.storage_mocker.StubOutWithMock(storage, 'select_item') storage.select_item(IgnoreArg(), IgnoreArg(), IgnoreArg(), select_type=SelectType.count(), index_name=IgnoreArg(), limit=IgnoreArg(), exclusive_start_key=IgnoreArg(), consistent=IgnoreArg(), order_type=IgnoreArg()).AndReturn( models.SelectResult(count=100500)) self.storage_mocker.ReplayAll() table = Table('test_table', connection=self.DYNAMODB_CON) count = table.query_count(consistent=False, hash_key__eq=1) self.assertEqual(count, 100500) self.storage_mocker.VerifyAll()