julee.repositories.memory.base

Memory repository base classes and mixins.

This module provides common functionality for in-memory repository implementations, reducing code duplication and ensuring consistent patterns across all memory-based repositories in the julee domain.

The MemoryRepositoryMixin encapsulates common patterns like: - Dictionary-based storage management - Standardized logging patterns - ID generation with consistent prefixes - Timestamp management (created_at, updated_at) - Generic CRUD operations with proper error handling

Classes using this mixin must provide: - self.storage_dict: Dict[str, T] for entity storage - self.entity_name: str for logging and ID generation - self.logger: logging.Logger instance

Attributes

T

Classes

MemoryRepositoryMixin

Mixin that provides common repository patterns for memory implementations.

Module Contents

class julee.repositories.memory.base.MemoryRepositoryMixin[source]

Bases: Generic[T]

Mixin that provides common repository patterns for memory implementations.

This mixin encapsulates common functionality used across all memory repository implementations, including: - Dictionary-based entity storage and retrieval - Standardized logging patterns with consistent messaging - ID generation with configurable prefixes - Timestamp management (created_at if None, always updated_at) - Generic error handling patterns

Classes using this mixin must provide: - self.storage_dict: Dict[str, T] instance for entity storage - self.entity_name: str for logging and ID generation prefixes - self.logger: logging.Logger instance (typically set in __init__)

generate_entity_id(prefix=None)[source]

Generate a unique entity ID with consistent format.

Parameters:

prefix (str | None) – Optional prefix for the ID. If None, uses entity_name

Returns:

Unique entity ID string in format “{prefix}-{uuid}”

Return type:

str

get_entity(entity_id)[source]

Get an entity from memory storage with standardized logging.

Parameters:

entity_id (str) – Unique entity identifier

Returns:

Entity if found, None otherwise

Return type:

T | None

get_many_entities(entity_ids)[source]

Get multiple entities from memory storage with standardized logging.

Parameters:

entity_ids (list[str]) – List of unique entity identifiers

Returns:

Dict mapping entity_id to entity (or None if not found)

Return type:

dict[str, T | None]

save_entity(entity, entity_id_field)[source]

Save an entity to memory storage with timestamp management.

Parameters:
  • entity (T) – Entity to save

  • entity_id_field (str) – Name of the ID field on the entity

update_timestamps(entity)[source]

Update timestamps on an entity (created_at if None, always updated_at).

Parameters:

entity (T) – Pydantic model with created_at and updated_at fields

entity_name: str[source]
logger: Any[source]
storage_dict: dict[str, T][source]
julee.repositories.memory.base.T[source]