diff --git a/db/eloquent.pyi b/db/eloquent.pyi new file mode 100644 index 0000000..0ab7167 --- /dev/null +++ b/db/eloquent.pyi @@ -0,0 +1,140 @@ +# pylint: disable = missing-class-docstring +# pylint: disable = missing-function-docstring +# pylint: disable = missing-module-docstring +# pylint: disable = unused-argument + +from __future__ import annotations + +from typing import Any, Generic, Type, TypeVar, overload +from typing_extensions import Self + +_ModelT = TypeVar ('_ModelT', bound = 'Model') + + +class Connection: + def select (self, query: str, bindings: dict[str, Any] | None = None) -> Any: ... + + def insert (self, query: str, bindings: dict[str, Any] | None = None) -> int: ... + + def update (self, query: str, bindings: dict[str, Any] | None = None) -> int: ... + + def delete (self, query: str, bindings: dict[str, Any] | None = None) -> int: ... + + def transaction (self, callback: Any) -> Any: ... + + def begin_transaction (self) -> None: ... + + def commit (self) -> None: ... + + def rollback (self) -> None: ... + + +class ConnectionResolver: + def connection (self, name: str | None = None) -> Any: ... + + def get_default_connection (self) -> str: ... + + def set_default_connection (self, name: str) -> None: ... + + +class DatabaseManager: + connections: dict[str, Connection] + + def __init__ (self, config: dict[str, Any]) -> None: ... + + def connection (self, name: str | None = None) -> Connection: ... + + def disconnect (self, name: str | None = None) -> None: ... + + def reconnect (self, name: str | None = None) -> Connection: ... + + def get_connections (self) -> dict[str, Connection]: ... + + +class Model: + id: int + + _Model__exists: bool + + def has_one ( + self, + related_model: Type[_ModelT], + foreign_key: str | None = None, + ) -> _ModelT: ... + + def has_many ( + self, + related_model: Type[_ModelT], + foreign_key: str | None = None, + ) -> list[_ModelT]: ... + + def belongs_to ( + self, + related_model: Type[_ModelT], + foreign_key: str | None = None, + ) -> _ModelT: ... + + def belongs_to_many ( + self, + related_model: Type[_ModelT], + foreign_key: str | None = None, + ) -> list[_ModelT]: ... + + def save (self) -> None: ... + + def delete (self) -> None: ... + + @classmethod + def find (cls, id_: int) -> Self | None: ... + + @classmethod + def query ( + cls, + ) -> QueryBuilder[Self]: ... + + @overload + @classmethod + def where ( + cls, + field: str, + operator: str, + value: Any, + ) -> QueryBuilder[Self]: ... + + @overload + @classmethod + def where (cls, field: str, value: Any) -> QueryBuilder[Self]: ... + + @classmethod + def where_not_in ( + cls, + column: str, + values: list[Any] | tuple + ) -> QueryBuilder[Self]: ... + + @classmethod + def where_not_null (cls, field: str) -> QueryBuilder[Self]: ... + + @classmethod + def set_connection_resolver (cls, resolver: DatabaseManager) -> None: ... + + +class QueryBuilder (Generic[_ModelT]): + def first (self) -> _ModelT | None: ... + + def get (self) -> list[_ModelT]: ... + + @overload + def where ( + self, + field: str, + operator: str, + value: Any, + ) -> QueryBuilder[_ModelT]: ... + + @overload + def where (self, field: str, value: Any) -> QueryBuilder[_ModelT]: ... + + def where_null (self, field: str) -> QueryBuilder[_ModelT]: ... + + def _load_relation (self, relation_name: str) -> QueryBuilder[_ModelT]: ... diff --git a/models.py b/db/models.py similarity index 98% rename from models.py rename to db/models.py index d16e273..37d25e8 100644 --- a/models.py +++ b/db/models.py @@ -9,7 +9,7 @@ from __future__ import annotations from datetime import date, datetime -from my_eloquent import Model +from db.my_eloquent import Model class Comment (Model): diff --git a/my_eloquent.py b/db/my_eloquent.py similarity index 100% rename from my_eloquent.py rename to db/my_eloquent.py diff --git a/eloquent.pyi b/eloquent.pyi deleted file mode 100644 index 0ab7167..0000000 --- a/eloquent.pyi +++ /dev/null @@ -1,140 +0,0 @@ -# pylint: disable = missing-class-docstring -# pylint: disable = missing-function-docstring -# pylint: disable = missing-module-docstring -# pylint: disable = unused-argument - -from __future__ import annotations - -from typing import Any, Generic, Type, TypeVar, overload -from typing_extensions import Self - -_ModelT = TypeVar ('_ModelT', bound = 'Model') - - -class Connection: - def select (self, query: str, bindings: dict[str, Any] | None = None) -> Any: ... - - def insert (self, query: str, bindings: dict[str, Any] | None = None) -> int: ... - - def update (self, query: str, bindings: dict[str, Any] | None = None) -> int: ... - - def delete (self, query: str, bindings: dict[str, Any] | None = None) -> int: ... - - def transaction (self, callback: Any) -> Any: ... - - def begin_transaction (self) -> None: ... - - def commit (self) -> None: ... - - def rollback (self) -> None: ... - - -class ConnectionResolver: - def connection (self, name: str | None = None) -> Any: ... - - def get_default_connection (self) -> str: ... - - def set_default_connection (self, name: str) -> None: ... - - -class DatabaseManager: - connections: dict[str, Connection] - - def __init__ (self, config: dict[str, Any]) -> None: ... - - def connection (self, name: str | None = None) -> Connection: ... - - def disconnect (self, name: str | None = None) -> None: ... - - def reconnect (self, name: str | None = None) -> Connection: ... - - def get_connections (self) -> dict[str, Connection]: ... - - -class Model: - id: int - - _Model__exists: bool - - def has_one ( - self, - related_model: Type[_ModelT], - foreign_key: str | None = None, - ) -> _ModelT: ... - - def has_many ( - self, - related_model: Type[_ModelT], - foreign_key: str | None = None, - ) -> list[_ModelT]: ... - - def belongs_to ( - self, - related_model: Type[_ModelT], - foreign_key: str | None = None, - ) -> _ModelT: ... - - def belongs_to_many ( - self, - related_model: Type[_ModelT], - foreign_key: str | None = None, - ) -> list[_ModelT]: ... - - def save (self) -> None: ... - - def delete (self) -> None: ... - - @classmethod - def find (cls, id_: int) -> Self | None: ... - - @classmethod - def query ( - cls, - ) -> QueryBuilder[Self]: ... - - @overload - @classmethod - def where ( - cls, - field: str, - operator: str, - value: Any, - ) -> QueryBuilder[Self]: ... - - @overload - @classmethod - def where (cls, field: str, value: Any) -> QueryBuilder[Self]: ... - - @classmethod - def where_not_in ( - cls, - column: str, - values: list[Any] | tuple - ) -> QueryBuilder[Self]: ... - - @classmethod - def where_not_null (cls, field: str) -> QueryBuilder[Self]: ... - - @classmethod - def set_connection_resolver (cls, resolver: DatabaseManager) -> None: ... - - -class QueryBuilder (Generic[_ModelT]): - def first (self) -> _ModelT | None: ... - - def get (self) -> list[_ModelT]: ... - - @overload - def where ( - self, - field: str, - operator: str, - value: Any, - ) -> QueryBuilder[_ModelT]: ... - - @overload - def where (self, field: str, value: Any) -> QueryBuilder[_ModelT]: ... - - def where_null (self, field: str) -> QueryBuilder[_ModelT]: ... - - def _load_relation (self, relation_name: str) -> QueryBuilder[_ModelT]: ... diff --git a/eloquent.pyi b/eloquent.pyi new file mode 120000 index 0000000..a074ddf --- /dev/null +++ b/eloquent.pyi @@ -0,0 +1 @@ +db/eloquent.pyi \ No newline at end of file diff --git a/update_db.py b/update_db.py index 4e4e420..83d72eb 100644 --- a/update_db.py +++ b/update_db.py @@ -20,7 +20,7 @@ import jaconv import requests from eloquent import DatabaseManager, Model -from models import Comment, Tag, User, Video, VideoHistory, VideoTag +from db.models import Comment, Tag, User, Video, VideoHistory, VideoTag def main (