types.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2020 The Matrix.org Foundation C.I.C.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from typing import Any, Iterable, Iterator, List, Tuple
  16. from typing_extensions import Protocol
  17. """
  18. Some very basic protocol definitions for the DB-API2 classes specified in PEP-249
  19. """
  20. class Cursor(Protocol):
  21. def execute(self, sql: str, parameters: Iterable[Any] = ...) -> Any:
  22. ...
  23. def executemany(self, sql: str, parameters: Iterable[Iterable[Any]]) -> Any:
  24. ...
  25. def fetchall(self) -> List[Tuple]:
  26. ...
  27. def fetchone(self) -> Tuple:
  28. ...
  29. @property
  30. def description(self) -> Any:
  31. return None
  32. @property
  33. def rowcount(self) -> int:
  34. return 0
  35. def __iter__(self) -> Iterator[Tuple]:
  36. ...
  37. def close(self) -> None:
  38. ...
  39. class Connection(Protocol):
  40. def cursor(self) -> Cursor:
  41. ...
  42. def close(self) -> None:
  43. ...
  44. def commit(self) -> None:
  45. ...
  46. def rollback(self, *args, **kwargs) -> None:
  47. ...