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

129 lines
3.2 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. def has_one (
  30. self,
  31. related_model: Type[_ModelT],
  32. foreign_key: str | None = None,
  33. ) -> _ModelT: ...
  34. def has_many (
  35. self,
  36. related_model: Type[_ModelT],
  37. foreign_key: str | None = None,
  38. ) -> _ModelT: ...
  39. def belongs_to (
  40. self,
  41. related_model: Type[_ModelT],
  42. foreign_key: str | None = None,
  43. ) -> _ModelT: ...
  44. def belongs_to_many (
  45. self,
  46. related_model: Type[_ModelT],
  47. foreign_key: str | None = None,
  48. ) -> _ModelT: ...
  49. def save (self) -> None: ...
  50. def delete (self) -> None: ...
  51. @classmethod
  52. def find (cls, id_: int) -> Self | None: ...
  53. @overload
  54. @classmethod
  55. def where (
  56. cls,
  57. field: str,
  58. operator: str,
  59. value: Any,
  60. ) -> QueryBuilder[Self]: ...
  61. @overload
  62. @classmethod
  63. def where (cls, field: str, value: Any) -> QueryBuilder[Self]: ...
  64. @classmethod
  65. def where_not_in (
  66. cls,
  67. column: str,
  68. values: list[Any] | tuple
  69. ) -> QueryBuilder[Self]: ...
  70. @classmethod
  71. def where_not_null (cls, field: str) -> QueryBuilder[Self]: ...
  72. @classmethod
  73. def set_connection_resolver (cls, resolver: DatabaseManager) -> None: ...
  74. class QueryBuilder (Generic[_ModelT]):
  75. def first (self) -> _ModelT | None: ...
  76. def get (self) -> list[_ModelT]: ...
  77. @overload
  78. def where (
  79. self,
  80. field: str,
  81. operator: str,
  82. value: Any,
  83. ) -> QueryBuilder[_ModelT]: ...
  84. @overload
  85. def where (self, field: str, value: Any) -> QueryBuilder[_ModelT]: ...
  86. def where_null (self, field: str) -> QueryBuilder[_ModelT]: ...