Skip to content

model

SelectAll

Bases: BaseModel

SelectAll tells the query engine to get all fields from the from() table ONLY.

Ideally it could get fields from joined tables too, but no way for that to work (from a typing POV) Not recommended for public use, users should rather use their table's all() method.

Source code in src/embar/model.py
20
21
22
23
24
25
26
27
28
class SelectAll(BaseModel):
    """
    `SelectAll` tells the query engine to get all fields from the `from()` table ONLY.

    Ideally it could get fields from joined tables too, but no way for that to work (from a typing POV)
    Not recommended for public use, users should rather use their table's `all()` method.
    """

    ...

generate_model(cls)

Create a model based on a Table.

Note the new table has the same exact name, maybe something to revisit.

from embar.table import Table
from embar.model import generate_model
class MyTable(Table): ...
generate_model(MyTable)
Source code in src/embar/model.py
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
def generate_model(cls: type[TableBase]) -> type[BaseModel]:
    """
    Create a model based on a `Table`.

    Note the new table has the same exact name, maybe something to revisit.

    ```python
    from embar.table import Table
    from embar.model import generate_model
    class MyTable(Table): ...
    generate_model(MyTable)
    ```
    """

    fields_dict: dict[str, Any] = {}
    for field_name, column in cls._fields.items():  # pyright:ignore[reportPrivateUsage]
        field_type = column.info.py_type
        fields_dict[field_name] = (
            Annotated[field_type, column],
            Field(default_factory=lambda a=column: column.info.fqn()),
        )

    model = create_model(cls.__name__, **fields_dict)
    model.model_rebuild()
    return model