-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.py
More file actions
113 lines (80 loc) · 2.45 KB
/
Copy pathinterface.py
File metadata and controls
113 lines (80 loc) · 2.45 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from typing import (
Protocol,
Any,
Union,
Sequence,
Tuple,
Optional,
Mapping,
Iterator,
Type,
TypeVar,
AsyncIterator,
Awaitable,
)
import pydantic
class Cursor(Protocol):
rowcount: int
def fetchone(self) -> Mapping[str, Any]:
pass
def fetchmany(self, size: int = None) -> Sequence[Mapping[str, Any]]:
pass
def fetchall(self) -> Sequence[Mapping[str, Any]]:
pass
def __iter__(self) -> Iterator[Mapping[str, Any]]:
pass
def __len__(self) -> int:
pass
T = TypeVar("T", bound=pydantic.BaseModel)
class Connection(Protocol):
def execute(self, query: str, *params: Any) -> Cursor:
pass
def execute_none(self, query: str, *params: Any) -> None:
pass
def execute_rowcount(self, query: str, *params: Any) -> int:
pass
def execute_one(self, query: str, *params: Any) -> Any:
pass
def execute_one_model(
self, model: Type[T], query: str, *params: Any
) -> Optional[T]:
pass
def execute_many(self, query: str, *params: Any) -> Iterator[Any]:
pass
def execute_many_model(
self, model: Type[T], query: str, *params: Any
) -> Iterator[T]:
pass
class AsyncCursor(Protocol):
async def fetch(
self, n: int, *, timeout: float = None
) -> Sequence[Mapping[str, Any]]:
pass
async def fetchrow(self, *, timeout: float = None) -> Mapping[str, Any]:
pass
async def forward(self, n: int, *, timeout: float = None) -> int:
pass
class AsyncConnection(Protocol):
async def execute(self, query: str, *params: Any) -> AsyncCursor:
pass
async def execute_none(self, query: str, *params: Any) -> None:
pass
async def execute_rowcount(self, query: str, *params: Any) -> int:
pass
async def execute_one(self, query: str, *params: Any) -> Any:
pass
async def execute_one_model(
self, model: Type[T], query: str, *params: Any
) -> Optional[T]:
pass
def execute_many(self, query: str, *params: Any) -> AsyncIterator[Any]:
pass
def execute_many_model(
self, model: Type[T], query: str, *params: Any
) -> AsyncIterator[T]:
pass
GenericConnection = Union[Connection, AsyncConnection]
GenericCursor = Union[Cursor, AsyncCursor]
RT = TypeVar("RT")
ReturnType = Union[RT, Awaitable[RT]]
IteratorReturn = Union[Iterator[RT], AsyncIterator[RT]]