ぼざろクリーチャーシリーズ 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.
 
 
 

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