Skip to content

constraints

CheckColumns

Bases: CheckConstraint

Subclass of sqlalchemy.CheckConstraint. Used to avoid importing anything from sqlalchemy by user.

Note that some databases do not actively support check constraints such as MySQL.

Source code in ormar/fields/constraints.py
Python
49
50
51
52
53
54
55
class CheckColumns(CheckConstraint):
    """
    Subclass of sqlalchemy.CheckConstraint.
    Used to avoid importing anything from sqlalchemy by user.

    Note that some databases do not actively support check constraints such as MySQL.
    """

IndexColumns

Bases: Index

Subclass of sqlalchemy.Index. Used to avoid importing anything from sqlalchemy by user.

Passing unique=True together with case_insensitive=True builds a case-insensitive unique index by wrapping each named column in LOWER(), which is how case-insensitive uniqueness is expressed (a regular UniqueConstraint cannot hold SQL expressions).

Source code in ormar/fields/constraints.py
Python
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class IndexColumns(Index):
    """
    Subclass of sqlalchemy.Index.
    Used to avoid importing anything from sqlalchemy by user.

    Passing ``unique=True`` together with ``case_insensitive=True`` builds a
    case-insensitive unique index by wrapping each named column in ``LOWER()``,
    which is how case-insensitive uniqueness is expressed (a regular
    UniqueConstraint cannot hold SQL expressions).
    """

    def __init__(
        self,
        *args: Any,
        name: Optional[str] = None,
        case_insensitive: bool = False,
        **kw: Any,
    ) -> None:
        """
        :param args: column names, or SQL expressions for a functional index
        :type args: Any
        :param name: optional explicit index name
        :type name: Optional[str]
        :param case_insensitive: wrap each named column in ``LOWER()`` so the
            index (and its uniqueness, when ``unique=True``) ignores case
        :type case_insensitive: bool
        :param kw: additional keyword arguments passed to sqlalchemy.Index
        :type kw: Any
        """
        if case_insensitive:
            args = tuple(func.lower(column(arg)) for arg in args)
        if not name:
            name = "TEMPORARY_NAME"
        super().__init__(name, *args, **kw)

__init__(*args, name=None, case_insensitive=False, **kw)

Parameters:

Name Type Description Default
args Any

column names, or SQL expressions for a functional index

()
name Optional[str]

optional explicit index name

None
case_insensitive bool

wrap each named column in LOWER() so the index (and its uniqueness, when unique=True) ignores case

False
kw Any

additional keyword arguments passed to sqlalchemy.Index

{}
Source code in ormar/fields/constraints.py
Python
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def __init__(
    self,
    *args: Any,
    name: Optional[str] = None,
    case_insensitive: bool = False,
    **kw: Any,
) -> None:
    """
    :param args: column names, or SQL expressions for a functional index
    :type args: Any
    :param name: optional explicit index name
    :type name: Optional[str]
    :param case_insensitive: wrap each named column in ``LOWER()`` so the
        index (and its uniqueness, when ``unique=True``) ignores case
    :type case_insensitive: bool
    :param kw: additional keyword arguments passed to sqlalchemy.Index
    :type kw: Any
    """
    if case_insensitive:
        args = tuple(func.lower(column(arg)) for arg in args)
    if not name:
        name = "TEMPORARY_NAME"
    super().__init__(name, *args, **kw)

UniqueColumns

Bases: UniqueConstraint

Subclass of sqlalchemy.UniqueConstraint. Used to avoid importing anything from sqlalchemy by user.

Source code in ormar/fields/constraints.py
Python
 6
 7
 8
 9
10
class UniqueColumns(UniqueConstraint):
    """
    Subclass of sqlalchemy.UniqueConstraint.
    Used to avoid importing anything from sqlalchemy by user.
    """