MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / Boolean

Class Boolean

lib/sqlalchemy/sql/sqltypes.py:2092–2228  ·  view source on GitHub ↗

A bool datatype. :class:`.Boolean` typically uses BOOLEAN or SMALLINT on the DDL side, and on the Python side deals in ``True`` or ``False``. The :class:`.Boolean` datatype currently has two levels of assertion that the values persisted are simple true/false values. For all ba

Source from the content-addressed store, hash-verified

2090
2091
2092class Boolean(SchemaType, Emulated, TypeEngine[bool]):
2093 """A bool datatype.
2094
2095 :class:`.Boolean` typically uses BOOLEAN or SMALLINT on the DDL side,
2096 and on the Python side deals in ``True`` or ``False``.
2097
2098 The :class:`.Boolean` datatype currently has two levels of assertion
2099 that the values persisted are simple true/false values. For all
2100 backends, only the Python values ``None``, ``True``, ``False``, ``1``
2101 or ``0`` are accepted as parameter values. For those backends that
2102 don't support a "native boolean" datatype, an option exists to
2103 also create a CHECK constraint on the target column
2104
2105 """
2106
2107 __visit_name__ = "boolean"
2108 native = True
2109
2110 operator_classes = OperatorClass.BOOLEAN
2111
2112 def __init__(
2113 self,
2114 create_constraint: bool = False,
2115 name: Optional[str] = None,
2116 _create_events: bool = True,
2117 _adapted_from: Optional[SchemaType] = None,
2118 ):
2119 """Construct a Boolean.
2120
2121 :param create_constraint: defaults to False. If the boolean
2122 is generated as an int/smallint, also create a CHECK constraint
2123 on the table that ensures 1 or 0 as a value.
2124
2125 .. note:: it is strongly recommended that the CHECK constraint
2126 have an explicit name in order to support schema-management
2127 concerns. This can be established either by setting the
2128 :paramref:`.Boolean.name` parameter or by setting up an
2129 appropriate naming convention; see
2130 :ref:`constraint_naming_conventions` for background.
2131
2132 .. versionchanged:: 1.4 - this flag now defaults to False, meaning
2133 no CHECK constraint is generated for a non-native enumerated
2134 type.
2135
2136 :param name: if a CHECK constraint is generated, specify
2137 the name of the constraint.
2138
2139 """
2140 self.create_constraint = create_constraint
2141 self.name = name
2142 self._create_events = _create_events
2143 if _adapted_from:
2144 self.dispatch = self.dispatch._join(_adapted_from.dispatch)
2145
2146 def copy(self, **kw):
2147 # override SchemaType.copy() to not include to_metadata logic
2148 return self.adapt(
2149 cast("Type[TypeEngine[Any]]", self.__class__),

Calls

no outgoing calls