Skip to content

config

Configuration for table definitions.

EmbarConfig

Configuration for table definitions.

Holds table name and constraints.

Source code in src/embar/config.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class EmbarConfig:
    """
    Configuration for table definitions.

    Holds table name and constraints.
    """

    table_name: str = Undefined
    constraints: list[Constraint]

    def __init__(
        self,
        table_name: str | None = None,
        constraints: list[Constraint] | None = None,
    ):
        """
        Create a new EmbarConfig instance.
        """
        if table_name is not None:
            self.table_name = table_name
        self.constraints = constraints if constraints is not None else []

    def __set_name__(self, owner: Any, attr_name: str):
        """
        This runs after __init__ and sets the name (if unset) from containing class.
        """
        if self.table_name == Undefined:
            self.table_name = "".join("_" + c.lower() if c.isupper() else c for c in owner.__name__).lstrip("_")

__init__(table_name=None, constraints=None)

Create a new EmbarConfig instance.

Source code in src/embar/config.py
19
20
21
22
23
24
25
26
27
28
29
def __init__(
    self,
    table_name: str | None = None,
    constraints: list[Constraint] | None = None,
):
    """
    Create a new EmbarConfig instance.
    """
    if table_name is not None:
        self.table_name = table_name
    self.constraints = constraints if constraints is not None else []

__set_name__(owner, attr_name)

This runs after init and sets the name (if unset) from containing class.

Source code in src/embar/config.py
31
32
33
34
35
36
def __set_name__(self, owner: Any, attr_name: str):
    """
    This runs after __init__ and sets the name (if unset) from containing class.
    """
    if self.table_name == Undefined:
        self.table_name = "".join("_" + c.lower() if c.isupper() else c for c in owner.__name__).lstrip("_")