Vous êtes un professionnel et vous avez besoin d'une formation ?
Mise en oeuvre d'IHM
avec Qt et PySide6
Voir le programme détaillé
Module « sqlalchemy »
Classe « Enum »
Informations générales
Héritage
builtins.object
Generic
builtins.object
Visitable
TypeEngine
builtins.object
TypeEngineMixin
Emulated
builtins.object
TypeEngineMixin
builtins.object
EventTarget
SchemaEventTarget
SchemaType
builtins.object
Generic
builtins.object
Visitable
TypeEngine
builtins.object
TypeEngineMixin
Concatenable
String
Enum
Définition
class Enum(String, SchemaType, Emulated, TypeEngine):
help(Enum)
Generic Enum Type.
The :class:`.Enum` type provides a set of possible string values
which the column is constrained towards.
The :class:`.Enum` type will make use of the backend's native "ENUM"
type if one is available; otherwise, it uses a VARCHAR datatype.
An option also exists to automatically produce a CHECK constraint
when the VARCHAR (so called "non-native") variant is produced;
see the :paramref:`.Enum.create_constraint` flag.
The :class:`.Enum` type also provides in-Python validation of string
values during both read and write operations. When reading a value
from the database in a result set, the string value is always checked
against the list of possible values and a ``LookupError`` is raised
if no match is found. When passing a value to the database as a
plain string within a SQL statement, if the
:paramref:`.Enum.validate_strings` parameter is
set to True, a ``LookupError`` is raised for any string value that's
not located in the given list of possible values; note that this
impacts usage of LIKE expressions with enumerated values (an unusual
use case).
The source of enumerated values may be a list of string values, or
alternatively a PEP-435-compliant enumerated class. For the purposes
of the :class:`.Enum` datatype, this class need only provide a
``__members__`` method.
When using an enumerated class, the enumerated objects are used
both for input and output, rather than strings as is the case with
a plain-string enumerated type::
import enum
from sqlalchemy import Enum
class MyEnum(enum.Enum):
one = 1
two = 2
three = 3
t = Table("data", MetaData(), Column("value", Enum(MyEnum)))
connection.execute(t.insert(), {"value": MyEnum.two})
assert connection.scalar(t.select()) is MyEnum.two
Above, the string names of each element, e.g. "one", "two", "three",
are persisted to the database; the values of the Python Enum, here
indicated as integers, are **not** used; the value of each enum can
therefore be any kind of Python object whether or not it is persistable.
In order to persist the values and not the names, the
:paramref:`.Enum.values_callable` parameter may be used. The value of
this parameter is a user-supplied callable, which is intended to be used
with a PEP-435-compliant enumerated class and returns a list of string
values to be persisted. For a simple enumeration that uses string values,
a callable such as ``lambda x: [e.value for e in x]`` is sufficient.
.. seealso::
:ref:`orm_declarative_mapped_column_enums` - background on using
the :class:`_sqltypes.Enum` datatype with the ORM's
:ref:`ORM Annotated Declarative <orm_declarative_mapped_column>`
feature.
:class:`_postgresql.ENUM` - PostgreSQL-specific type,
which has additional functionality.
:class:`.mysql.ENUM` - MySQL-specific type
Constructeur(s)
Liste des attributs statiques
dispatch | <sqlalchemy.event.base.DDLEventsDispatch object at 0x0000020D9F843260> |
hashable | True |
render_bind_cast | False |
render_literal_cast | False |
should_evaluate_none | False |
Attributs statiques hérités de la classe String
sort_key_function
Liste des propriétés
native | |
python_type | |
sort_key_function | |
Liste des opérateurs
Opérateurs hérités de la classe object
__eq__,
__ge__,
__gt__,
__le__,
__lt__,
__ne__
Liste des méthodes
Toutes les méthodes
Méthodes d'instance
Méthodes statiques
Méthodes dépréciées
__repr__(self) |
|
adapt(self, cls, **kw) |
|
adapt_to_emulated(self, impltype, **kw) |
|
as_generic(self, allow_nulltype=False) |
|
bind_processor(self, dialect) |
|
Comparator(expr: 'ColumnElement[_CT]') |
|
comparator_factory(expr: 'ColumnElement[_CT]') |
|
copy(self, **kw) |
|
literal_processor(self, dialect) |
|
result_processor(self, dialect, coltype) |
|
Méthodes héritées de la classe Emulated
__init_subclass__, __subclasshook__
Méthodes héritées de la classe SchemaType
create, drop
Méthodes héritées de la classe String
get_dbapi_type
Méthodes héritées de la classe TypeEngine
__str__, bind_expression, coerce_compared_value, column_expression, compare_values, compile, copy_value, dialect_impl, evaluates_none, with_variant
Méthodes héritées de la classe Generic
__class_getitem__
Méthodes héritées de la classe Visitable
__class_getitem__
Méthodes héritées de la classe object
__delattr__,
__dir__,
__format__,
__getattribute__,
__getstate__,
__hash__,
__reduce__,
__reduce_ex__,
__setattr__,
__sizeof__
Vous êtes un professionnel et vous avez besoin d'une formation ?
RAG (Retrieval-Augmented Generation)et Fine Tuning d'un LLM
Voir le programme détaillé
Améliorations / Corrections
Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.
Emplacement :
Description des améliorations :