Represent a database agnostic UUID datatype. For backends that have no "native" UUID datatype, the value will make use of ``CHAR(32)`` and store the UUID as a 32-character alphanumeric hex string. For backends which are known to support ``UUID`` directly or a similar uuid-stori
| 3778 | |
| 3779 | |
| 3780 | class Uuid(Emulated, TypeEngine[_UUID_RETURN]): |
| 3781 | """Represent a database agnostic UUID datatype. |
| 3782 | |
| 3783 | For backends that have no "native" UUID datatype, the value will |
| 3784 | make use of ``CHAR(32)`` and store the UUID as a 32-character alphanumeric |
| 3785 | hex string. |
| 3786 | |
| 3787 | For backends which are known to support ``UUID`` directly or a similar |
| 3788 | uuid-storing datatype such as SQL Server's ``UNIQUEIDENTIFIER``, a |
| 3789 | "native" mode enabled by default allows these types will be used on those |
| 3790 | backends. |
| 3791 | |
| 3792 | In its default mode of use, the :class:`_sqltypes.Uuid` datatype expects |
| 3793 | **Python uuid objects**, from the Python |
| 3794 | `uuid <https://docs.python.org/3/library/uuid.html>`_ |
| 3795 | module:: |
| 3796 | |
| 3797 | import uuid |
| 3798 | |
| 3799 | from sqlalchemy import Uuid |
| 3800 | from sqlalchemy import Table, Column, MetaData, String |
| 3801 | |
| 3802 | metadata_obj = MetaData() |
| 3803 | |
| 3804 | t = Table( |
| 3805 | "t", |
| 3806 | metadata_obj, |
| 3807 | Column("uuid_data", Uuid, primary_key=True), |
| 3808 | Column("other_data", String), |
| 3809 | ) |
| 3810 | |
| 3811 | with engine.begin() as conn: |
| 3812 | conn.execute( |
| 3813 | t.insert(), {"uuid_data": uuid.uuid4(), "other_data": "some data"} |
| 3814 | ) |
| 3815 | |
| 3816 | To have the :class:`_sqltypes.Uuid` datatype work with string-based |
| 3817 | Uuids (e.g. 32 character hexadecimal strings), pass the |
| 3818 | :paramref:`_sqltypes.Uuid.as_uuid` parameter with the value ``False``. |
| 3819 | |
| 3820 | .. versionadded:: 2.0 |
| 3821 | |
| 3822 | .. seealso:: |
| 3823 | |
| 3824 | :class:`_sqltypes.UUID` - represents exactly the ``UUID`` datatype |
| 3825 | without any backend-agnostic behaviors. |
| 3826 | |
| 3827 | """ # noqa: E501 |
| 3828 | |
| 3829 | __visit_name__ = "uuid" |
| 3830 | |
| 3831 | operator_classes = OperatorClass.BASE | OperatorClass.COMPARISON |
| 3832 | |
| 3833 | length: Optional[int] = None |
| 3834 | collation: Optional[str] = None |
| 3835 | |
| 3836 | @overload |
| 3837 | def __init__( |
no outgoing calls