MCPcopy Create free account
hub / github.com/couchbase/couchbase-python-client / get_at

Method get_at

acouchbase/datastructures.py:223–250  ·  view source on GitHub ↗

Get a specific element within a list. :param index: The index to retrieve :return: value for the element :raise: :exc:`IndexError` if the index does not exist

(self, index: int)

Source from the content-addressed store, hash-verified

221 raise InvalidArgumentException(message=f'Index: {index} is out of range.') from None
222
223 async def get_at(self, index: int) -> Any:
224 """
225 Get a specific element within a list.
226
227 :param index: The index to retrieve
228 :return: value for the element
229 :raise: :exc:`IndexError` if the index does not exist
230 """
231 op_type = DatastructureOperationType.ListGetAt
232 async with ObservableRequestHandler(op_type, self._impl.observability_instruments) as ds_obs_handler:
233 ds_obs_handler.create_kv_span(self._impl._request_builder._collection_dtls.get_details_as_dict())
234 kv_op_type = KeyValueOperationType.LookupIn
235 async with ObservableRequestHandler(kv_op_type, self._impl.observability_instruments) as obs_handler:
236 try:
237 op = subdoc_get(f'[{index}]')
238 req, transcoder = self._impl.request_builder.build_lookup_in_request(self._key,
239 (op,),
240 obs_handler,
241 parent_span=ds_obs_handler.wrapped_span) # noqa: E501
242 sdres: LookupInResult = await self._execute_op(self._impl.lookup_in,
243 req,
244 obs_handler,
245 ds_obs_handler.wrapped_span,
246 create_type=True,
247 transcoder=transcoder)
248 return sdres.value[0].get('value', None)
249 except PathNotFoundException:
250 raise InvalidArgumentException(message=f'Index: {index} is out of range.') from None
251
252 async def remove_at(self, index: int) -> None:
253 """

Callers 3

test_listMethod · 0.45
test_kv_ds_listMethod · 0.45
test_kv_ds_listMethod · 0.45

Calls 7

_execute_opMethod · 0.95
get_details_as_dictMethod · 0.80
create_kv_spanMethod · 0.45
getMethod · 0.45

Tested by 3

test_listMethod · 0.36
test_kv_ds_listMethod · 0.36
test_kv_ds_listMethod · 0.36