class HStore(UserDefinedType):""" SQLAlchemy type that passes through values to be handled by a psycopg2extension type."""type_name = 'HSTORE'def get_col_spec(self):return self.type_namedef bind_processor(self, dialect):return Nonedef result_processor(self, dialect, coltype):return Nonedef is_mutable(self):return Truedef copy_value(self, value):return copy.copy(value)
class MutationDict(Mutable, dict):@classmethoddef coerce(cls, key, value):"Convert plain dictionaries to MutationDict."if not isinstance(value, MutationDict):if isinstance(value, dict):return MutationDict(value)# this call will raise ValueErrorreturn Mutable.coerce(key, value)else:return valuedef __setitem__(self, key, value):"Detect dictionary set events and emit change events."dict.__setitem__(self, key, value)self.changed()def __delitem__(self, key):"Detect dictionary del events and emit change events."dict.__delitem__(self, key)self.changed()
some_attrs = Column(MutationDict.as_mutable(HStore))
newobject.some_attrs = other_object.some_attrs
def copy_value(self, value):try:# Use dict.copy(), because copy.copy will call __setitem__ on the# value causing it to be marked dirty, which could result in# an infinite loop of flushing dirty copies if an hstore is# copied to another hstore column.return value.copy()except Exception:return None
--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/q7YGmmDyhxsJ.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.