ぼざろクリーチャーシリーズ DB 兼 API(自分用)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

146 lines
3.6 KiB

  1. # pylint: disable = missing-class-docstring
  2. # pylint: disable = missing-function-docstring
  3. # pylint: disable = missing-module-docstring
  4. # pylint: disable = unused-argument
  5. from __future__ import annotations
  6. from typing import Any, Generic, Type, TypeVar, overload
  7. from typing_extensions import Self
  8. _ModelT = TypeVar ('_ModelT', bound = 'Model')
  9. class Connection:
  10. def select (self, query: str, bindings: dict[str, Any] | None = None) -> Any: ...
  11. def insert (self, query: str, bindings: dict[str, Any] | None = None) -> int: ...
  12. def update (self, query: str, bindings: dict[str, Any] | None = None) -> int: ...
  13. def delete (self, query: str, bindings: dict[str, Any] | None = None) -> int: ...
  14. def transaction (self, callback: Any) -> Any: ...
  15. def begin_transaction (self) -> None: ...
  16. def commit (self) -> None: ...
  17. def rollback (self) -> None: ...
  18. class ConnectionResolver:
  19. def connection (self, name: str | None = None) -> Any: ...
  20. def get_default_connection (self) -> str: ...
  21. def set_default_connection (self, name: str) -> None: ...
  22. class DatabaseManager:
  23. connections: dict[str, Connection]
  24. def __init__ (self, config: dict[str, Any]) -> None: ...
  25. def connection (self, name: str | None = None) -> Connection: ...
  26. def disconnect (self, name: str | None = None) -> None: ...
  27. def reconnect (self, name: str | None = None) -> Connection: ...
  28. def get_connections (self) -> dict[str, Connection]: ...
  29. class Model:
  30. id: int
  31. _Model__exists: bool
  32. def has_one (
  33. self,
  34. related_model: Type[_ModelT],
  35. foreign_key: str | None = None,
  36. ) -> _ModelT: ...
  37. def has_many (
  38. self,
  39. related_model: Type[_ModelT],
  40. foreign_key: str | None = None,
  41. ) -> list[_ModelT]: ...
  42. def belongs_to (
  43. self,
  44. related_model: Type[_ModelT],
  45. foreign_key: str | None = None,
  46. ) -> _ModelT: ...
  47. def belongs_to_many (
  48. self,
  49. related_model: Type[_ModelT],
  50. foreign_key: str | None = None,
  51. ) -> list[_ModelT]: ...
  52. def save (self) -> None: ...
  53. def delete (self) -> None: ...
  54. @classmethod
  55. def find (cls, id_: int) -> Self | None: ...
  56. @classmethod
  57. def query (
  58. cls,
  59. ) -> QueryBuilder[Self]: ...
  60. @overload
  61. @classmethod
  62. def where (
  63. cls,
  64. field: str,
  65. operator: str,
  66. value: Any,
  67. ) -> QueryBuilder[Self]: ...
  68. @overload
  69. @classmethod
  70. def where (cls, field: str, value: Any) -> QueryBuilder[Self]: ...
  71. @classmethod
  72. def where_not_in (
  73. cls,
  74. column: str,
  75. values: list[Any] | tuple
  76. ) -> QueryBuilder[Self]: ...
  77. @classmethod
  78. def where_not_null (cls, field: str) -> QueryBuilder[Self]: ...
  79. @classmethod
  80. def max (cls, column: str) -> Any: ...
  81. @classmethod
  82. def set_connection_resolver (cls, resolver: DatabaseManager) -> None: ...
  83. class QueryBuilder (Generic[_ModelT]):
  84. def first (self) -> _ModelT | None: ...
  85. def get (self) -> list[_ModelT]: ...
  86. @overload
  87. def where (
  88. self,
  89. field: str,
  90. operator: str,
  91. value: Any,
  92. ) -> QueryBuilder[_ModelT]: ...
  93. @overload
  94. def where (self, field: str, value: Any) -> QueryBuilder[_ModelT]: ...
  95. def where_null (self, field: str) -> QueryBuilder[_ModelT]: ...
  96. def max (self, column: str) -> Any: ...
  97. def _load_relation (self, relation_name: str) -> QueryBuilder[_ModelT]: ...