You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class UUIDType(ScalarCoercible, types.TypeDecorator):
"""
Stores a UUID in the database natively when it can and falls back to
a BINARY(16) or a CHAR(32) when it can't.
::
from sqlalchemy_utils import UUIDType
import uuid
class User(Base):
__tablename__ = 'user'
# Pass `binary=False` to fallback to CHAR instead of BINARY
id = sa.Column(
UUIDType(binary=False),
primary_key=True,
default=uuid.uuid4
)
"""
// value for impl remain same on binary = False
impl = types.BINARY(16)
python_type = uuid.UUID
cache_ok = True
def __init__(self, binary=True, native=True):
"""
:param binary: Whether to use a BINARY(16) or CHAR(32) fallback.
"""
self.binary = binary
self.native = native
def __repr__(self):
return util.generic_repr(self)
def load_dialect_impl(self, dialect):
if self.native and dialect.name in ('postgresql', 'cockroachdb'):
# Use the native UUID type.
return dialect.type_descriptor(postgresql.UUID())
if dialect.name == 'mssql' and self.native:
# Use the native UNIQUEIDENTIFIER type.
return dialect.type_descriptor(mssql.UNIQUEIDENTIFIER())
else:
# Fallback to either a BINARY or a CHAR.
kind = self.impl if self.binary else types.CHAR(32)
return dialect.type_descriptor(kind)
The text was updated successfully, but these errors were encountered:
BhuwanPandey
changed the title
Even though binary set false, impl remain as binary(16)
Even though binary was set false, impl remain as binary(16)
Oct 10, 2023
BhuwanPandey
changed the title
Even though binary was set false, impl remain as binary(16)
Even though binary was set false, impl remain binary(16)
Oct 10, 2023
class UUIDType(ScalarCoercible, types.TypeDecorator):
"""
Stores a UUID in the database natively when it can and falls back to
a BINARY(16) or a CHAR(32) when it can't.
// value for impl remain same on binary = False
The text was updated successfully, but these errors were encountered: