summaryrefslogtreecommitdiff
path: root/venv/lib/python3.11/site-packages/polyfactory/persistence.py
blob: 7aa510bc462ed64dc5b41f75afc453fbbcb1d3d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from __future__ import annotations

from typing import Protocol, TypeVar, runtime_checkable

T = TypeVar("T")


@runtime_checkable
class SyncPersistenceProtocol(Protocol[T]):
    """Protocol for sync persistence"""

    def save(self, data: T) -> T:
        """Persist a single instance synchronously.

        :param data: A single instance to persist.

        :returns: The persisted result.

        """
        ...

    def save_many(self, data: list[T]) -> list[T]:
        """Persist multiple instances synchronously.

        :param data: A list of instances to persist.

        :returns: The persisted result

        """
        ...


@runtime_checkable
class AsyncPersistenceProtocol(Protocol[T]):
    """Protocol for async persistence"""

    async def save(self, data: T) -> T:
        """Persist a single instance asynchronously.

        :param data: A single instance to persist.

        :returns: The persisted result.
        """
        ...

    async def save_many(self, data: list[T]) -> list[T]:
        """Persist multiple instances asynchronously.

        :param data: A list of instances to persist.

        :returns: The persisted result
        """
        ...