MCPcopy Create free account
hub / github.com/dot-agent/nextpy / get

Method get

nextpy/data/jsondb.py:224–247  ·  view source on GitHub ↗

Retrieves an instance from the database by its ID. Args: id_value (int): The ID of the instance to retrieve. Returns: Optional[T]: The retrieved instance, or None if not found. Raises: TypeError: If id_value is not an integer.

(self, id_value: int)

Source from the content-addressed store, hash-verified

222 return [self.model(**record) for record in filtered_data] # type: ignore
223
224 def get(self, id_value: int) -> Optional[T]:
225 """Retrieves an instance from the database by its ID.
226
227 Args:
228 id_value (int): The ID of the instance to retrieve.
229
230 Returns:
231 Optional[T]: The retrieved instance, or None if not found.
232
233 Raises:
234 TypeError: If id_value is not an integer.
235 IdNotFoundError: If no instance with the given ID is found.
236 """
237 if not isinstance(id_value, int):
238 raise TypeError(
239 f"Expected id_value to be an int, got {type(id_value).__name__} instead."
240 )
241
242 data = self._read_data()["data"]
243 for record in data:
244 if record.get(self.id_fieldname) == id_value:
245 return self.model(**record) # type: ignore
246
247 raise IdNotFoundError(f"Id {id_value!r} does not exist.")
248
249 def delete(self, id_value: int) -> None:
250 """Deletes an instance from the database by its ID.

Callers 15

add_default_endpointsMethod · 0.45
get_load_eventsMethod · 0.45
setup_admin_dashMethod · 0.45
get_frontend_packagesMethod · 0.45
_should_compileMethod · 0.45
compile_Method · 0.45
upload_fileFunction · 0.45
serializerFunction · 0.45
get_serializerFunction · 0.45
__init__Method · 0.45
_create_event_chainMethod · 0.45

Calls 2

_read_dataMethod · 0.95
IdNotFoundErrorClass · 0.85

Tested by

no test coverage detected