File: persistence.py

package info (click to toggle)
python-polyfactory 2.22.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,892 kB
  • sloc: python: 11,338; makefile: 103; sh: 37
file content (53 lines) | stat: -rw-r--r-- 1,192 bytes parent folder | download
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
        """
        ...