|
| 1 | +"""Autogenerated SQLAlchemy models based on OpenAlchemy models.""" |
| 2 | +# pylint: disable=no-member,super-init-not-called,unused-argument |
| 3 | + |
| 4 | +import typing |
| 5 | + |
| 6 | +import sqlalchemy |
| 7 | +from sqlalchemy import orm |
| 8 | + |
| 9 | +from open_alchemy import models |
| 10 | + |
| 11 | +Base = models.Base # type: ignore |
| 12 | + |
| 13 | + |
| 14 | +class _EmployeeDictBase(typing.TypedDict, total=True): |
| 15 | + """TypedDict for properties that are required.""" |
| 16 | + |
| 17 | + name: str |
| 18 | + division: str |
| 19 | + |
| 20 | + |
| 21 | +class EmployeeDict(_EmployeeDictBase, total=False): |
| 22 | + """TypedDict for properties that are not required.""" |
| 23 | + |
| 24 | + id: int |
| 25 | + salary: typing.Optional[float] |
| 26 | + |
| 27 | + |
| 28 | +class TEmployee(typing.Protocol): |
| 29 | + """ |
| 30 | + SQLAlchemy model protocol. |
| 31 | +
|
| 32 | + Person that works for a company. |
| 33 | +
|
| 34 | + Attrs: |
| 35 | + id: Unique identifier for the employee. |
| 36 | + name: The name of the employee. |
| 37 | + division: The part of the company the employee works in. |
| 38 | + salary: The amount of money the employee is paid. |
| 39 | +
|
| 40 | + """ |
| 41 | + |
| 42 | + # SQLAlchemy properties |
| 43 | + __table__: sqlalchemy.Table |
| 44 | + __tablename__: str |
| 45 | + query: orm.Query |
| 46 | + |
| 47 | + # Model properties |
| 48 | + id: "sqlalchemy.Column[int]" |
| 49 | + name: "sqlalchemy.Column[str]" |
| 50 | + division: "sqlalchemy.Column[str]" |
| 51 | + salary: "sqlalchemy.Column[typing.Optional[float]]" |
| 52 | + |
| 53 | + def __init__( |
| 54 | + self, |
| 55 | + name: str, |
| 56 | + division: str, |
| 57 | + id: typing.Optional[int] = None, |
| 58 | + salary: typing.Optional[float] = None, |
| 59 | + ) -> None: |
| 60 | + """ |
| 61 | + Construct. |
| 62 | +
|
| 63 | + Args: |
| 64 | + id: Unique identifier for the employee. |
| 65 | + name: The name of the employee. |
| 66 | + division: The part of the company the employee works in. |
| 67 | + salary: The amount of money the employee is paid. |
| 68 | +
|
| 69 | + """ |
| 70 | + ... |
| 71 | + |
| 72 | + @classmethod |
| 73 | + def from_dict( |
| 74 | + cls, |
| 75 | + name: str, |
| 76 | + division: str, |
| 77 | + id: typing.Optional[int] = None, |
| 78 | + salary: typing.Optional[float] = None, |
| 79 | + ) -> "TEmployee": |
| 80 | + """ |
| 81 | + Construct from a dictionary (eg. a POST payload). |
| 82 | +
|
| 83 | + Args: |
| 84 | + id: Unique identifier for the employee. |
| 85 | + name: The name of the employee. |
| 86 | + division: The part of the company the employee works in. |
| 87 | + salary: The amount of money the employee is paid. |
| 88 | +
|
| 89 | + Returns: |
| 90 | + Model instance based on the dictionary. |
| 91 | +
|
| 92 | + """ |
| 93 | + ... |
| 94 | + |
| 95 | + @classmethod |
| 96 | + def from_str(cls, value: str) -> "TEmployee": |
| 97 | + """ |
| 98 | + Construct from a JSON string (eg. a POST payload). |
| 99 | +
|
| 100 | + Returns: |
| 101 | + Model instance based on the JSON string. |
| 102 | +
|
| 103 | + """ |
| 104 | + ... |
| 105 | + |
| 106 | + def to_dict(self) -> EmployeeDict: |
| 107 | + """ |
| 108 | + Convert to a dictionary (eg. to send back for a GET request). |
| 109 | +
|
| 110 | + Returns: |
| 111 | + Dictionary based on the model instance. |
| 112 | +
|
| 113 | + """ |
| 114 | + ... |
| 115 | + |
| 116 | + def to_str(self) -> str: |
| 117 | + """ |
| 118 | + Convert to a JSON string (eg. to send back for a GET request). |
| 119 | +
|
| 120 | + Returns: |
| 121 | + JSON string based on the model instance. |
| 122 | +
|
| 123 | + """ |
| 124 | + ... |
| 125 | + |
| 126 | + |
| 127 | +Employee: typing.Type[TEmployee] = models.Employee # type: ignore |
0 commit comments