thanks micheal,

2013/8/1 Michael Bayer <[email protected]>

> here you go, note MutableList is copied from MutableDict except adapted
> for lists, works as advertised (you'd need to add other list methods
> besides append()):
>
> from sqlalchemy import *
> from sqlalchemy.orm import *
> from sqlalchemy.ext.declarative import declarative_base
> from sqlalchemy.ext.mutable import Mutable
> from sqlalchemy.dialects.postgresql import ARRAY
>
>
> Base = declarative_base()
>
> class MutableList(Mutable, list):
>     def append(self, value):
>         list.append(self, value)
>         self.changed()
>
>     @classmethod
>     def coerce(cls, key, value):
>         if not isinstance(value, MutableList):
>             if isinstance(value, list):
>                 return MutableList(value)
>             return Mutable.coerce(key, value)
>         else:
>             return value
>
>
> class A(Base):
>     __tablename__ = 'a'
>
>     id = Column(Integer, primary_key=True)
>     data = Column(MutableList.as_mutable(ARRAY(Integer)))
>
> engine = create_engine("postgresql://scott:tiger@localhost/test",
> echo=True)
> Base.metadata.drop_all(engine)
> Base.metadata.create_all(engine)
>
> s = Session(engine)
>
> a1 = A(data=[1, 2, 3])
> s.add(a1)
> s.commit()
>
> a1.data.append(4)
> a1.data.append(5)
> a1.data.append(6)
>
> s.commit()
>
> assert a1.data == [1, 2, 3, 4, 5, 6]
>
>
>
>
> On Jul 31, 2013, at 10:39 AM, Michael Bayer <[email protected]>
> wrote:
>
> can you pass along a short code example?   I can try to edit it.
>
>
> On Jul 31, 2013, at 10:27 AM, notedit <[email protected]> wrote:
>
> yes  i have readed the doc,  but i just can not make it work with ARRAY.
>
>
> 2013/7/31 Michael Bayer <[email protected]>
>
>> I dont' have an example specific to ARRAY handy, did you read the
>> documentation at
>> http://docs.sqlalchemy.org/en/rel_0_8/orm/extensions/mutable.html ?
>>
>>
>> On Jul 31, 2013, at 10:12 AM, notedit <[email protected]> wrote:
>>
>> yes  i have noticed these.  but i still do not know how to use these with
>> array.
>> can you give me some example code?
>>
>>
>> 2013/7/31 Michael Bayer <[email protected]>
>>
>>> see
>>> http://docs.sqlalchemy.org/en/rel_0_8/changelog/migration_08.html#mutabletype
>>>
>>>
>>> On Jul 31, 2013, at 4:02 AM, notedit <[email protected]> wrote:
>>>
>>> hi,
>>>
>>> i just come accross this,  i use sqlalchemy 0.7.8 before  these all
>>> work. when i update to 0.8.2  this does not work.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "sqlalchemy" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>>
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/sqlalchemy.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>>
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/sqlalchemy.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to