anymodel.mapper

Data mapper implementation for entity persistence.

This module provides the Mapper class which handles the persistence of entities to various storage backends while maintaining separation between domain logic and storage concerns.

Classes

class anymodel.mapper.Mapper(entity_type=None, *, relations=None, storage, cache=None)[source]

Bases: Generic

Maps entities to storage backends.

The Mapper class handles all persistence operations for a specific entity type, including CRUD operations, identity mapping, and relation management.

__init__(entity_type=None, *, relations=None, storage, cache=None)[source]
relations: Mapping[str, Relation] = None
storage: Storage
property fields
property primary_key
save(entity)[source]

Saves an entity to the database, either inserting (if not mapped yet) or updating it (if a mapping identity is present).

Return type:

TypeVar(TMappedEntity)

find_one_by_pk(*pk)[source]

Find an entity by its primary key.

Return type:

TypeVar(TMappedEntity)

find(**criteria)[source]
Return type:

Iterable[TypeVar(TMappedEntity)]

delete(entity)[source]