|
| 1 | +# PEP 249 Database API 2.0 Types |
| 2 | +# https://www.python.org/dev/peps/pep-0249/ |
| 3 | + |
| 4 | +from collections.abc import Mapping, Sequence |
| 5 | +from typing import Any, Protocol |
| 6 | + |
| 7 | +DBAPITypeCode = Any | None |
| 8 | +# Strictly speaking, this should be a Sequence, but the type system does |
| 9 | +# not support fixed-length sequences. |
| 10 | +DBAPIColumnDescription = tuple[str, DBAPITypeCode, int | None, int | None, int | None, int | None, bool | None] |
| 11 | + |
| 12 | +class DBAPIConnection(Protocol): |
| 13 | + def close(self) -> object: ... |
| 14 | + def commit(self) -> object: ... |
| 15 | + # optional: |
| 16 | + # def rollback(self) -> Any: ... |
| 17 | + def cursor(self) -> DBAPICursor: ... |
| 18 | + |
| 19 | +class DBAPICursor(Protocol): |
| 20 | + @property |
| 21 | + def description(self) -> Sequence[DBAPIColumnDescription] | None: ... |
| 22 | + @property |
| 23 | + def rowcount(self) -> int: ... |
| 24 | + # optional: |
| 25 | + # def callproc(self, __procname: str, __parameters: Sequence[Any] = ...) -> Sequence[Any]: ... |
| 26 | + def close(self) -> object: ... |
| 27 | + def execute(self, __operation: str, __parameters: Sequence[Any] | Mapping[str, Any] = ...) -> object: ... |
| 28 | + def executemany(self, __operation: str, __seq_of_parameters: Sequence[Sequence[Any]]) -> object: ... |
| 29 | + def fetchone(self) -> Sequence[Any] | None: ... |
| 30 | + def fetchmany(self, __size: int = ...) -> Sequence[Sequence[Any]]: ... |
| 31 | + def fetchall(self) -> Sequence[Sequence[Any]]: ... |
| 32 | + # optional: |
| 33 | + # def nextset(self) -> None | Literal[True]: ... |
| 34 | + arraysize: int |
| 35 | + def setinputsizes(self, __sizes: Sequence[DBAPITypeCode | int | None]) -> object: ... |
| 36 | + def setoutputsize(self, __size: int, __column: int = ...) -> object: ... |
0 commit comments