I think we should put this in 0.6 since 0.5.3 is already out with the
non-UUID version, code that expects a string to be returned will break.
Im using a TypeDecorator myself to integrate with UUID at the moment.
class GUIDType(TypeDecorator):
impl = PGUuid
def process_bind_param(self, value, dialect):
if value is None:
return value
else:
return str(value)
def process_result_value(self, value, dialect):
if value is None:
return value
else:
return uuid.UUID(value)
Jonathan Gardner wrote:
>
> The PGUuid doesn't accept Python's uuid.UUID type. Here's a simple patch
> to fix that:
>
> diff --git
> a/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/databases/po
> index 038a9e8..394c293 100755
> ---
> a/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/databases/postgres.
> +++
> b/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/databases/postgres.
> @@ -200,6 +200,17 @@ class PGBit(sqltypes.TypeEngine):
> class PGUuid(sqltypes.TypeEngine):
> def get_col_spec(self):
> return "UUID"
> +
> + def bind_processor(self, dialect):
> + def process(value):
> + return str(value)
> + return process
> +
> + def result_processor(self, dialect):
> + import uuid
> + def process(value):
> + return uuid.UUID(value)
> + return process
>
> class PGArray(sqltypes.MutableType, sqltypes.Concatenable,
> sqltypes.TypeEngine):
> def __init__(self, item_type, mutable=True):
>
>
>
> Also, I wonder if we should make UUID type a generic type. Other
> databases can either store it as an integer or as a string of hex
> digits. There are db designers out there (like myself) who prefer UUIDs
> over numbers for IDs.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---