On Oct 10, 2008, at 4:25 PM, Hermann Himmelbauer wrote:

>
> Hi,
> I created a custom type that represents a string as list of  
> int(elements),
> e.g.:
>
> "2222" <-> [2, 2, 2, 2]
>
> The class I created looks as follows:
>
> class IntList(types.TypeDecorator):
>    """List of integers that is represented by string in the RDB"""
>    impl=String
>
>    def process_bind_param(self, value, engine):
>        if value == [] or value is None:
>            return None
>        else:
>            return ''.join((str(x) for x in value))
>    def process_result_value(self, value, engine):
>        if value is None:
>            return []
>        else:
>            return [int(x) for x in value]


have your IntList type also extend the mixin MutableType, i.e. class  
IntList(MutableType, TypeDecorator).  SQLA will detect this and dig in  
to the object's value in order to detect changes.  You'll also want to  
implement copy_value() and compare_values() for this type.

The reason this is not default behavior is for reasons of performance  
- SQLA doesn't scan and compare all attributes of all clean objects  
each time it looks for "dirty" objects, nor does it store a second  
copy of every attribute's value by default.  When a mutable type is  
detected, these two steps take place.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to