import uuid
from sqlalchemy.dialects.postgresql import UUID as PG_UUID
from sqlalchemy.types import CHAR, TypeDecorator
class GUID(TypeDecorator):
    impl = CHAR
    cache_ok = True
    def load_dialect_impl(self, dialect): return dialect.type_descriptor(PG_UUID(as_uuid=True) if dialect.name == "postgresql" else CHAR(36))
    def process_bind_param(self, value, dialect):
        if value is None: return None
        return (value if isinstance(value, uuid.UUID) else uuid.UUID(str(value))) if dialect.name == "postgresql" else str(value)
    def process_result_value(self, value, dialect): return value if value is None or isinstance(value, uuid.UUID) else uuid.UUID(str(value))
