Hi Folks,

So we have a sort of generic table; let's call it 'Thing'. For the sake of
example, let it have two columns. An integer 'id', and a hstore 'data':

from sqlalchemy.dialects.postgresql import HSTORE
from Column, Integer

class Thing(Base):
    __tablename__ = 'thing'

    id          = Column(Integer, primary_key=True)
    data        = Column(MutableDict.as_mutable(HSTORE))


Now what I want to do is have some more mapped attributes that peek inside
the HSTORE. I am assuming I know something about the HSTORE structure when
I add this to the class definition:

foo  = column_property(expression.cast(data["foo"], Integer))

And this works pretty well; when I get an instance of Thing, I can ask it
for it's 'foo' and I get an integer back.

However it doesn't work if I *assign* to foo. The session notices the
object is dirty but doesn't know how to write back my changes.

In an earlier attempt at this I just made 'foo' a hybrid property which
wrote and read directly into the data 'hstore', doing the casting at each
read/write. This was OK for integers and strings but what I really want to
say is something like:

bar  = column_property(expression.cast(data["bar"], *JSONEncoded*))

And be able to do:

mything.bar.append("lalala")

(Here I am assuming that I had a HSTORE with a key 'bar' with a value that
was a JSON encoded list)

(JSONEncoded is a custom mutable type similar to examples in the docs).

So I'd like to be able to use mutable types; not just reassignment. Perhaps
I need some custom types and a reimplementation of column_expression to
fetch/write to the HSTORE but I am getting a bit lost!

Anyone tried anything like this before?

All the best,

Philip

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
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